Created
June 25, 2014 01:37
-
-
Save drmarshall/2230a4439aa8439d0897 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 "TSTapstream.h" | |
#define MIXPANEL_TOKEN @"YOUR_MIXPANEL_TOKEN" | |
// ... | |
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions | |
{ | |
[Mixpanel sharedInstanceWithToken:MIXPANEL_TOKEN]; | |
TSConfig *config = [TSConfig configWithDefaults]; | |
[TSTapstream createWithAccountName:@"YOUR_TAPSTREAM_ACCOUNT_NAME" developerSecret:@"YOUR_TAPSTREAM_SDK_SECRET" config:config]; | |
TSTapstream *tracker = [TSTapstream instance]; | |
// Call getConversionData to get the user's timeline history | |
[tracker getConversionData:^(NSData *jsonInfo) { | |
if(jsonInfo == nil) | |
{ | |
// No conversion data available | |
} | |
else | |
{ | |
NSError *error = nil; | |
NSDictionary *json = [NSJSONSerialization JSONObjectWithData:jsonInfo options:kNilOptions error:&error]; | |
if(!json || error) | |
{ | |
// No luck parsing the JSON | |
} | |
else | |
{ | |
NSArray* hits = [json objectForKey:@"hits"]; | |
if(!hits || [hits count] == 0) | |
{ | |
// No hits in timeline | |
} | |
else | |
{ | |
// Hit exists in timeline | |
NSDictionary* hit = [hits objectAtIndex:0]; // Grab the oldest hit | |
if(!hit) | |
{ | |
// Couldn't get any hits | |
} | |
else | |
{ | |
// Get the slug of the Tapstream tracker that this user was attributed to. | |
// For a complete example of the returned JSON, including other | |
// data, please see: | |
// http://docs.tapstream.apiary.io/ | |
NSString* slug = [hit objectForKey:@"tracker"]; | |
// Set a Mixpanel super property called 'source' to the Tapstream tracker | |
// that this user was attributed to | |
Mixpanel *mixpanel = [Mixpanel sharedInstance]; | |
[mixpanel registerSuperPropertiesOnce:@{@"source": slug}]; | |
} | |
} | |
} | |
} | |
}]; | |
//... | |
return YES; | |
} |
Author
drmarshall
commented
Jun 25, 2014
- Where to put the code: The logic for this functionality should go in your AppDelegate.m, in the -application:didFinishLaunchingWithOptions: method.
- How to call it without blocking: As shown in the example.
- How to parse out the JSON: As shown in the example (iOS 6+ only).
- What to do if nil comes back: This means that Tapstream doesn't know where the user came from; in general, the developer shouldn't do anything in this case (it's an organic user, or a user that hasn't converted yet).
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment