Skip to content

feat: support identify user by id #435

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## [Unreleased](https://github.com/Instabug/Instabug-Flutter/compare/v12.5.0...dev)

### Added

- Support user identification using ID ([#435](https://github.com/Instabug/Instabug-Flutter/pull/435)).

## [12.5.0](https://github.com/Instabug/Instabug-Flutter/compare/v12.4.0...v12.5.0) (January 08 , 2024)

### Changed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@ public void showWelcomeMessageWithMode(@NonNull String mode) {
}

@Override
public void identifyUser(@NonNull String email, @Nullable String name) {
Instabug.identifyUser(name, email);
public void identifyUser(@NonNull String email, @Nullable String name, @Nullable String userId) {
Instabug.identifyUser(name, email, userId);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,10 +174,11 @@ public void testShowWelcomeMessageWithMode() {
public void testIdentifyUser() {
String email = "[email protected]";
String name = "John Doe";
String id = "123";

api.identifyUser(email, name);
api.identifyUser(email, name, id);

mInstabug.verify(() -> Instabug.identifyUser(name, email));
mInstabug.verify(() -> Instabug.identifyUser(name, email, id));
}

@Test
Expand Down
16 changes: 4 additions & 12 deletions example/ios/InstabugTests/InstabugApiTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -64,23 +64,15 @@ - (void)testShowWelcomeMessageWithMode {
OCMVerify([self.mInstabug showWelcomeMessageWithMode:IBGWelcomeMessageModeLive]);
}

- (void)testIdentifyUserGivenName {
- (void)testIdentifyUser {
NSString *email = @"[email protected]";
NSString *name = @"John Doe";
NSString *userId = @"123";
FlutterError *error;

[self.api identifyUserEmail:email name:name error:&error];
[self.api identifyUserEmail:email name:name userId:userId error:&error];

OCMVerify([self.mInstabug identifyUserWithEmail:email name:name]);
}

- (void)testIdentifyUserGivenNoName {
NSString *email = @"[email protected]";
FlutterError *error;

[self.api identifyUserEmail:email name:[NSNull null] error:&error];

OCMVerify([self.mInstabug identifyUserWithEmail:email name:nil]);
OCMVerify([self.mInstabug identifyUserWithID:userId email:email name:name]);
}

- (void)testSetUserData {
Expand Down
8 changes: 2 additions & 6 deletions ios/Classes/Modules/InstabugApi.m
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,8 @@ - (void)showWelcomeMessageWithModeMode:(NSString *)mode error:(FlutterError *_Nu
[Instabug showWelcomeMessageWithMode:resolvedMode];
}

- (void)identifyUserEmail:(NSString *)email name:(nullable NSString *)name error:(FlutterError *_Nullable *_Nonnull)error {
if ([name isKindOfClass:[NSNull class]]) {
[Instabug identifyUserWithEmail:email name:nil];
} else {
[Instabug identifyUserWithEmail:email name:name];
}
- (void)identifyUserEmail:(NSString *)email name:(nullable NSString *)name userId:(nullable NSString *)userId error:(FlutterError *_Nullable *_Nonnull)error {
[Instabug identifyUserWithID:userId email:email name:name];
}

- (void)setUserDataData:(NSString *)data error:(FlutterError *_Nullable *_Nonnull)error {
Expand Down
10 changes: 7 additions & 3 deletions lib/src/modules/instabug.dart
Original file line number Diff line number Diff line change
Expand Up @@ -180,11 +180,15 @@ class Instabug {
}

/// Sets the default value of the user's [email] and hides the email field from the reporting UI
/// and set the user's [name] to be included with all reports.
/// and set the user's [name] and [id] to be included with all reports.
/// It also reset the chats on device to that email and removes user attributes,
/// user data and completed surveys.
static Future<void> identifyUser(String email, [String? name]) async {
return _host.identifyUser(email, name);
static Future<void> identifyUser(
String email, [
String? name,
String? id,
]) async {
return _host.identifyUser(email, name, id);
}

/// Sets the default value of the user's email to nil and show email field and remove user name
Expand Down
2 changes: 1 addition & 1 deletion pigeons/instabug.api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ abstract class InstabugHostApi {
void show();
void showWelcomeMessageWithMode(String mode);

void identifyUser(String email, String? name);
void identifyUser(String email, String? name, String? userId);
void setUserData(String data);
void logUserEvent(String name);
void logOut();
Expand Down
16 changes: 14 additions & 2 deletions test/instabug_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,26 @@ void main() {
).called(1);
});

test('[identifyUser] should call host method', () async {
test('[identifyUser] should call host method with no ID', () async {
const email = "[email protected]";
const name = "Instabug";

await Instabug.identifyUser(email, name);

verify(
mHost.identifyUser(email, name),
mHost.identifyUser(email, name, null),
).called(1);
});

test('[identifyUser] should call host method with an ID', () async {
const email = "[email protected]";
const name = "Instabug";
const id = "123";

await Instabug.identifyUser(email, name, id);

verify(
mHost.identifyUser(email, name, id),
).called(1);
});

Expand Down