Skip to content

Commit e0b8198

Browse files
feat: Map Selected Identity to Emailsha256
1 parent 1696f39 commit e0b8198

4 files changed

Lines changed: 155 additions & 5 deletions

File tree

mParticle-Rokt-Swift/MPRoktLayout.swift

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,10 @@ public class MPRoktLayout {
5353
}
5454
let email = attributes?["email"]
5555
let hashedEmail = attributes?["emailsha256"]
56+
let hashedEmailIdentity = MPKitRokt.getHashedEmailUserIdentityType()
5657

5758
let userEmailIdentity = user.identities[NSNumber(value: MPIdentity.email.rawValue)]
58-
let userHashedEmailIdentity = user.identities[NSNumber(value: MPIdentity.other.rawValue)]
59+
let userHashedEmailIdentity = user.identities[hashedEmailIdentity]
5960

6061
let emailMismatch = email != nil && email != userEmailIdentity
6162
let hashedEmailMismatch = hashedEmail != nil && hashedEmail != userHashedEmailIdentity
@@ -69,7 +70,7 @@ public class MPRoktLayout {
6970
print("The existing hashed email on the user (\(userHashedEmailIdentity ?? "nil")) does not match the email passed in to `selectPlacements:` (\(hashedEmail ?? "nil")). Please remember to sync the email identity to mParticle as soon as you receive it. We will now identify the user before creating the layout")
7071
}
7172

