Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#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

This comment has been minimized.

Copy link
Owner Author

@drmarshall drmarshall commented Jun 25, 2014

  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
You can’t perform that action at this time.