Skip to content

Commit

Permalink
Update to Kochava Version 4
Browse files Browse the repository at this point in the history
  • Loading branch information
BrandonStalnaker authored Nov 18, 2020
1 parent e09ff00 commit 9d336ce
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 101 deletions.
4 changes: 2 additions & 2 deletions mParticle-Kochava.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ Pod::Spec.new do |s|
s.social_media_url = "https://twitter.com/mparticle"
s.static_framework = true

s.ios.deployment_target = "9.0"
s.ios.deployment_target = "10.3"
s.ios.source_files = 'mParticle-Kochava/*.{h,m,mm}'
s.ios.dependency 'mParticle-Apple-SDK/mParticle', '~> 8.0'
s.ios.dependency 'KochavaTrackeriOS', '~> 3.0'
s.ios.dependency 'KochavaTrackeriOS', '~> 4.0'
s.ios.pod_target_xcconfig = {
'LIBRARY_SEARCH_PATHS' => '$(inherited) $(PODS_ROOT)/KochavaTrackeriOS/**',
'OTHER_LDFLAGS' => '$(inherited) -l"KochavaTrackeriOS"'
Expand Down
3 changes: 2 additions & 1 deletion mParticle-Kochava/MPKitKochava.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ extern NSString * _Nonnull const MPKitKochavaEnhancedDeeplinkRawKey;
@property (nonatomic, unsafe_unretained, readonly) BOOL started;
@property (nonatomic, strong, nullable) MPKitAPI *kitApi;

+ (void)setIdentityLink:(nonnull NSDictionary *)identityLink;
- (void)retrieveAttributionWithCompletionHandler:(void(^)(NSDictionary *attribution))completionHandler;
+ (void)addCustomIdentityLinks:(nonnull NSDictionary *)identityLink;

@end
145 changes: 47 additions & 98 deletions mParticle-Kochava/MPKitKochava.m
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,7 @@
NSString *const kvLogScreenFormat = @"Viewed %@";
NSString *const kvEcommerce = @"eCommerce";

static KochavaTracker *kochavaTracker = nil;
static NSDictionary *kochavaIdentityLink = nil;

@interface MPKitKochava() <KochavaTrackerDelegate>
@interface MPKitKochava()

@end

Expand All @@ -39,63 +36,13 @@ + (void)load {
[MParticle registerExtension:kitRegister];
}

+ (void)setIdentityLink:(NSDictionary *)identityLink {
kochavaIdentityLink = identityLink;
+ (void)addCustomIdentityLinks:(NSDictionary *)identityLink {
for (NSString *key in identityLink.allKeys) {
[KVATracker.shared.identityLink registerWithNameString:key identifierString:identityLink[key]];
}
}

#pragma mark Accessors and private methods
- (void)kochavaTracker:(void (^)(KochavaTracker *const kochavaTracker))completionHandler {
static dispatch_once_t kochavaPredicate;

dispatch_async(dispatch_get_main_queue(), ^{
dispatch_once(&kochavaPredicate, ^{
NSMutableDictionary *kochavaInfo = [@{kKVAParamAppGUIDStringKey:self.configuration[kvAppId]
} mutableCopy];

if (self.configuration[kvCurrency]) {
kochavaInfo[@"currency"] = self.configuration[kvCurrency];
}

if (self.configuration[kvLimitAdTracking]) {
kochavaInfo[kKVAParamAppLimitAdTrackingBoolKey] = [self.configuration[kvLimitAdTracking] boolValue] ? @YES : @NO;
}

if (self.configuration[kvEnableLogging]) {
kochavaInfo[kKVAParamLogLevelEnumKey] = [self.configuration[kvEnableLogging] boolValue] ? kKVALogLevelEnumDebug : kKVALogLevelEnumNone;
}

id<KochavaTrackerDelegate> delegate = nil;

if (self.configuration[kvRetrieveAttributionData]) {
if ([self.configuration[kvRetrieveAttributionData] boolValue]) {
kochavaInfo[kKVAParamRetrieveAttributionBoolKey] = @YES;
delegate = self;
} else {
kochavaInfo[kKVAParamRetrieveAttributionBoolKey] = @NO;
}

}

if (kochavaIdentityLink) {
kochavaInfo[kKVAParamIdentityLinkDictionaryKey] = kochavaIdentityLink;
}

CFTypeRef kochavaTrackRef = CFRetain((__bridge CFTypeRef)[[KochavaTracker alloc] initWithParametersDictionary:kochavaInfo delegate:delegate]);
kochavaTracker = (__bridge KochavaTracker *)kochavaTrackRef;

dispatch_async(dispatch_get_main_queue(), ^{
NSDictionary *userInfo = @{mParticleKitInstanceKey:[[self class] kitCode]};

[[NSNotificationCenter defaultCenter] postNotificationName:mParticleKitDidBecomeActiveNotification
object:nil
userInfo:userInfo];
});
});

completionHandler(kochavaTracker);
});
}

- (void)identityLinkCustomerId {
FilteredMParticleUser *user = [self currentUser];
if (!user || user.userIdentities.count == 0) {
Expand All @@ -111,10 +58,8 @@ - (void)identityLinkCustomerId {
identityInfo[identityKey] = identityValue;
}

if (identityInfo.count > 0) {
[self kochavaTracker:^(KochavaTracker *const kochavaTracker) {
[kochavaTracker sendIdentityLinkWithDictionary:(NSDictionary *)identityInfo];
}];
for (NSString *key in identityInfo.allKeys) {
[KVATracker.shared.identityLink registerWithNameString:key identifierString:identityInfo[key]];
}
}

Expand Down Expand Up @@ -170,10 +115,8 @@ - (void)identityLinkOtherUserIds {
}
}

if (identityInfo.count > 0) {
[self kochavaTracker:^(KochavaTracker *const kochavaTracker) {
[kochavaTracker sendIdentityLinkWithDictionary:(NSDictionary *)identityInfo];
}];
for (NSString *key in identityInfo.allKeys) {
[KVATracker.shared.identityLink registerWithNameString:key identifierString:identityInfo[key]];
}
}

Expand All @@ -183,22 +126,21 @@ - (NSError *)errorWithMessage:(NSString *)message {
}

- (void)retrieveAttributionWithCompletionHandler:(void(^)(NSDictionary *attribution))completionHandler {
[self kochavaTracker:^(KochavaTracker *const kochavaTracker) {
NSDictionary *attribution = [kochavaTracker attributionDictionary];
completionHandler(attribution);
}];
}
[KVATracker.shared.attribution retrieveResultWithCompletionHandler:^(KVAAttributionResult * _Nonnull attributionResult)
{
if (!attributionResult.rawDictionary) {
[self->_kitApi onAttributionCompleteWithResult:nil error:[self errorWithMessage:@"Received nil attributionData from Kochava"]];
} else {
MPAttributionResult *mParticleResult = [[MPAttributionResult alloc] init];
mParticleResult.linkInfo = attributionResult.rawDictionary;

- (void)tracker:(nonnull KochavaTracker *)tracker didRetrieveAttributionDictionary:(nonnull NSDictionary *)attributionDictionary {
if (!attributionDictionary) {
[self->_kitApi onAttributionCompleteWithResult:nil error:[self errorWithMessage:@"Received nil attributionData from Kochava"]];
return;
}

MPAttributionResult *attributionResult = [[MPAttributionResult alloc] init];
attributionResult.linkInfo = attributionDictionary;

[self->_kitApi onAttributionCompleteWithResult:attributionResult error:nil];
[self->_kitApi onAttributionCompleteWithResult:mParticleResult error:nil];
}

if (completionHandler) {
completionHandler(attributionResult.rawDictionary);
}
}];
}

- (void)synchronize {
Expand All @@ -220,30 +162,39 @@ - (MPKitExecStatus *)didFinishLaunchingWithConfiguration:(NSDictionary *)configu
return execStatus;
}

__weak MPKitKochava *weakSelf = self;
_configuration = configuration;
_started = YES;

[self kochavaTracker:^(KochavaTracker *const kochavaTracker) {
__strong MPKitKochava *strongSelf = weakSelf;

if (!strongSelf) {
return;
}
[KVATracker.shared startWithAppGUIDString:self.configuration[kvAppId]];

if (self.configuration[kvLimitAdTracking]) {
KVATracker.shared.appLimitAdTrackingBool = [self.configuration[kvLimitAdTracking] boolValue] ? @YES : @NO;
}

if (self.configuration[kvEnableLogging]) {
KVALog.shared.level = [self.configuration[kvEnableLogging] boolValue] ? KVALogLevel.debug : KVALogLevel.never;
}

if ([configuration[kvUseCustomerId] boolValue] || [configuration[kvIncludeOtherUserIds] boolValue]) {
[self synchronize];
}

dispatch_async(dispatch_get_main_queue(), ^{
NSDictionary *userInfo = @{mParticleKitInstanceKey:[[self class] kitCode]};

if (kochavaTracker) {
if ([configuration[kvUseCustomerId] boolValue] || [configuration[kvIncludeOtherUserIds] boolValue]) {
[strongSelf synchronize];
}
}
}];
[[NSNotificationCenter defaultCenter] postNotificationName:mParticleKitDidBecomeActiveNotification
object:nil
userInfo:userInfo];
});

[self retrieveAttributionWithCompletionHandler:nil];

execStatus = [[MPKitExecStatus alloc] initWithSDKCode:[[self class] kitCode] returnCode:MPKitReturnCodeSuccess];
return execStatus;
}

- (id const)providerKitInstance {
return [self started] ? kochavaTracker : nil;
return [self started] ? KVATracker.shared : nil;
}

- (MPKitAPI *)kitApi {
Expand All @@ -255,9 +206,7 @@ - (MPKitAPI *)kitApi {
}

- (MPKitExecStatus *)setOptOut:(BOOL)optOut {
[self kochavaTracker:^(KochavaTracker *const kochavaTracker) {
[kochavaTracker setAppLimitAdTrackingBool:optOut];
}];
KVATracker.shared.appLimitAdTrackingBool = optOut;

MPKitExecStatus *execStatus = [[MPKitExecStatus alloc] initWithSDKCode:@(MPKitInstanceKochava) returnCode:MPKitReturnCodeSuccess];
return execStatus;
Expand Down

0 comments on commit 9d336ce

Please sign in to comment.