Skip to Content

Getting the data with Mixpanel and iOS

Posted on 2 mins read

It’s easy to get used to having detailed statistics when developing web apps, using split tests to determine the better optimisations and finding patterns in usage that lead to your most profitable customers and features. When developing iOS apps, these stats are much harder to collect.

Thankfully, there is a service that helps aleviate this problem: Mixpanel.

Integrating your app with the Mixpanel API is a simple case of grabbing their library, importing the MPLib filder and adding the include to your prefix header:

#import "MixpanelAPI.h"

… initialising the lib in your app delegate:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
  MixpanelAPI* mixpanel = [MixpanelAPI sharedAPIWithToken:@"Your Token"];

  [mixpanel registerSuperProperties:[NSDictionary dictionaryWithObjectsAndKeys:
      [[UIDevice currentDevice] systemVersion], @"OS Version",
      [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleVersion"], @"version", nil

  [mixpanel track:@"App Launch"];

  // Override point for customization after app launch
  [window addSubview:[navigationController view]];
  [window makeKeyAndVisible];

  return YES;

… and collecting metrics as you see fit:

MixpanelAPI *mixpanel = [MixpanelAPI sharedAPI];
[mixpanel track:@"Checkin"];

Instead of synchronously sending data back to your Mixpanel, individual events are queued up and sent as a connection is available - good news if your app is going to be used when net connectivity may be poor.

Additionally, you can send properties that allow you to segment your data further. In the above example, I send the OS version and app bundle version with every request. Collecting these additional details will let me determine whether a particular pattern can be attributed to either of these attributes.