Instance Methods
The following instance methods are available globally.
-
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() -
Sets the distinct ID of the current user.
Mixpanel uses 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 UUIDFor tracking events, you do not need to call
identify:if you want to use the default. However, Mixpanel People always requires an explicit call toidentify:. If calls are made toset:,incrementor otherPeoplemethods prior to callingidentify:, then they are queued up and flushed onceidentify: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)Parameters
distinctIdstring that uniquely identifies the current 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 both createAlias: and identify: when the user signs up, and only identify: (with their new user ID) when they log in. 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)Parameters
aliasthe new distinct id that should represent the original
distinctIdthe old distinct id that alias will be mapped to
-
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
IDThe notification ID you want to present
-
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() -
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 thetrackcall 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
eventthe event name to be timed
-
Clears all stored properties including the distinct Id. Useful if your app’s user logs out.
Declaration
Swift
open func reset() -
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 (sinceflushOnBackgroundis 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
completionan optional completion handler for when the flush has completed.
-
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) -
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
undefinedin Mixpanel until a new value is registered.Declaration
Swift
open func unregisterSuperProperty(_ propertyName: String)Parameters
propertyNamearray of property name strings to remove
-
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
typeThe type of notification to show, either “mini” or “takeover”
-
Returns the currently set super properties.
Declaration
Swift
open func currentSuperProperties() -> [String: Any]Return Value
the current super properties
-
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,Parameters
propertiesproperties dictionary
defaultValueOptional. overwrite existing properties that have this value
-
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
callbackOptional callback for after the experiments have been loaded and applied
-
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
propertiesproperties dictionary
-
Clears all current event timers.
Declaration
Swift
open func clearTimedEvents() -
Track a push notification using its payload sent from Mixpanel.
To simplify user interaction tracking, Mixpanel automatically sends IDs for the relevant notification of each push. This method parses the standard payload and queues a track call using this information.
Declaration
Swift
open func trackPushNotification(_ userInfo: [AnyHashable: Any],Parameters
userInforemote notification payload dictionary
eventoptional, and usually shouldn’t be used, unless the results is needed to be tracked elsewhere.
-
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
eventevent name
propertiesproperties dictionary
View on GitHub
Instance Methods Reference