72-
syncIdentities(user: user, email: email, hashedEmail: hashedEmail, completion: completion)
73+
syncIdentities(user: user, email: email, hashedEmail: hashedEmail, hashedEmailKey: hashedEmailIdentity, completion: completion)
7374
} else {
7475
completion()
7576
}
@@ -79,11 +80,12 @@ public class MPRoktLayout {
7980
user: MParticleUser,
8081
email: String?,
8182
hashedEmail: String?,
83+
hashedEmailKey: NSNumber,
8284
completion: @escaping () -> Void
8385
) {
8486
let identityRequest = MPIdentityApiRequest(user: user)
8587
identityRequest.setIdentity(email, identityType: .email)
86-
identityRequest.setIdentity(hashedEmail, identityType: .other)
88+
identityRequest.setIdentity(hashedEmail, identityType: MPIdentity(rawValue: hashedEmailKey.uintValue) ?? .other)
8789

8890
mparticle.identity.identify(identityRequest) {apiResult, error in
8991
if let error = error {

mParticle-Rokt/MPKitRokt.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,6 @@
1717
@property (nonatomic, unsafe_unretained, readonly) BOOL started;
1818

1919
+ (NSDictionary<NSString *, NSString *> * _Nonnull)prepareAttributes:(NSDictionary<NSString *, NSString *> * _Nonnull)attributes filteredUser:(FilteredMParticleUser * _Nullable)filteredUser performMapping:(BOOL)performMapping;
20+
+ (NSNumber * _Nonnull)getRoktHashedEmailUserIdentityType;
2021

2122
@end

mParticle-Rokt/MPKitRokt.m

Lines changed: 81 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
NSString * const MPKitRoktErrorDomain = @"com.mparticle.kits.rokt";
77
NSString * const MPKitRoktErrorMessageKey = @"mParticle-Rokt Error";
88
NSString * const kMPPlacementAttributesMapping = @"placementAttributesMapping";
9+
NSString * const kMPHashedEmailUserIdentityType = @"hashedEmailUserIdentityType";
910
static __weak MPKitRokt *roktKit = nil;
1011

1112
@interface MPKitRokt () <MPKitProtocol>
@@ -361,6 +362,12 @@ + (RoktConfig *)convertMPRoktConfig:(MPRoktConfig *)mpRoktConfig {
361362
}
362363

363364
+ (NSString *)stringForIdentityType:(MPIdentity)identityType {
365+
NSNumber *hashedEmailIdentity = [MPKitRokt getRoktHashedEmailUserIdentityType];
366+
367+
if (hashedEmailIdentity.unsignedIntValue == identityType) {
368+
return @"emailsha256";
369+
}
370+
364371
switch (identityType) {
365372
case MPIdentityCustomerId:
366373
return @"customerid";
@@ -381,8 +388,7 @@ + (NSString *)stringForIdentityType:(MPIdentity)identityType {
381388
return @"microsoft";
382389

383390
case MPIdentityOther:
384-
// As of 7/30/2025, "MPIdentityOther" is used by Rokt customers to identify based off hashed email
385-
return @"emailsha256";
391+
return @"other";
386392

387393
case MPIdentityTwitter:
388394
return @"twitter";
@@ -443,6 +449,79 @@ + (NSString *)stringForIdentityType:(MPIdentity)identityType {
443449
}
444450
}
445451

452+
+ (NSNumber *)identityTypeForString:(NSString *)identityString {
453+
if ([identityString isEqualToString:@"customerid"]){
454+
return @(MPIdentityCustomerId);
455+
} else if ([identityString isEqualToString:@"email"]){
456+
return @(MPIdentityEmail);
457+
} else if ([identityString isEqualToString:@"facebook"]){
458+
return @(MPIdentityFacebook);
459+
} else if ([identityString isEqualToString:@"facebookcustomaudienceid"]){
460+
return @(MPIdentityFacebookCustomAudienceId);
461+
} else if ([identityString isEqualToString:@"google"]){
462+
return @(MPIdentityGoogle);
463+
} else if ([identityString isEqualToString:@"microsoft"]){
464+
return @(MPIdentityMicrosoft);
465+
} else if ([identityString isEqualToString:@"other"]){
466+
return @(MPIdentityOther);
467+
} else if ([identityString isEqualToString:@"twitter"]){
468+
return @(MPIdentityTwitter);
469+
} else if ([identityString isEqualToString:@"yahoo"]){
470+
return @(MPIdentityYahoo);
471+
} else if ([identityString isEqualToString:@"other2"]){
472+
return @(MPIdentityOther2);
473+
} else if ([identityString isEqualToString:@"other3"]){
474+
return @(MPIdentityOther3);
475+
} else if ([identityString isEqualToString:@"other4"]){
476+
return @(MPIdentityOther4);
477+
} else if ([identityString isEqualToString:@"other5"]){
478+
return @(MPIdentityOther5);
479+
} else if ([identityString isEqualToString:@"other6"]){
480+
return @(MPIdentityOther6);
481+
} else if ([identityString isEqualToString:@"other7"]){
482+
return @(MPIdentityOther7);
483+
} else if ([identityString isEqualToString:@"other8"]){
484+
return @(MPIdentityOther8);
485+
} else if ([identityString isEqualToString:@"other9"]){
486+
return @(MPIdentityOther9);
487+
} else if ([identityString isEqualToString:@"other10"]){
488+
return @(MPIdentityOther10);
489+
} else if ([identityString isEqualToString:@"mobile_number"]){
490+
return @(MPIdentityMobileNumber);
491+
} else if ([identityString isEqualToString:@"phone_number_2"]){
492+
return @(MPIdentityPhoneNumber2);
493+
} else if ([identityString isEqualToString:@"phone_number_3"]){
494+
return @(MPIdentityPhoneNumber3);
495+
} else if ([identityString isEqualToString:@"ios_idfa"]){
496+
return @(MPIdentityIOSAdvertiserId);
497+
} else if ([identityString isEqualToString:@"ios_idfv"]){
498+
return @(MPIdentityIOSVendorId);
499+
} else if ([identityString isEqualToString:@"push_token"]){
500+
return @(MPIdentityPushToken);
501+
} else if ([identityString isEqualToString:@"device_application_stamp"]){
502+
return @(MPIdentityDeviceApplicationStamp);
503+
} else {
504+
return nil;
505+
}
506+
}
507+
508+
+ (NSNumber *)getRoktHashedEmailUserIdentityType {
509+
// Get the kit configuration
510+
NSArray<NSDictionary *> *kitConfigs = [MParticle sharedInstance].kitContainer_PRIVATE.originalConfig.copy;
511+
NSDictionary *roktKitConfig;
512+
for (NSDictionary *kitConfig in kitConfigs) {
513+
if (kitConfig[@"id"] != nil && [kitConfig[@"id"] integerValue] == 181) {
514+
roktKitConfig = kitConfig;
515+
}
516+
}
517+
518+
// Get the string representing which identity to use and convert it to the key (NSNumber)
519+
NSString *hashedIdentityTypeString = roktKitConfig[kMPHashedEmailUserIdentityType];
520+
NSNumber *hashedIdentityTypeNumber = [MPKitRokt identityTypeForString:hashedIdentityTypeString.lowercaseString];
521+
522+
return hashedIdentityTypeNumber != nil ? hashedIdentityTypeNumber : @(MPIdentityOther);
523+
}
524+
446525
- (MPKitExecStatus *)purchaseFinalized:(NSString *)placementId catalogItemId:(NSString *)catalogItemId success:(NSNumber *)success {
447526
if (placementId != nil && catalogItemId != nil && success != nil) {
448527
if (@available(iOS 15.0, *)) {

mParticle_RoktTests/mParticle_RoktTests.m

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ + (void)addIdentityAttributes:(NSMutableDictionary<NSString *, NSString *> * _Nu
2424

2525
+ (void)handleHashedEmail:(NSMutableDictionary<NSString *, NSString *> * _Nullable)attributes;
2626

27+
+ (NSNumber *)getRoktHashedEmailUserIdentityType;
28+
2729
+ (RoktConfig *)convertMPRoktConfig:(MPRoktConfig *)mpRoktConfig;
2830

2931
+ (NSDictionary<NSString *, NSString *> *)transformValuesToString:(NSDictionary<NSString *, id> * _Nullable)originalDictionary;
@@ -329,6 +331,72 @@ - (void)testAddIdentityAttributesWithExistingAttributes {
329331
XCTAssertEqualObjects(passedAttributes[@"device_application_stamp"], @"Test DAS");
330332
}
331333

334+
- (void)testAddIdentityAttributesWithExistingAttributesAndOther {
335+
NSMutableDictionary<NSString *, NSString *> *passedAttributes = [[NSMutableDictionary alloc] init];
336+
[passedAttributes setObject:@"bar" forKey:@"foo"];
337+
NSDictionary<NSNumber *, NSString *> *testIdentities = @{@(MPIdentityCustomerId): @"testCustomerID",
338+
@(MPIdentityEmail): @"testEmail@gmail.com",
339+
@(MPIdentityFacebook): @"testFacebook",
340+
@(MPIdentityFacebookCustomAudienceId): @"testCustomAudienceID",
341+
@(MPIdentityGoogle): @"testGoogle",
342+
@(MPIdentityMicrosoft): @"testMicrosoft",
343+
@(MPIdentityOther): @"testOther",
344+
@(MPIdentityTwitter): @"testTwitter",
345+
@(MPIdentityYahoo): @"testYahoo",
346+
@(MPIdentityOther2): @"testOther2",
347+
@(MPIdentityOther3): @"testOther3",
348+
@(MPIdentityOther4): @"testOther4",
349+
@(MPIdentityOther5): @"testOther5",
350+
@(MPIdentityOther6): @"testOther6",
351+
@(MPIdentityOther7): @"testOther7",
352+
@(MPIdentityOther8): @"testOther8",
353+
@(MPIdentityOther9): @"testOther9",
354+
@(MPIdentityOther10): @"testOther10",
355+
@(MPIdentityMobileNumber): @"1(234)-567-8910",
356+
@(MPIdentityPhoneNumber2): @"1(234)-567-2222",
357+
@(MPIdentityPhoneNumber3): @"1(234)-567-3333",
358+
@(MPIdentityIOSAdvertiserId): @"testAdvertID",
359+
@(MPIdentityIOSVendorId): @"testVendorID",
360+
@(MPIdentityPushToken): @"testPushToken",
361+
@(MPIdentityDeviceApplicationStamp): @"Test DAS"};
362+
363+
FilteredMParticleUser *filteredUser = [[FilteredMParticleUser alloc] init];
364+
id mockfilteredUser = OCMPartialMock(filteredUser);
365+
[[[mockfilteredUser stub] andReturn:testIdentities] userIdentities];
366+
id mockMPKitRoktClass = OCMClassMock([MPKitRokt class]);
367+
[[[mockMPKitRoktClass stub] andReturn:@(MPIdentityOther4)] getRoktHashedEmailUserIdentityType];
368+
369+
[MPKitRokt addIdentityAttributes:passedAttributes filteredUser:filteredUser];
370+
371+
XCTAssertEqualObjects(passedAttributes[@"foo"], @"bar");
372+
XCTAssertEqualObjects(passedAttributes[@"customerid"], @"testCustomerID");
373+
XCTAssertEqualObjects(passedAttributes[@"email"], @"testEmail@gmail.com");
374+
XCTAssertEqualObjects(passedAttributes[@"facebook"], @"testFacebook");
375+
XCTAssertEqualObjects(passedAttributes[@"facebookcustomaudienceid"], @"testCustomAudienceID");
376+
XCTAssertEqualObjects(passedAttributes[@"google"], @"testGoogle");
377+
XCTAssertEqualObjects(passedAttributes[@"microsoft"], @"testMicrosoft");
378+
XCTAssertEqualObjects(passedAttributes[@"other"], @"testOther");
379+
XCTAssertEqualObjects(passedAttributes[@"emailsha256"], @"testOther4");
380+
XCTAssertEqualObjects(passedAttributes[@"twitter"], @"testTwitter");
381+
XCTAssertEqualObjects(passedAttributes[@"yahoo"], @"testYahoo");
382+
XCTAssertEqualObjects(passedAttributes[@"other2"], @"testOther2");
383+
XCTAssertEqualObjects(passedAttributes[@"other3"], @"testOther3");
384+
XCTAssertNil(passedAttributes[@"other4"]);
385+
XCTAssertEqualObjects(passedAttributes[@"other5"], @"testOther5");
386+
XCTAssertEqualObjects(passedAttributes[@"other6"], @"testOther6");
387+
XCTAssertEqualObjects(passedAttributes[@"other7"], @"testOther7");
388+
XCTAssertEqualObjects(passedAttributes[@"other8"], @"testOther8");
389+
XCTAssertEqualObjects(passedAttributes[@"other9"], @"testOther9");
390+
XCTAssertEqualObjects(passedAttributes[@"other10"], @"testOther10");
391+
XCTAssertEqualObjects(passedAttributes[@"mobile_number"], @"1(234)-567-8910");
392+
XCTAssertEqualObjects(passedAttributes[@"phone_number_2"], @"1(234)-567-2222");
393+
XCTAssertEqualObjects(passedAttributes[@"phone_number_3"], @"1(234)-567-3333");
394+
XCTAssertEqualObjects(passedAttributes[@"ios_idfa"], @"testAdvertID");
395+
XCTAssertEqualObjects(passedAttributes[@"ios_idfv"], @"testVendorID");
396+
XCTAssertEqualObjects(passedAttributes[@"push_token"], @"testPushToken");
397+
XCTAssertEqualObjects(passedAttributes[@"device_application_stamp"], @"Test DAS");
398+
}
399+
332400
- (void)testConvertMPRoktConfig {
333401
MPRoktConfig *mpConfig = [[MPRoktConfig alloc] init];
334402
mpConfig.colorMode = MPColorModeDark;

0 commit comments

Comments
 (0)