Skip to content

Commit 411727e

Browse files
fix: Rokt User Attribute Mapping
1 parent bb4dd76 commit 411727e

File tree

4 files changed

+69
-20
lines changed

4 files changed

+69
-20
lines changed

UnitTests/ObjCTests/MPRoktTests.m

Lines changed: 56 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -293,17 +293,19 @@ - (void)testGetRoktPlacementAttributesMapping {
293293
self.mockInstance = OCMPartialMock(instance);
294294
self.mockContainer = OCMClassMock([MPKitContainer_PRIVATE class]);
295295
NSArray *kitConfig = @[@{
296-
@"AllowJavaScriptResponse": @"True",
297-
@"accountId": @12345,
298-
@"onboardingExpProvider": @"None",
299-
kMPPlacementAttributesMapping: @"[{\"jsmap\":null,\"map\":\"f.name\",\"maptype\":\"UserAttributeClass.Name\",\"value\":\"firstname\"},{\"jsmap\":null,\"map\":\"zip\",\"maptype\":\"UserAttributeClass.Name\",\"value\":\"billingzipcode\"},{\"jsmap\":null,\"map\":\"l.name\",\"maptype\":\"UserAttributeClass.Name\",\"value\":\"lastname\"}]",
300-
@"sandboxMode": @"True",
301-
@"eau": @0,
302-
@"hs": @{
303-
@"pur": @{},
304-
@"reg": @{}
305-
},
306-
@"id": @181
296+
@"id": @181,
297+
kMPRemoteConfigKitConfigurationKey: @{
298+
@"AllowJavaScriptResponse": @"True",
299+
@"accountId": @12345,
300+
@"onboardingExpProvider": @"None",
301+
kMPPlacementAttributesMapping: @"[{\"jsmap\":null,\"map\":\"f.name\",\"maptype\":\"UserAttributeClass.Name\",\"value\":\"firstname\"},{\"jsmap\":null,\"map\":\"zip\",\"maptype\":\"UserAttributeClass.Name\",\"value\":\"billingzipcode\"},{\"jsmap\":null,\"map\":\"l.name\",\"maptype\":\"UserAttributeClass.Name\",\"value\":\"lastname\"}]",
302+
@"sandboxMode": @"True",
303+
@"eau": @0,
304+
@"hs": @{
305+
@"pur": @{},
306+
@"reg": @{}
307+
}
308+
}
307309
}];
308310
[[[self.mockContainer stub] andReturn:kitConfig] originalConfig];
309311
[[[self.mockInstance stub] andReturn:self.mockContainer] kitContainer_PRIVATE];
@@ -315,6 +317,49 @@ - (void)testGetRoktPlacementAttributesMapping {
315317
XCTAssertEqualObjects(testResult, expectedResult, @"Mapping does not match .");
316318
}
317319

320+
- (void)testGetRoktHashedEmailUserIdentityType {
321+
MParticle *instance = [MParticle sharedInstance];
322+
self.mockInstance = OCMPartialMock(instance);
323+
self.mockContainer = OCMClassMock([MPKitContainer_PRIVATE class]);
324+
NSArray *kitConfig = @[@{
325+
@"id": @181,
326+
kMPRemoteConfigKitConfigurationKey: @{
327+
@"AllowJavaScriptResponse": @"True",
328+
@"accountId": @12345,
329+
kMPHashedEmailUserIdentityType: @"other3",
330+
@"sandboxMode": @"True"
331+
}
332+
}];
333+
[[[self.mockContainer stub] andReturn:kitConfig] originalConfig];
334+
[[[self.mockInstance stub] andReturn:self.mockContainer] kitContainer_PRIVATE];
335+
[[[self.mockInstance stub] andReturn:self.mockInstance] sharedInstance];
336+
337+
NSNumber *testResult = [self.rokt getRoktHashedEmailUserIdentityType];
338+
339+
XCTAssertEqualObjects(testResult, @(MPIdentityOther3), @"Hashed email identity type does not match.");
340+
}
341+
342+
- (void)testGetRoktHashedEmailUserIdentityTypeReturnsNilWhenNotConfigured {
343+
MParticle *instance = [MParticle sharedInstance];
344+
self.mockInstance = OCMPartialMock(instance);
345+
self.mockContainer = OCMClassMock([MPKitContainer_PRIVATE class]);
346+
NSArray *kitConfig = @[@{
347+
@"id": @181,
348+
kMPRemoteConfigKitConfigurationKey: @{
349+
@"AllowJavaScriptResponse": @"True",
350+
@"accountId": @12345,
351+
@"sandboxMode": @"True"
352+
}
353+
}];
354+
[[[self.mockContainer stub] andReturn:kitConfig] originalConfig];
355+
[[[self.mockInstance stub] andReturn:self.mockContainer] kitContainer_PRIVATE];
356+
[[[self.mockInstance stub] andReturn:self.mockInstance] sharedInstance];
357+
358+
NSNumber *testResult = [self.rokt getRoktHashedEmailUserIdentityType];
359+
360+
XCTAssertNil(testResult, @"Hashed email identity type should be nil when not configured.");
361+
}
362+
318363
- (void)testSelectPlacementsIdentifyUser {
319364
[[[self.mockRokt stub] andReturn:@[]] getRoktPlacementAttributesMapping];
320365
MParticle *instance = [MParticle sharedInstance];

mParticle-Apple-SDK/MPIConstants.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,7 @@ extern NSString * _Nonnull const kMPRemoteConfigAppDefined;
241241
extern NSString * _Nonnull const kMPRemoteConfigForceTrue;
242242
extern NSString * _Nonnull const kMPRemoteConfigForceFalse;
243243
extern NSString * _Nonnull const kMPRemoteConfigKitsKey;
244+
extern NSString * _Nonnull const kMPRemoteConfigKitConfigurationKey;
244245
extern NSString * _Nonnull const kMPRemoteConfigKitHashesKey;
245246
extern NSString * _Nonnull const kMPRemoteConfigConsumerInfoKey;
246247
extern NSString * _Nonnull const kMPRemoteConfigCookiesKey;

mParticle-Apple-SDK/MPIConstants.m

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,7 @@
194194
NSString *const kMPRemoteConfigForceTrue = @"forcetrue";
195195
NSString *const kMPRemoteConfigForceFalse = @"forcefalse";
196196
NSString *const kMPRemoteConfigKitsKey = @"eks";
197+
NSString *const kMPRemoteConfigKitConfigurationKey = @"as";
197198
NSString *const kMPRemoteConfigKitHashesKey = @"hs";
198199
NSString *const kMPRemoteConfigConsumerInfoKey = @"ci";
199200
NSString *const kMPRemoteConfigCookiesKey = @"ck";

mParticle-Apple-SDK/MPRokt.m

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,9 @@ - (void)close {
155155
NSData *dataAttributeMap;
156156
// Rokt Kit is available though there may not be an attribute map
157157
attributeMap = @[];
158-
if (roktKitConfig[kMPPlacementAttributesMapping] != [NSNull null]) {
159-
strAttributeMap = [roktKitConfig[kMPPlacementAttributesMapping] stringByRemovingPercentEncoding];
158+
id configJSONString = roktKitConfig[kMPRemoteConfigKitConfigurationKey][kMPPlacementAttributesMapping];
159+
if (configJSONString != nil && configJSONString != [NSNull null]) {
160+
strAttributeMap = [configJSONString stringByRemovingPercentEncoding];
160161
dataAttributeMap = [strAttributeMap dataUsingEncoding:NSUTF8StringEncoding];
161162
}
162163

@@ -167,12 +168,13 @@ - (void)close {
167168
@try {
168169
attributeMap = [NSJSONSerialization JSONObjectWithData:dataAttributeMap options:kNilOptions error:&error];
169170
} @catch (NSException *exception) {
171+
MPILogVerbose(@"Exception parsing placement attribute map: %@", exception);
170172
}
171173

172174
if (attributeMap && !error) {
173-
NSLog(@"%@", attributeMap);
175+
MPILogVerbose(@"Successfully parsed placement attribute map with %lu entries", (unsigned long)attributeMap.count);
174176
} else {
175-
NSLog(@"%@", error);
177+
MPILogVerbose(@"Failed to parse placement attribute map: %@", error);
176178
}
177179
}
178180

@@ -190,7 +192,7 @@ - (NSNumber *)getRoktHashedEmailUserIdentityType {
190192
}
191193

192194
// Get the string representing which identity to use and convert it to the key (NSNumber)
193-
NSString *hashedIdentityTypeString = roktKitConfig[kMPHashedEmailUserIdentityType];
195+
NSString *hashedIdentityTypeString = roktKitConfig[kMPRemoteConfigKitConfigurationKey][kMPHashedEmailUserIdentityType];
194196
NSNumber *hashedIdentityTypeNumber = [MPIdentityHTTPIdentities identityTypeForString:hashedIdentityTypeString.lowercaseString];
195197

196198
return hashedIdentityTypeNumber;
@@ -233,19 +235,19 @@ - (void)confirmUser:(NSDictionary<NSString *, NSString *> * _Nullable)attributes
233235

234236
[[[MParticle sharedInstance] identity] identify:identityRequest completion:^(MPIdentityApiResult *_Nullable apiResult, NSError *_Nullable error) {
235237
if (error) {
236-
NSLog(@"Failed to sync email from selectPlacement to user: %@", error);
238+
MPILogVerbose(@"Failed to sync email from selectPlacement to user: %@", error);
237239
completion(user);
238240
} else {
239-
NSLog(@"Updated user identity based off selectPlacement's attributes: %@", apiResult.user.identities);
241+
MPILogVerbose(@"Updated user identity based off selectPlacement's attributes: %@", apiResult.user.identities);
240242
completion(apiResult.user);
241243
}
242244
}];
243245

244246
// Warn the customer if we had to identify and therefore delay their Rokt placement.
245247
if (shouldIdentifyFromEmail) {
246-
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 continuing to `selectPlacements:`", user.identities[@(MPIdentityEmail)], email);
248+
MPILogVerbose(@"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 continuing to `selectPlacements:`", user.identities[@(MPIdentityEmail)], email);
247249
} else if (shouldIdentifyFromHash) {
248-
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 continuing to `selectPlacements:`", user.identities[hashedEmailIdentity], hashedEmail);
250+
MPILogVerbose(@"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 continuing to `selectPlacements:`", user.identities[hashedEmailIdentity], hashedEmail);
249251
}
250252
} else {
251253
completion(user);

0 commit comments

Comments
 (0)