Skip to content

Commit 08ef119

Browse files
a7medevHeshamMegid
authored andcommitted
feat: support identify user by id (#435)
1 parent 1e5dcea commit 08ef119

File tree

8 files changed

+39
-28
lines changed

8 files changed

+39
-28
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Changelog
22

3+
## [Unreleased](https://github.com/Instabug/Instabug-Flutter/compare/v12.5.0...dev)
4+
5+
### Added
6+
7+
- Support user identification using ID ([#435](https://github.com/Instabug/Instabug-Flutter/pull/435)).
8+
39
## [12.5.0](https://github.com/Instabug/Instabug-Flutter/compare/v12.4.0...v12.5.0) (January 08 , 2024)
410

511
### Changed

android/src/main/java/com/instabug/flutter/modules/InstabugApi.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,8 @@ public void showWelcomeMessageWithMode(@NonNull String mode) {
118118
}
119119

120120
@Override
121-
public void identifyUser(@NonNull String email, @Nullable String name) {
122-
Instabug.identifyUser(name, email);
121+
public void identifyUser(@NonNull String email, @Nullable String name, @Nullable String userId) {
122+
Instabug.identifyUser(name, email, userId);
123123
}
124124

125125
@Override

android/src/test/java/com/instabug/flutter/InstabugApiTest.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,10 +174,11 @@ public void testShowWelcomeMessageWithMode() {
174174
public void testIdentifyUser() {
175175
String email = "[email protected]";
176176
String name = "John Doe";
177+
String id = "123";
177178

178-
api.identifyUser(email, name);
179+
api.identifyUser(email, name, id);
179180

180-
mInstabug.verify(() -> Instabug.identifyUser(name, email));
181+
mInstabug.verify(() -> Instabug.identifyUser(name, email, id));
181182
}
182183

183184
@Test

example/ios/InstabugTests/InstabugApiTests.m

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -64,23 +64,15 @@ - (void)testShowWelcomeMessageWithMode {
6464
OCMVerify([self.mInstabug showWelcomeMessageWithMode:IBGWelcomeMessageModeLive]);
6565
}
6666

67-
- (void)testIdentifyUserGivenName {
67+
- (void)testIdentifyUser {
6868
NSString *email = @"[email protected]";
6969
NSString *name = @"John Doe";
70+
NSString *userId = @"123";
7071
FlutterError *error;
7172

72-
[self.api identifyUserEmail:email name:name error:&error];
73+
[self.api identifyUserEmail:email name:name userId:userId error:&error];
7374

74-
OCMVerify([self.mInstabug identifyUserWithEmail:email name:name]);
75-
}
76-
77-
- (void)testIdentifyUserGivenNoName {
78-
NSString *email = @"[email protected]";
79-
FlutterError *error;
80-
81-
[self.api identifyUserEmail:email name:[NSNull null] error:&error];
82-
83-
OCMVerify([self.mInstabug identifyUserWithEmail:email name:nil]);
75+
OCMVerify([self.mInstabug identifyUserWithID:userId email:email name:name]);
8476
}
8577

8678
- (void)testSetUserData {

ios/Classes/Modules/InstabugApi.m

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,8 @@ - (void)showWelcomeMessageWithModeMode:(NSString *)mode error:(FlutterError *_Nu
5555
[Instabug showWelcomeMessageWithMode:resolvedMode];
5656
}
5757

58-
- (void)identifyUserEmail:(NSString *)email name:(nullable NSString *)name error:(FlutterError *_Nullable *_Nonnull)error {
59-
if ([name isKindOfClass:[NSNull class]]) {
60-
[Instabug identifyUserWithEmail:email name:nil];
61-
} else {
62-
[Instabug identifyUserWithEmail:email name:name];
63-
}
58+
- (void)identifyUserEmail:(NSString *)email name:(nullable NSString *)name userId:(nullable NSString *)userId error:(FlutterError *_Nullable *_Nonnull)error {
59+
[Instabug identifyUserWithID:userId email:email name:name];
6460
}
6561

6662
- (void)setUserDataData:(NSString *)data error:(FlutterError *_Nullable *_Nonnull)error {

lib/src/modules/instabug.dart

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -180,11 +180,15 @@ class Instabug {
180180
}
181181

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

190194
/// Sets the default value of the user's email to nil and show email field and remove user name

pigeons/instabug.api.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ abstract class InstabugHostApi {
88
void show();
99
void showWelcomeMessageWithMode(String mode);
1010

11-
void identifyUser(String email, String? name);
11+
void identifyUser(String email, String? name, String? userId);
1212
void setUserData(String data);
1313
void logUserEvent(String name);
1414
void logOut();

test/instabug_test.dart

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,14 +69,26 @@ void main() {
6969
).called(1);
7070
});
7171

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

7676
await Instabug.identifyUser(email, name);
7777

7878
verify(
79-
mHost.identifyUser(email, name),
79+
mHost.identifyUser(email, name, null),
80+
).called(1);
81+
});
82+
83+
test('[identifyUser] should call host method with an ID', () async {
84+
const email = "[email protected]";
85+
const name = "Instabug";
86+
const id = "123";
87+
88+
await Instabug.identifyUser(email, name, id);
89+
90+
verify(
91+
mHost.identifyUser(email, name, id),
8092
).called(1);
8193
});
8294

0 commit comments

Comments
 (0)