> ## Documentation Index
> Fetch the complete documentation index at: https://mintlify.com/mixpanel/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# iOS SDK (Objective-C)

> Track events from iOS apps with the Mixpanel Objective-C SDK

## Installation

<Tabs>
  <Tab title="CocoaPods">
    <Steps>
      <Step title="Install CocoaPods">
        ```bash theme={null}
        gem install cocoapods
        pod setup
        ```
      </Step>

      <Step title="Create Podfile">
        ```bash theme={null}
        pod init
        ```
      </Step>

      <Step title="Add Mixpanel">
        ```ruby theme={null}
        target 'MyApp' do
          pod 'Mixpanel'
        end
        ```
      </Step>

      <Step title="Install">
        ```bash theme={null}
        pod install
        ```
      </Step>
    </Steps>
  </Tab>

  <Tab title="Carthage">
    Add to your `Cartfile`:

    ```bash theme={null}
    github "mixpanel/mixpanel-iphone"
    ```
  </Tab>

  <Tab title="Swift Package Manager">
    1. In Xcode: File > Add Packages...
    2. Enter: `https://github.com/mixpanel/mixpanel-iphone`
    3. Select version v4.0.0+
  </Tab>
</Tabs>

## Initialize

In `AppDelegate.m`:

```objc theme={null}
#import "Mixpanel/Mixpanel.h"

- (BOOL)application:(UIApplication *)application
    didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
  
  [Mixpanel sharedInstanceWithToken:@"YOUR_PROJECT_TOKEN"
                 trackAutomaticEvents:NO];
  
  return YES;
}
```

Access the instance:

```objc theme={null}
Mixpanel *mixpanel = [Mixpanel sharedInstance];
```

## Track Events

```objc theme={null}
Mixpanel *mixpanel = [Mixpanel sharedInstance];

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

### Timing Events

```objc theme={null}
[mixpanel timeEvent:@"Image Upload"];

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

### Flush Events

```objc theme={null}
// Flush immediately
[mixpanel flush];

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

## Identify Users

```objc theme={null}
Mixpanel *mixpanel = [Mixpanel sharedInstance];

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

### Reset on Logout

```objc theme={null}
[mixpanel track:@"log out"];
[mixpanel reset];
```

## User Profiles

```objc theme={null}
Mixpanel *mixpanel = [Mixpanel sharedInstance];

[mixpanel identify:@"12345"];
[mixpanel.people set:@{
  @"Plan": @"Premium",
  @"$email": @"user@example.com",
  @"$name": @"John Doe"
}];
```

<Tabs>
  <Tab title="setOnce:">
    ```objc theme={null}
    [mixpanel.people setOnce:@{
      @"First Login": [NSDate date]
    }];
    ```
  </Tab>

  <Tab title="increment:by:">
    ```objc theme={null}
    [mixpanel.people increment:@"age" by:@1];
    [mixpanel.people increment:@"login_count" by:@1];
    ```
  </Tab>

  <Tab title="append:">
    ```objc theme={null}
    [mixpanel.people append:@{
      @"roles": @"admin"
    }];
    ```
  </Tab>

  <Tab title="union:">
    ```objc theme={null}
    // Add without duplicates
    [mixpanel.people union:@{
      @"skills": @"iOS Development"
    }];
    ```
  </Tab>
</Tabs>

## Super Properties

```objc theme={null}
Mixpanel *mixpanel = [Mixpanel sharedInstance];

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

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

## Group Analytics

```objc theme={null}
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

```objc theme={null}
[mixpanel optOutTracking];

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

### EU/India Data Residency

```objc theme={null}
Mixpanel *mixpanel = [Mixpanel sharedInstance];

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

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

### Disable Geolocation

```objc theme={null}
[Mixpanel sharedInstance].useIPAddressForGeoLocation = NO;
```

## Debug Mode

```objc theme={null}
[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

<Info>
  Since v3.6.2, Mixpanel no longer uses IDFA by default.
</Info>

## Resources

* [Full API Reference](https://mixpanel.github.io/mixpanel-iphone/index.html)
* [GitHub Repository](https://github.com/mixpanel/mixpanel-iphone)
* [Example App](https://github.com/mixpanel/mixpanel-iphone/tree/master/HelloMixpanel)
