# Mixpanel

    open class Mixpanel

The primary class for integrating Mixpanel with your app.

- `initialize(options:)`

  Undocumented

  #### Declaration

  Swift

      @discardableResult
      open class func initialize(options: MixpanelOptions) -> MixpanelInstance

- `initialize(token:trackAutomaticEvents:flushInterval:instanceName:optOutTrackingByDefault:useUniqueDistinctId:superProperties:serverURL:useGzipCompression:)`

  Initializes an instance of the API with the given project token.

  Returns a new Mixpanel instance API object. This allows you to create more than one instance of the API object, which is convenient if you’d like to send data to more than one Mixpanel project from a single app.

  Important

  If you have more than one Mixpanel instance, it is beneficial to initialize the instances with an instanceName. Then they can be reached by calling getInstance with name.

  #### Declaration

  Swift

      @discardableResult
      open class func initialize(
        token apiToken: String,
        trackAutomaticEvents: Bool,
        flushInterval: Double = 60,
        instanceName: String? = nil,
        optOutTrackingByDefault: Bool = false,
        useUniqueDistinctId: Bool = false,
        superProperties: Properties? = nil,
        serverURL: String? = nil,
        useGzipCompression: Bool = false
      ) -> MixpanelInstance

  #### Parameters

  `token` | your project token
  `trackAutomaticEvents` | Whether or not to collect common mobile events
  `flushInterval` | Optional. Interval to run background flushing
  `instanceName` | Optional. The name you want to uniquely identify the Mixpanel Instance. It is useful when you want more than one Mixpanel instance under the same project token.
  `optOutTrackingByDefault` | Optional. Whether or not to be opted out from tracking by default
  `useUniqueDistinctId` | Optional. whether or not to use the unique device identifier as the distinct_id
  `superProperties` | Optional. Super properties dictionary to register during initialization
  `serverURL` | Optional. Mixpanel cluster URL
  `useGzipCompression` | Optional. Whether to use gzip compression for network requests.

  #### Return Value

  returns a mixpanel instance if needed to keep throughout the project. You can always get the instance by calling getInstance(name)

- `initialize(token:trackAutomaticEvents:flushInterval:instanceName:optOutTrackingByDefault:useUniqueDistinctId:superProperties:proxyServerConfig:useGzipCompression:)`

  Initializes an instance of the API with the given project token.

  Returns a new Mixpanel instance API object. This allows you to create more than one instance of the API object, which is convenient if you’d like to send data to more than one Mixpanel project from a single app.

  Important

  If you have more than one Mixpanel instance, it is beneficial to initialize the instances with an instanceName. Then they can be reached by calling getInstance with name.

  #### Declaration

  Swift

      @discardableResult
      open class func initialize(
        token apiToken: String,
        trackAutomaticEvents: Bool,
        flushInterval: Double = 60,
        instanceName: String? = nil,
        optOutTrackingByDefault: Bool = false,
        useUniqueDistinctId: Bool = false,
        superProperties: Properties? = nil,
        proxyServerConfig: ProxyServerConfig,
        useGzipCompression: Bool = false
      ) -> MixpanelInstance

  #### Parameters

  `token` | your project token
  `trackAutomaticEvents` | Whether or not to collect common mobile events
  `flushInterval` | Optional. Interval to run background flushing
  `instanceName` | Optional. The name you want to uniquely identify the Mixpanel Instance. It is useful when you want more than one Mixpanel instance under the same project token.
  `optOutTrackingByDefault` | Optional. Whether or not to be opted out from tracking by default
  `useUniqueDistinctId` | Optional. whether or not to use the unique device identifier as the distinct_id
  `superProperties` | Optional. Super properties dictionary to register during initialization
  `proxyServerConfig` | Optional. Setup for proxy server.
  `useGzipCompression` | Optional. Whether to use gzip compression for network requests.

  #### Return Value

  returns a mixpanel instance if needed to keep throughout the project. You can always get the instance by calling getInstance(name)

- `initialize(token:flushInterval:instanceName:optOutTrackingByDefault:useUniqueDistinctId:superProperties:serverURL:useGzipCompression:)`

  Initializes an instance of the API with the given project token (MAC OS ONLY).

  Returns a new Mixpanel instance API object. This allows you to create more than one instance of the API object, which is convenient if you’d like to send data to more than one Mixpanel project from a single app.

  Important

  If you have more than one Mixpanel instance, it is beneficial to initialize the instances with an instanceName. Then they can be reached by calling getInstance with name.

- `initialize(token:flushInterval:instanceName:optOutTrackingByDefault:useUniqueDistinctId:superProperties:proxyServerConfig:useGzipCompression:)`

  Initializes an instance of the API with the given project token (MAC OS ONLY).

  Returns a new Mixpanel instance API object. This allows you to create more than one instance of the API object, which is convenient if you’d like to send data to more than one Mixpanel project from a single app.

  Important

  If you have more than one Mixpanel instance, it is beneficial to initialize the instances with an instanceName. Then they can be reached by calling getInstance with name.

- `getInstance(name:)`

  Gets the mixpanel instance with the given name

  #### Declaration

  Swift

      open class func getInstance(name: String) -> MixpanelInstance?

  #### Parameters

  `name` | the instance name

  #### Return Value

  returns the mixpanel instance

- `mainInstance()`

  Returns the main instance that was initialized.

  If not specified explicitly, the main instance is always the last instance added

  #### Declaration

  Swift

      open class func mainInstance() -> MixpanelInstance

  #### Return Value

  returns the main Mixpanel instance

- `safeMainInstance()`

  Returns the main Mixpanel instance if it has been initialized.

  #### Declaration

  Swift

      public class func safeMainInstance() -> MixpanelInstance?

  #### Return Value

  An optional MixpanelInstance, or nil if not yet initialized.

- `setMainInstance(name:)`

  Sets the main instance based on the instance name

  #### Declaration

  Swift

      open class func setMainInstance(name: String)

  #### Parameters

  `name` | the instance name

- `removeInstance(name:)`

  Removes an unneeded Mixpanel instance based on its name

  #### Declaration

  Swift

      open class func removeInstance(name: String)

  #### Parameters

  `name` | the instance name

© 2026 Mixpanel. All rights reserved. (Last updated: 2026-03-17)

Generated by jazzy ♪♫ v0.15.4, a Realm project.