Skip to content

Commit 6637af6

Browse files
feat: Update Forwarding Logic (#19)
1 parent 5889c33 commit 6637af6

1 file changed

Lines changed: 68 additions & 85 deletions

File tree

mParticle-Kochava/MPKitKochava.m

Lines changed: 68 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414

1515
NSString *const kvAppId = @"appId";
1616
NSString *const kvCurrency = @"currency";
17-
NSString *const kvUseCustomerId = @"useCustomerId";
18-
NSString *const kvIncludeOtherUserIds = @"passAllOtherUserIdentities";
17+
NSString *const kvUserIdentificationType = @"userIdentificationType";
18+
NSString *const kvEmailIdentificationType = @"emailIdentificationType";
1919
NSString *const kvRetrieveAttributionData = @"retrieveAttributionData";
2020
NSString *const kvEnableLogging = @"enableLogging";
2121
NSString *const kvLimitAdTracking = @"limitAdTracking";
@@ -130,27 +130,30 @@ + (void)addCustomIdentityLinks:(NSDictionary *)identityLink {
130130
}
131131

132132
#pragma mark Accessors and private methods
133-
- (void)identityLinkCustomerId {
134-
FilteredMParticleUser *user = [self currentUser];
135-
if (!user || user.userIdentities.count == 0) {
136-
return;
137-
}
138-
139-
NSMutableDictionary *identityInfo = [[NSMutableDictionary alloc] initWithCapacity:user.userIdentities.count];
140-
NSString *identityKey;
141-
142-
NSString *identityValue = user.userIdentities[@(MPUserIdentityCustomerId)];
143-
if (identityValue) {
144-
identityKey = @"CustomerId";
145-
identityInfo[identityKey] = identityValue;
146-
}
147-
148-
for (NSString *key in identityInfo.allKeys) {
149-
[KVAIdentityLink registerWithName:key identifier:identityInfo[key]];
150-
}
133+
- (NSError *)errorWithMessage:(NSString *)message {
134+
NSError *error = [NSError errorWithDomain:MPKitKochavaErrorDomain code:0 userInfo:@{MPKitKochavaErrorKey:message}];
135+
return error;
136+
}
137+
138+
- (void)retrieveAttributionWithCompletionHandler:(void(^)(NSDictionary *attribution))completionHandler {
139+
[KVATracker.shared.attribution retrieveResultWithCompletionHandler:^(KVAAttributionResult * _Nonnull attributionResult)
140+
{
141+
if (!attributionResult.rawDictionary) {
142+
[self->_kitApi onAttributionCompleteWithResult:nil error:[self errorWithMessage:@"Received nil attributionData from Kochava"]];
143+
} else {
144+
MPAttributionResult *mParticleResult = [[MPAttributionResult alloc] init];
145+
mParticleResult.linkInfo = attributionResult.rawDictionary;
146+
147+
[self->_kitApi onAttributionCompleteWithResult:mParticleResult error:nil];
148+
}
149+
150+
if (completionHandler) {
151+
completionHandler(attributionResult.rawDictionary);
152+
}
153+
}];
151154
}
152155

153-
- (void)identityLinkOtherUserIds {
156+
- (void)synchronizeIdentity {
154157
FilteredMParticleUser *user = [self currentUser];
155158
if (!user.userIdentities || user.userIdentities.count == 0) {
156159
return;
@@ -163,32 +166,52 @@ - (void)identityLinkOtherUserIds {
163166
userIdentity = [userIdentityType integerValue];
164167

165168
switch (userIdentity) {
166-
case MPUserIdentityEmail:
167-
identityKey = @"Email";
169+
case MPUserIdentityCustomerId:
170+
identityKey = @"CustomerId";
168171
break;
169172

170173
case MPUserIdentityOther:
171-
identityKey = @"OtherId";
174+
identityKey = @"Other";
175+
break;
176+
177+
case MPUserIdentityOther2:
178+
identityKey = @"Other2";
179+
break;
180+
181+
case MPUserIdentityOther3:
182+
identityKey = @"Other3";
183+
break;
184+
185+
case MPUserIdentityOther4:
186+
identityKey = @"Other4";
187+
break;
188+
189+
case MPUserIdentityOther5:
190+
identityKey = @"Other5";
191+
break;
192+
193+
case MPUserIdentityOther6:
194+
identityKey = @"Other6";
172195
break;
173196

174-
case MPUserIdentityFacebook:
175-
identityKey = @"Facebook";
197+
case MPUserIdentityOther7:
198+
identityKey = @"Other7";
176199
break;
177200

178-
case MPUserIdentityTwitter:
179-
identityKey = @"Twitter";
201+
case MPUserIdentityOther8:
202+
identityKey = @"Other8";
180203
break;
181204

182-
case MPUserIdentityGoogle:
183-
identityKey = @"Google";
205+
case MPUserIdentityOther9:
206+
identityKey = @"Other9";
184207
break;
185208

186-
case MPUserIdentityYahoo:
187-
identityKey = @"Yahoo";
209+
case MPUserIdentityOther10:
210+
identityKey = @"Other10";
188211
break;
189212

190-
case MPUserIdentityMicrosoft:
191-
identityKey = @"Microsoft";
213+
case MPUserIdentityEmail:
214+
identityKey = @"Email";
192215
break;
193216

194217
default:
@@ -198,7 +221,12 @@ - (void)identityLinkOtherUserIds {
198221

199222
NSString *identityValue = user.userIdentities[userIdentityType];
200223
if (identityValue) {
201-
identityInfo[identityKey] = identityValue;
224+
if ([self.configuration[kvUserIdentificationType] isEqualToString:identityKey]) {
225+
identityInfo[identityKey] = identityValue;
226+
}
227+
if ([self.configuration[kvEmailIdentificationType] isEqualToString:identityKey]) {
228+
identityInfo[identityKey] = identityValue;
229+
}
202230
}
203231
}
204232

@@ -207,39 +235,6 @@ - (void)identityLinkOtherUserIds {
207235
}
208236
}
209237

210-
- (NSError *)errorWithMessage:(NSString *)message {
211-
NSError *error = [NSError errorWithDomain:MPKitKochavaErrorDomain code:0 userInfo:@{MPKitKochavaErrorKey:message}];
212-
return error;
213-
}
214-
215-
- (void)retrieveAttributionWithCompletionHandler:(void(^)(NSDictionary *attribution))completionHandler {
216-
[KVATracker.shared.attribution retrieveResultWithCompletionHandler:^(KVAAttributionResult * _Nonnull attributionResult)
217-
{
218-
if (!attributionResult.rawDictionary) {
219-
[self->_kitApi onAttributionCompleteWithResult:nil error:[self errorWithMessage:@"Received nil attributionData from Kochava"]];
220-
} else {
221-
MPAttributionResult *mParticleResult = [[MPAttributionResult alloc] init];
222-
mParticleResult.linkInfo = attributionResult.rawDictionary;
223-
224-
[self->_kitApi onAttributionCompleteWithResult:mParticleResult error:nil];
225-
}
226-
227-
if (completionHandler) {
228-
completionHandler(attributionResult.rawDictionary);
229-
}
230-
}];
231-
}
232-
233-
- (void)synchronize {
234-
if ([self.configuration[kvUseCustomerId] boolValue]) {
235-
[self identityLinkCustomerId];
236-
}
237-
238-
if ([self.configuration[kvIncludeOtherUserIds] boolValue]) {
239-
[self identityLinkOtherUserIds];
240-
}
241-
}
242-
243238
#pragma mark MPKitInstanceProtocol methods
244239
- (MPKitExecStatus *)didFinishLaunchingWithConfiguration:(NSDictionary *)configuration {
245240
MPKitExecStatus *execStatus = nil;
@@ -277,8 +272,8 @@ - (void)start {
277272
KVALog.shared.level = [self.configuration[kvEnableLogging] boolValue] ? KVALogLevel.debug : KVALogLevel.never;
278273
}
279274

280-
if ([self.configuration[kvUseCustomerId] boolValue] || [self.configuration[kvIncludeOtherUserIds] boolValue]) {
281-
[self synchronize];
275+
if (self.configuration[kvUserIdentificationType] || self.configuration[kvEmailIdentificationType] ) {
276+
[self synchronizeIdentity];
282277
}
283278

284279
NSDictionary *userActivityDictionary = self.launchOptions[UIApplicationLaunchOptionsUserActivityDictionaryKey];
@@ -429,21 +424,9 @@ - (MPKitExecStatus *)setUserIdentity:(NSString *)identityString identityType:(MP
429424
return execStatus;
430425
}
431426

432-
if (user.userIdentities[@(identityType)] && [user.userIdentities[@(identityType)] isEqual:identityString]) {
433-
execStatus = [[MPKitExecStatus alloc] initWithSDKCode:@(MPKitInstanceKochava) returnCode:MPKitReturnCodeRequirementsNotMet];
434-
return execStatus;
435-
}
436-
437-
if (identityType == MPUserIdentityCustomerId) {
438-
if ([self.configuration[kvUseCustomerId] boolValue]) {
439-
[self identityLinkCustomerId];
440-
execStatus = [[MPKitExecStatus alloc] initWithSDKCode:@(MPKitInstanceKochava) returnCode:MPKitReturnCodeSuccess];
441-
}
442-
} else {
443-
if ([self.configuration[kvIncludeOtherUserIds] boolValue]) {
444-
[self identityLinkOtherUserIds];
445-
execStatus = [[MPKitExecStatus alloc] initWithSDKCode:@(MPKitInstanceKochava) returnCode:MPKitReturnCodeSuccess];
446-
}
427+
if (self.configuration[kvUserIdentificationType] || self.configuration[kvEmailIdentificationType] ) {
428+
[self synchronizeIdentity];
429+
execStatus = [[MPKitExecStatus alloc] initWithSDKCode:@(MPKitInstanceKochava) returnCode:MPKitReturnCodeSuccess];
447430
}
448431

449432
if (!execStatus) {

0 commit comments

Comments
 (0)