> For the complete documentation index, see [llms.txt](https://doc.batch.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://doc.batch.com/developer/sdk/ios/event-dispatchers/mixpanel.md).

# Mixpanel

The Mixpanel dispatcher automatically dispatches events to the [Mixpanel SDK](https://developer.mixpanel.com/docs/ios), using UTM tags when available.

Two flavors of the dispatcher are available, depending on which flavour of the Mixpanel SDK you're using:

* One for the Objective-C Mixpanel SDK
* One for the Swift Mixpanel SDK

{% tabs %}
{% tab title="SPM" %}

```
"https://github.com/BatchLabs/Batch-iOS-mixpanel-swift-dispatcher"
```

{% endtab %}

{% tab title="CocoaPods" %}
{% code title="Podfile" %}

```yaml
pod 'BatchMixpanelSwiftDispatcher'
# or
# pod 'BatchMixpanelObjcDispatcher'
```

{% endcode %}
{% endtab %}

{% tab title="Carthage" %}
{% code title="Cartfile" %}

```yaml
github "BatchLabs/Batch-iOS-mixpanel-swift-dispatcher"
# or
# github "BatchLabs/Batch-iOS-mixpanel-objc-dispatcher"
```

{% endcode %}
{% endtab %}
{% endtabs %}

Don't forget to register the dispatcher:

{% tabs %}
{% tab title="Swift" %}

```swift
import Batch
import BatchMixpanelSwiftDispatcher
// or import BatchMixpanelObjcDispatcher
import Mixpanel

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
    
    func application(_ application: UIApplication,
                     didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        // Find your mixpanel setup line, which looks like this:
        let mixpanel = Mixpanel.initialize(token: "MIXPANEL_TOKEN")
        // Objective-C Mixpanel SDK users: let mixpanel = Mixpanel.sharedInstance(withToken: "MIXPANEL_TOKEN")

        let mixpanelDispatcher = BatchMixpanelSwiftDispatcher.instance
        // If you're using BatchMixpanelObjcDispatcher, comment the previous lines and uncomment the next one
        // let mixpanelDispatcher = BatchMixpanelObjcDispatcher.instance()
         
        // Tell Batch about your Mixpanel instance to enable tracking
        mixpanelDispatcher.mixpanelInstance = mixpanel
        BatchEventDispatcher.add(mixpanelDispatcher)

        [...]

        BatchSDK.start(withAPIKey: "YOUR_API_KEY")
        return true
    }
}
```

{% endtab %}

{% tab title="Objective-C" %}

```objectivec
// MYAppDelegate.m

@import Batch;
@import BatchMixpanelObjcDispatcher;
@import Mixpanel;

@implementation MYAppDelegate

- (BOOL)application:(UIApplication *)application 
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    // Find your mixpanel setup line, which looks like this:
    Mixpanel *mixpanel = [Mixpanel sharedInstanceWithToken:@"MIXPANEL_TOKEN"];
    
    // BatchMixpanelSwiftDispatcher isn't supported from Objective-C
    BatchMixpanelObjcDispatcher *mixpanelDispatcher = [BatchMixpanelObjcDispatcher instance];
    // Tell Batch about your Mixpanel instance to enable tracking
    mixpanelDispatcher.mixpanelInstance = mixpanel;
    [BatchEventDispatcher addDispatcher:mixpanelDispatcher];

    [...]

    [BatchSDK startWithAPIKey:@"MY_API_KEY"];
    return YES;
}

@end
```

{% endtab %}
{% endtabs %}

Once your dispatcher is installed, restart your app and you should see something like this in your log:

```
[Batch] EventDispatcher - Adding event dispatcher: BatchFirebaseDispatcher
```

{% hint style="info" %}
If you can't find the line in your log, it may be due to missing dependencies, be sure to add the AT Internet and/or Firebase Analytics SDKs to your project.
{% endhint %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://doc.batch.com/developer/sdk/ios/event-dispatchers/mixpanel.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
