Skip to main content

Installation

1

Install CocoaPods

gem install cocoapods
pod setup
2

Create Podfile

pod init
3

Add Mixpanel

target 'MyApp' do
  pod 'Mixpanel'
end
4

Install

pod install

Initialize

In AppDelegate.m:
#import "Mixpanel/Mixpanel.h"

- (BOOL)application:(UIApplication *)application
    didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
  
  [Mixpanel sharedInstanceWithToken:@"YOUR_PROJECT_TOKEN"
                 trackAutomaticEvents:NO];
  
  return YES;
}
Access the instance:
Mixpanel *mixpanel = [Mixpanel sharedInstance];

Track Events

Mixpanel *mixpanel = [Mixpanel sharedInstance];

[mixpanel track:@"Video Watched"
     properties:@{
       @"video_title": @"iOS Development",
       @"duration": @120,
       @"quality": @"HD"
     }];

Timing Events

[mixpanel timeEvent:@"Image Upload"];

// 20 seconds later
[self uploadImageWithSuccessHandler:^{
  [mixpanel track:@"Image Upload"];
}];

Flush Events

// Flush immediately
[mixpanel flush];

// Adjust flush interval (seconds)
[Mixpanel sharedInstance].flushInterval = 120;

Identify Users

Mixpanel *mixpanel = [Mixpanel sharedInstance];

[mixpanel track:@"sign in"];
[mixpanel identify:@"12345"];

Reset on Logout

[mixpanel track:@"log out"];
[mixpanel reset];

User Profiles

Mixpanel *mixpanel = [Mixpanel sharedInstance];

[mixpanel identify:@"12345"];
[mixpanel.people set:@{
  @"Plan": @"Premium",
  @"$email": @"[email protected]",
  @"$name": @"John Doe"
}];
[mixpanel.people setOnce:@{
  @"First Login": [NSDate date]
}];

Super Properties

Mixpanel *mixpanel = [Mixpanel sharedInstance];

[mixpanel registerSuperProperties:@{
  @"App Version": @"2.0.1",
  @"Platform": @"iOS"
}];

// Register without overwriting
[mixpanel registerSuperPropertiesOnce:@{
  @"First Launch": [NSDate date]
}];

Group Analytics

Mixpanel *mixpanel = [Mixpanel sharedInstance];

// Assign to group
[mixpanel setGroup:@"company" groupID:@"Acme Inc"];

// Track event
[mixpanel track:@"feature_used"];

// Set group properties
[[mixpanel getGroup:@"company" groupID:@"Acme Inc"] set:@{
  @"industry": @"Technology",
  @"employees": @500
}];

Privacy Controls

Opt Out

[mixpanel optOutTracking];

// Initialize with opt-out
Mixpanel *mixpanel = [Mixpanel sharedInstanceWithToken:@"YOUR_PROJECT_TOKEN"
                                   trackAutomaticEvents:NO
                                optOutTrackingByDefault:YES];

EU/India Data Residency

Mixpanel *mixpanel = [Mixpanel sharedInstance];

// EU
mixpanel.serverURL = @"https://api-eu.mixpanel.com";

// India
mixpanel.serverURL = @"https://api-in.mixpanel.com";

Disable Geolocation

[Mixpanel sharedInstance].useIPAddressForGeoLocation = NO;

Debug Mode

[Mixpanel sharedInstance].enableLogging = YES;
Or add to build settings Preprocessor Macros:
  • MIXPANEL_DEBUG=1
  • MIXPANEL_ERROR=1

Platform Considerations

  • Events flush every 60 seconds or on app background
  • Requires iOS 9.0+
  • Uses IFV (Identifier for Vendor) for distinct_id
  • Super properties persist in local storage
  • Supports push notification tracking
Since v3.6.2, Mixpanel no longer uses IDFA by default.

Resources

Build docs developers (and LLMs) love