Skip to content

Instantly share code, notes, and snippets.

Last active January 3, 2016 04:39
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
KISSmetrics & Tapstream iOS integration helper. Compatible with iOS 5.0+ & KISSmetrics-iOS-SDK v2.0.0+.
//#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