diff --git a/CHANGELOG.md b/CHANGELOG.md index 57bc7db91..c0f4bdca9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/android/src/main/java/com/instabug/flutter/modules/InstabugApi.java b/android/src/main/java/com/instabug/flutter/modules/InstabugApi.java index c67c1b41b..80e9cfa67 100644 --- a/android/src/main/java/com/instabug/flutter/modules/InstabugApi.java +++ b/android/src/main/java/com/instabug/flutter/modules/InstabugApi.java @@ -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 diff --git a/android/src/test/java/com/instabug/flutter/InstabugApiTest.java b/android/src/test/java/com/instabug/flutter/InstabugApiTest.java index 5e4e9d27e..140daab65 100644 --- a/android/src/test/java/com/instabug/flutter/InstabugApiTest.java +++ b/android/src/test/java/com/instabug/flutter/InstabugApiTest.java @@ -174,10 +174,11 @@ public void testShowWelcomeMessageWithMode() { public void testIdentifyUser() { String email = "inst@bug.com"; 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 diff --git a/example/ios/InstabugTests/InstabugApiTests.m b/example/ios/InstabugTests/InstabugApiTests.m index a7f624774..3b55e0c3f 100644 --- a/example/ios/InstabugTests/InstabugApiTests.m +++ b/example/ios/InstabugTests/InstabugApiTests.m @@ -64,23 +64,15 @@ - (void)testShowWelcomeMessageWithMode { OCMVerify([self.mInstabug showWelcomeMessageWithMode:IBGWelcomeMessageModeLive]); } -- (void)testIdentifyUserGivenName { +- (void)testIdentifyUser { NSString *email = @"inst@bug.com"; 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 = @"inst@bug.com"; - 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 { diff --git a/ios/Classes/Modules/InstabugApi.m b/ios/Classes/Modules/InstabugApi.m index 4c3ae92d8..7def622f0 100644 --- a/ios/Classes/Modules/InstabugApi.m +++ b/ios/Classes/Modules/InstabugApi.m @@ -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 { diff --git a/lib/src/modules/instabug.dart b/lib/src/modules/instabug.dart index 2f75e4d4d..54450c1e5 100644 --- a/lib/src/modules/instabug.dart +++ b/lib/src/modules/instabug.dart @@ -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 identifyUser(String email, [String? name]) async { - return _host.identifyUser(email, name); + static Future 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 diff --git a/pigeons/instabug.api.dart b/pigeons/instabug.api.dart index e1d0dfc1e..2d1308ce1 100644 --- a/pigeons/instabug.api.dart +++ b/pigeons/instabug.api.dart @@ -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(); diff --git a/test/instabug_test.dart b/test/instabug_test.dart index f1b784f09..8f623796e 100644 --- a/test/instabug_test.dart +++ b/test/instabug_test.dart @@ -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 = "inst@bug.com"; 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 = "inst@bug.com"; + const name = "Instabug"; + const id = "123"; + + await Instabug.identifyUser(email, name, id); + + verify( + mHost.identifyUser(email, name, id), ).called(1); });