Last active
January 3, 2016 04:39
-
-
Save willrust/8410938 to your computer and use it in GitHub Desktop.
KISSmetrics & Tapstream iOS integration helper. Compatible with iOS 5.0+ & KISSmetrics-iOS-SDK v2.0.0+.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//#import <KISSmetricsSDK/KISSmetricsAPI.h> | |
//#import "TSTapstream.h" | |
// Aquire km_identity from TapStream's first-run modification feature and apply as KISSmetrics alias. | |
if (![[NSUserDefaults standardUserDefaults] objectForKey:@"TSKMIdentified"]) { | |
TSTapstream *tracker = [TSTapstream instance]; | |
[tracker getConversionData:^(NSData *jsonInfo) { | |
if (jsonInfo != nil) { | |
NSError *error; | |
NSDictionary *json = [NSJSONSerialization JSONObjectWithData:jsonInfo options:kNilOptions error:&error]; | |
if (json && !error) { | |
NSArray *hits = [json objectForKey:@"hits"]; | |
if (hits.count == 0) {return;} | |
NSDictionary *hitsDictionary = [hits objectAtIndex:0]; | |
if (![hitsDictionary objectForKey:@"custom_parameters"]) {return;} | |
NSDictionary *customParameters = [hitsDictionary objectForKey:@"custom_parameters"]; | |
if ([customParameters objectForKey:@"km_identity"]) { | |
[[KISSmetricsAPI sharedAPI] alias:[customParameters objectForKey:@"km_identity"] withIdentity:[[KISSmetricsAPI sharedAPI] identity]]; | |
// This should only need to be aliased once. | |
// KISSmetrics will retain the association between this alias and the user. | |
[[NSUserDefaults standardUserDefaults] setObject:@YES forKey:@"TSKMIdentified"]; | |
} | |
} | |
} | |
}]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment