Skip to content

Commit 3b9e072

Browse files
feat: Handle Hashed Email for Rokt (#383)
1 parent 66ebf11 commit 3b9e072

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

UnitTests/MPRoktTests.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
@interface MPRokt ()
1212
- (NSArray<NSDictionary<NSString *, NSString *> *> *)getRoktPlacementAttributesMapping;
13-
- (void)confirmEmail:(NSString * _Nullable)email user:(MParticleUser * _Nullable)user completion:(void (^)(MParticleUser *_Nullable))completion;
13+
- (void)confirmUser:(NSDictionary<NSString *, NSString *> *)attributes user:(MParticleUser * _Nullable)user completion:(void (^)(MParticleUser *_Nullable))completion;
1414
@end
1515

1616
@interface MPRokt (Testing)
@@ -328,7 +328,7 @@ - (void)testSelectPlacementsIdentifyUser {
328328

329329
// Set up expectations for kit container
330330
XCTestExpectation *expectation = [self expectationWithDescription:@"Wait for async operation"];
331-
OCMExpect([self.mockRokt confirmEmail:@"[email protected]" user:OCMOCK_ANY completion:OCMOCK_ANY]).andDo(^(NSInvocation *invocation) {
331+
OCMExpect([self.mockRokt confirmUser:attributes user:OCMOCK_ANY completion:OCMOCK_ANY]).andDo(^(NSInvocation *invocation) {
332332
[expectation fulfill];
333333
});
334334

mParticle-Apple-SDK/MPRokt.m

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,9 @@ - (void)selectPlacements:(NSString *)identifier
3939
config:(MPRoktConfig * _Nullable)config
4040
callbacks:(MPRoktEventCallback * _Nullable)callbacks {
4141
MParticleUser *currentUser = [MParticle sharedInstance].identity.currentUser;
42-
NSString *email = attributes[@"email"];
4342

4443
// If email is passed in as an attribute and it's different than the existing identity, identify with it
45-
[self confirmEmail:email user:currentUser completion:^(MParticleUser *_Nullable resolvedUser) {
44+
[self confirmUser:attributes user:currentUser completion:^(MParticleUser *_Nullable resolvedUser) {
4645
NSArray<NSDictionary<NSString *, NSString *> *> *attributeMap = [self getRoktPlacementAttributesMapping];
4746

4847
// If attributeMap is nil the kit hasn't been initialized
@@ -198,21 +197,28 @@ - (void)close {
198197
return finalAttributes;
199198
}
200199

201-
- (void)confirmEmail:(NSString * _Nullable)email user:(MParticleUser * _Nullable)user completion:(void (^)(MParticleUser *_Nullable))completion {
202-
if (email && email != user.identities[@(MPIdentityEmail)]) {
203-
// If there is an existing email but it doesn't match the email passed in, warn the customer
200+
- (void)confirmUser:(NSDictionary<NSString *, NSString *> * _Nullable)attributes user:(MParticleUser * _Nullable)user completion:(void (^)(MParticleUser *_Nullable))completion {
201+
NSString *email = attributes[@"email"];
202+
NSString *hashedEmail = attributes[@"other"];
203+
204+
if ((email && ![email isEqualToString:user.identities[@(MPIdentityEmail)]]) || (hashedEmail && ![hashedEmail isEqualToString: user.identities[@(MPIdentityOther)]])) {
205+
// If there is an existing email or hashed email but it doesn't match the what was passed in, warn the customer
204206
if (user.identities[@(MPIdentityEmail)]) {
205207
NSLog(@"The existing email on the user (%@) does not match the email passed in to `selectPlacements:` (%@). Please remember to sync the email identity to mParticle as soon as you receive it. We will now identify the user before contuing to `selectPlacements:`", user.identities[@(MPIdentityEmail)], email);
208+
} else if (user.identities[@(MPIdentityOther)]) {
209+
NSLog(@"The existing hashed email on the user (%@) does not match the email passed in to `selectPlacements:` (%@). Please remember to sync the email identity to mParticle as soon as you receive it. We will now identify the user before contuing to `selectPlacements:`", user.identities[@(MPIdentityOther)], hashedEmail);
206210
}
211+
207212
MPIdentityApiRequest *identityRequest = [MPIdentityApiRequest requestWithUser:user];
208-
identityRequest.email = email;
213+
[identityRequest setIdentity:email identityType:MPIdentityEmail];
214+
[identityRequest setIdentity:hashedEmail identityType:MPIdentityOther];
209215

210216
[[[MParticle sharedInstance] identity] identify:identityRequest completion:^(MPIdentityApiResult *_Nullable apiResult, NSError *_Nullable error) {
211217
if (error) {
212218
NSLog(@"Failed to sync email from selectPlacement to user: %@", error);
213219
completion(user);
214220
} else {
215-
NSLog(@"Updated email identity based off selectPlacement's attributes: %@", apiResult.user.identities[@(MPIdentityEmail)]);
221+
NSLog(@"Updated user identity based off selectPlacement's attributes: %@", apiResult.user.identities);
216222
completion(apiResult.user);
217223
}
218224
}];

0 commit comments

Comments
 (0)