Skip to content

Instantly share code, notes, and snippets.

@drmarshall
Created June 25, 2014 01:37
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save drmarshall/2230a4439aa8439d0897 to your computer and use it in GitHub Desktop.
Save drmarshall/2230a4439aa8439d0897 to your computer and use it in GitHub Desktop.
#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;
}
@drmarshall
Copy link
Author

  1. Where to put the code: The logic for this functionality should go in your AppDelegate.m, in the -application:didFinishLaunchingWithOptions: method.
  2. How to call it without blocking: As shown in the example.
  3. How to parse out the JSON: As shown in the example (iOS 6+ only).
  4. 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