MixpanelInstance

open class MixpanelInstance: CustomDebugStringConvertible, FlushDelegate, AEDelegate

The class that represents the Mixpanel Instance

  • The a MixpanelDelegate object that gives control over Mixpanel network activity.

    Declaration

    Swift

    open var delegate: MixpanelDelegate?
  • distinctId string that uniquely identifies the current user.

    Declaration

    Swift

    open var distinctId = ""
  • anonymousId string that uniquely identifies the device.

    Declaration

    Swift

    open var anonymousId: String? = nil
  • userId string that identify is called with.

    Declaration

    Swift

    open var userId: String? = nil
  • hadPersistedDistinctId is a boolean value which specifies that the stored distinct_id already exists in persistence

    Declaration

    Swift

    open var hadPersistedDistinctId: Bool? = nil
  • alias string that uniquely identifies the current user.

    Declaration

    Swift

    open var alias: String? = nil
  • Accessor to the Mixpanel People API object.

    Declaration

    Swift

    open var people: People!
  • Controls whether to show spinning network activity indicator when flushing data to the Mixpanel servers. Defaults to true.

    Declaration

    Swift

    open var showNetworkActivityIndicator = true
  • Flush timer’s interval. Setting a flush interval of 0 will turn off the flush timer.

    Declaration

    Swift

    open var flushInterval: Double
  • Control whether the library should flush data to Mixpanel when the app enters the background. Defaults to true.

    Declaration

    Swift

    open var flushOnBackground: Bool
  • Controls whether to automatically send the client IP Address as part of event tracking. With an IP address, the Mixpanel Dashboard will show you the users’ city. Defaults to true.

    Declaration

    Swift

    open var useIPAddressForGeoLocation: Bool
  • The base URL used for Mixpanel API requests. Useful if you need to proxy Mixpanel requests. Defaults to https://api.mixpanel.com.

    Declaration

    Swift

    open var serverURL = BasePath.DefaultMixpanelAPI
  • Declaration

    Swift

    open var debugDescription: String
  • This allows enabling or disabling of all Mixpanel logs at run time.

    Note

    All logging is disabled by default. Usually, this is only required if you are running in to issues with the SDK and you need support.

    Declaration

    Swift

    open var loggingEnabled: Bool = false
  • A unique identifier for this MixpanelInstance

    Declaration

    Swift

    public let name: String
  • Controls whether to enable the visual editor for codeless on mixpanel.com You will be unable to edit codeless events with this disabled, however previously created codeless events will still be delivered.

    Declaration

    Swift

    open var enableVisualEditorForCodeless: Bool
  • Controls whether to automatically check for A/B test variants for the currently identified user when the application becomes active. Defaults to true.

    Declaration

    Swift

    open var checkForVariantsOnActive: Bool
  • Controls whether to automatically check for notifications for the currently identified user when the application becomes active. Defaults to true.

    Declaration

    Swift

    open var checkForNotificationOnActive: Bool
  • Controls whether to automatically check for and show in-app notifications for the currently identified user when the application becomes active. Defaults to true.

    Declaration

    Swift

    open var showNotificationOnActive: Bool
  • Determines the time, in seconds, that a mini notification will remain on the screen before automatically hiding itself. Defaults to 6 (seconds).

    Declaration

    Swift

    open var miniNotificationPresentationTime: Double
  • The minimum session duration (ms) that is tracked in automatic events. The default value is 10000 (10 seconds).

    Declaration

    Swift

    open var minimumSessionDuration: UInt64
  • The maximum session duration (ms) that is tracked in automatic events. The default value is UINT64_MAX (no maximum session duration).

    Declaration

    Swift

    open var maximumSessionDuration: UInt64
  • Undocumented

    Declaration

    Swift

    deinit
  • Sets the distinct ID of the current user.

    Mixpanel will choose a default distinct ID based on whether you are using the AdSupport.framework or not.

    If you are not using the AdSupport Framework (iAds), then we use the IFV String (UIDevice.current().identifierForVendor) as the default distinct ID. This ID will identify a user across all apps by the same vendor, but cannot be used to link the same user across apps from different vendors. If we are unable to get the IFV, we will fall back to generating a random persistent UUID

    If you are showing iAds in your application, you are allowed use the iOS ID for Advertising (IFA) to identify users. If you have this framework in your app, Mixpanel will use the IFA as the default distinct ID. If you have AdSupport installed but still don’t want to use the IFA, you can define the MIXPANEL_NO_IFA flag in your Active Compilation Conditions build settings, and Mixpanel will use the IFV as the default distinct ID.

    If we are unable to get an IFA or IFV, we will fall back to generating a random persistent UUID. If you want to always use a random persistent UUID you can define the MIXPANEL_RANDOM_DISTINCT_ID preprocessor flag in your build settings.

    For tracking events, you do not need to call identify: if you want to use the default. However, Mixpanel People always requires an explicit call to identify:. If calls are made to set:, increment or other People methods prior to calling identify:, then they are queued up and flushed once identify: is called.

    If you’d like to use the default distinct ID for Mixpanel People as well (recommended), call identify: using the current distinct ID: mixpanelInstance.identify(mixpanelInstance.distinctId).

    Declaration

    Swift

    open func identify(distinctId: String, usePeople: Bool = true)

    Parameters

    distinctId

    string that uniquely identifies the current user

    usePeople

    boolean that controls whether or not to set the people distinctId to the event distinctId. This should only be set to false if you wish to prevent people profile updates for that user.

  • Creates a distinctId alias from alias to the current id.

    This method is used to map an identifier called an alias to the existing Mixpanel distinct id. This causes all events and people requests sent with the alias to be mapped back to the original distinct id. The recommended usage pattern is to call createAlias: and then identify: (with their new user ID) when they log in the next time. This will keep your signup funnels working correctly. This makes the current id and ‘Alias’ interchangeable distinct ids. Mixpanel. mixpanelInstance.createAlias(Alias, mixpanelInstance.distinctId)

    Precondition

    You must call identify if you haven’t already (e.g. when your app launches)

    Declaration

    Swift

    open func createAlias(_ alias: String, distinctId: String, usePeople: Bool = true)

    Parameters

    alias

    the new distinct id that should represent the original

    distinctId

    the old distinct id that alias will be mapped to

    usePeople

    boolean that controls whether or not to set the people distinctId to the event distinctId. This should only be set to false if you wish to prevent people profile updates for that user.

  • Clears all stored properties including the distinct Id. Useful if your app’s user logs out.

    Declaration

    Swift

    open func reset()
  • Writes current project info including the distinct Id, super properties, and pending event and People record queues to disk.

    This state will be recovered when the app is launched again if the Mixpanel library is initialized with the same project token. The library listens for app state changes and handles persisting data as needed.

    Important

    You do not need to call this method.**

    Declaration

    Swift

    open func archive()
  • Writes current project info including the distinct Id, super properties, and pending event and People record queues to disk.

    This state will be recovered when the app is launched again if the Mixpanel library is initialized with the same project token. The library listens for app state changes and handles persisting data as needed.

    Important

    You do not need to call this method.**
  • Uploads queued data to the Mixpanel server.

    By default, queued data is flushed to the Mixpanel servers every minute (the default for flushInterval), and on background (since flushOnBackground is on by default). You only need to call this method manually if you want to force a flush at a particular moment.

    Declaration

    Swift

    open func flush(completion: (() -> Void)? = nil)

    Parameters

    completion

    an optional completion handler for when the flush has completed.

  • Tracks an event with properties. Properties are optional and can be added only if needed.

    Properties will allow you to segment your events in your Mixpanel reports. Property keys must be String objects and the supported value types need to conform to MixpanelType. MixpanelType can be either String, Int, UInt, Double, Float, Bool, [MixpanelType], [String: MixpanelType], Date, URL, or NSNull. If the event is being timed, the timer will stop and be added as a property.

    Declaration

    Swift

    open func track(event: String?, properties: Properties? = nil)

    Parameters

    event

    event name

    properties

    properties dictionary

  • Tracks an event with properties and to specific groups. Properties and groups are optional and can be added only if needed.

    Properties will allow you to segment your events in your Mixpanel reports. Property and group keys must be String objects and the supported value types need to conform to MixpanelType. MixpanelType can be either String, Int, UInt, Double, Float, Bool, [MixpanelType], [String: MixpanelType], Date, URL, or NSNull. If the event is being timed, the timer will stop and be added as a property.

    Declaration

    Swift

    open func trackWithGroups(event: String?, properties: Properties? = nil, groups: Properties?)

    Parameters

    event

    event name

    properties

    properties dictionary

    groups

    groups dictionary

  • Undocumented

    Declaration

    Swift

    open func getGroup(groupKey: String, groupID: MixpanelType) -> Group
  • Starts a timer that will be stopped and added as a property when a corresponding event is tracked.

    This method is intended to be used in advance of events that have a duration. For example, if a developer were to track an Image Upload event she might want to also know how long the upload took. Calling this method before the upload code would implicitly cause the track call to record its duration.

    Precondition

    // begin timing the image upload: mixpanelInstance.time(event:Image Upload) // upload the image: self.uploadImageWithSuccessHandler() { _ in // track the event mixpanelInstance.track(Image Upload) }

    Declaration

    Swift

    open func time(event: String)

    Parameters

    event

    the event name to be timed

  • Retrieves the time elapsed for the named event since time(event:) was called.

    Declaration

    Swift

    open func eventElapsedTime(event: String) -> Double

    Parameters

    event

    the name of the event to be tracked that was passed to time(event:)

  • Clears all current event timers.

    Declaration

    Swift

    open func clearTimedEvents()
  • Returns the currently set super properties.

    Declaration

    Swift

    open func currentSuperProperties() -> [String: Any]

    Return Value

    the current super properties

  • Clears all currently set super properties.

    Declaration

    Swift

    open func clearSuperProperties()
  • Registers super properties, overwriting ones that have already been set.

    Super properties, once registered, are automatically sent as properties for all event tracking calls. They save you having to maintain and add a common set of properties to your events. Property keys must be String objects and the supported value types need to conform to MixpanelType. MixpanelType can be either String, Int, UInt, Double, Float, Bool, [MixpanelType], [String: MixpanelType], Date, URL, or NSNull.

    Declaration

    Swift

    open func registerSuperProperties(_ properties: Properties)

    Parameters

    properties

    properties dictionary

  • Registers super properties without overwriting ones that have already been set, unless the existing value is equal to defaultValue. defaultValue is optional.

    Property keys must be String objects and the supported value types need to conform to MixpanelType. MixpanelType can be either String, Int, UInt, Double, Float, Bool, [MixpanelType], [String: MixpanelType], Date, URL, or NSNull.

    Declaration

    Swift

    open func registerSuperPropertiesOnce(_ properties: Properties,
                                            defaultValue: MixpanelType? = nil)

    Parameters

    properties

    properties dictionary

    defaultValue

    Optional. overwrite existing properties that have this value

  • Removes a previously registered super property.

    As an alternative to clearing all properties, unregistering specific super properties prevents them from being recorded on future events. This operation does not affect the value of other super properties. Any property name that is not registered is ignored. Note that after removing a super property, events will show the attribute as having the value undefined in Mixpanel until a new value is registered.

    Declaration

    Swift

    open func unregisterSuperProperty(_ propertyName: String)

    Parameters

    propertyName

    array of property name strings to remove

  • Convenience method to set a single group the user belongs to.

    Declaration

    Swift

    open func setGroup(groupKey: String, groupID: MixpanelType)

    Parameters

    groupKey

    The property name associated with this group type (must already have been set up).

    groupID

    The group the user belongs to.

  • Set the groups this user belongs to.

    Declaration

    Swift

    open func setGroup(groupKey: String, groupIDs: [MixpanelType])

    Parameters

    groupKey

    The property name associated with this group type (must already have been set up).

    groupIDs

    The list of groups the user belongs to.

  • Add a group to this user’s membership for a particular group key

    Declaration

    Swift

    open func addGroup(groupKey: String, groupID: MixpanelType)

    Parameters

    groupKey

    The property name associated with this group type (must already have been set up).

    groupID

    The new group the user belongs to.

  • Remove a group from this user’s membership for a particular group key

    Declaration

    Swift

    open func removeGroup(groupKey: String, groupID: MixpanelType)

    Parameters

    groupKey

    The property name associated with this group type (must already have been set up).

    groupID

    The group value to remove.

  • Opt out tracking.

    This method is used to opt out tracking. This causes all events and people request no longer to be sent back to the Mixpanel server.

    Declaration

    Swift

    open func optOutTracking()
  • Opt in tracking.

    Use this method to opt in an already opted out user from tracking. People updates and track calls will be sent to Mixpanel after using this method.

    This method will internally track an opt in event to your project.

    Declaration

    Swift

    open func optInTracking(distinctId: String? = nil, properties: Properties? = nil)

    Parameters

    distintId

    an optional string to use as the distinct ID for events

    properties

    an optional properties dictionary that could be passed to add properties to the opt-in event that is sent to Mixpanel

  • Returns if the current user has opted out tracking.

    Declaration

    Swift

    open func hasOptedOutTracking() -> Bool

    Return Value

    the current super opted out tracking status

  • Join any experiments (A/B tests) that are available for the current user.

    Mixpanel will check for A/B tests automatically when your app enters the foreground. Call this method if you would like to to check for, and join, any experiments are newly available for the current user.

    Declaration

    Swift

    open func joinExperiments(callback: (() -> Void)? = nil)

    Parameters

    callback

    Optional callback for after the experiments have been loaded and applied

  • Shows a notification if one is available.

    Note

    You do not need to call this method on the main thread.

    Declaration

    Swift

    open func showNotification()
  • Shows a notification with the given type if one is available.

    Note

    You do not need to call this method on the main thread.

    Declaration

    Swift

    open func showNotification(type: String)

    Parameters

    type

    The type of notification to show, either mini or takeover

  • Shows a notification with the given ID

    Note

    You do not need to call this method on the main thread.

    Declaration

    Swift

    open func showNotification(ID: Int)

    Parameters

    ID

    The notification ID you want to present

  • Returns the payload of a notification if available

    Note

    You do not need to call this method on the main thread.

    Declaration

    Swift

    open func fetchNotificationPayload(completion: @escaping ([String: AnyObject]?) -> Void)