Skip to content

Commit f2786e1

Browse files
feat: Handle Hashed Email for Rokt
1 parent 0c2ead6 commit f2786e1

2 files changed

Lines changed: 53 additions & 0 deletions

File tree

mParticle-Rokt/MPKitRokt.m

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,9 @@ - (RoktFrameworkType)mapMPWrapperSdkToRoktFrameworkType:(MPWrapperSdk)wrapperSdk
197197
// Add all known user identities to the attributes being passed to the Rokt SDK
198198
[self addIdentityAttributes:finalAtt filteredUser:filteredUser];
199199

200+
// Handle hashed email use case
201+
[self handleHashedEmail:finalAtt];
202+
200203
// The core SDK does not set sandbox on the user, but we must pass it to Rokt if provided
201204
NSString *sandboxKey = @"sandbox";
202205
if (attributes[sandboxKey] != nil) {
@@ -293,6 +296,27 @@ + (void)addIdentityAttributes:(NSMutableDictionary<NSString *, NSString *> * _Nu
293296
}
294297
}
295298

299+
+ (void)handleHashedEmail:(NSMutableDictionary<NSString *, NSString *> * _Nullable)attributes {
300+
NSString *emailKey = [MPKitRokt stringForIdentityType:MPIdentityEmail];
301+
NSString *otherKey = [MPKitRokt stringForIdentityType:MPIdentityOther];
302+
NSString *hashedEmailValue = attributes[@"emailsha256"];
303+
304+
// Remove email and other is hashed vlaue already set
305+
if (hashedEmailValue != nil) {
306+
[attributes removeObjectForKey:emailKey];
307+
[attributes removeObjectForKey:otherKey];
308+
}
309+
310+
NSString *otherValue = attributes[otherKey];
311+
312+
// Remove email and replace key on other if it's set
313+
if (otherValue != nil) {
314+
[attributes removeObjectForKey:emailKey];
315+
attributes[@"emailsha256"] = otherValue;
316+
[attributes removeObjectForKey:otherKey];
317+
}
318+
}
319+
296320
+ (RoktConfig *)convertMPRoktConfig:(MPRoktConfig *)mpRoktConfig {
297321
if (mpRoktConfig != nil) {
298322
Builder *builder = [[Builder alloc] init];

mParticle_RoktTests/mParticle_RoktTests.m

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ - (MPKitExecStatus *)purchaseFinalized:(NSString *)placementId
2323

2424
+ (void)addIdentityAttributes:(NSMutableDictionary<NSString *, NSString *> * _Nullable)attributes filteredUser:(FilteredMParticleUser * _Nonnull)filteredUser;
2525

26+
+ (void)handleHashedEmail:(NSMutableDictionary<NSString *, NSString *> * _Nullable)attributes;
27+
2628
+ (RoktConfig *)convertMPRoktConfig:(MPRoktConfig *)mpRoktConfig;
2729

2830
@end
@@ -493,4 +495,31 @@ - (void)testEvents_NilIdentifier {
493495
[mockRoktSDK stopMocking];
494496
}
495497

498+
- (void)testHandleHashedEmailOtherOverride {
499+
NSMutableDictionary<NSString *, NSString *> *passedAttributes = [[NSMutableDictionary alloc] init];
500+
[passedAttributes setObject:@"foo@gmail.com" forKey:@"email"];
501+
[passedAttributes setObject:@"test@gmail.com" forKey:@"other"];
502+
503+
[MPKitRokt handleHashedEmail:passedAttributes];
504+
505+
XCTAssertNil(passedAttributes[@"email"]);
506+
XCTAssertNil(passedAttributes[@"other"]);
507+
XCTAssertEqualObjects(passedAttributes[@"emailsha256"], @"test@gmail.com");
508+
XCTAssertTrue(passedAttributes.allKeys.count == 1);
509+
}
510+
511+
- (void)testHandleHashedEmailHashedOverride {
512+
NSMutableDictionary<NSString *, NSString *> *passedAttributes = [[NSMutableDictionary alloc] init];
513+
[passedAttributes setObject:@"foo@gmail.com" forKey:@"email"];
514+
[passedAttributes setObject:@"test@gmail.com" forKey:@"other"];
515+
[passedAttributes setObject:@"test2@gmail.com" forKey:@"emailsha256"];
516+
517+
[MPKitRokt handleHashedEmail:passedAttributes];
518+
519+
XCTAssertNil(passedAttributes[@"email"]);
520+
XCTAssertNil(passedAttributes[@"other"]);
521+
XCTAssertEqualObjects(passedAttributes[@"emailsha256"], @"test2@gmail.com");
522+
XCTAssertTrue(passedAttributes.allKeys.count == 1);
523+
}
524+
496525
@end

0 commit comments

Comments
 (0)