MixpanelInstance
public class MixpanelInstance: CustomDebugStringConvertible, FlushDelegate
The class that represents the Mixpanel Instance
-
The a MixpanelDelegate object that gives control over Mixpanel network activity.
Declaration
Swift
public var delegate: MixpanelDelegate? -
distinctId string that uniquely identifies the current user.
Declaration
Swift
public var distinctId = "" -
Accessor to the Mixpanel People API object.
Declaration
Swift
public var people: People! -
Controls whether to show spinning network activity indicator when flushing data to the Mixpanel servers. Defaults to true.
Declaration
Swift
public var showNetworkActivityIndicator = true -
Flush timer’s interval. Setting a flush interval of 0 will turn off the flush timer.
Declaration
Swift
public var flushInterval: Double -
Control whether the library should flush data to Mixpanel when the app enters the background. Defaults to true.
Declaration
Swift
public 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
public 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
public var serverURL: String -
The base URL used for Mixpanel API requests. Useful if you need to proxy Mixpanel requests. Defaults to https://api.mixpanel.com.
Declaration
Swift
public 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
public var loggingEnabled: Bool = false
-
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
public 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
public 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
-
Clears all stored properties including the distinct Id. Useful if your app’s user logs out.
Declaration
Swift
public 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
public func archive()
-
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
public func flush(completion: (() -> Void)? = nil)Parameters
completionan 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 are: String, Int, UInt, Double, Float, [AnyObject], [String: AnyObject], Date, URL, and NSNull. If the event is being timed, the timer will stop and be added as a property.
Declaration
Swift
public func track(event: String?, properties: Properties? = nil)Parameters
eventevent name
propertiesproperties dictionary
-
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
public func trackPushNotification(_ userInfo: [NSObject: AnyObject], event: String = "$campaign_received")Parameters
userInforemote notification payload dictionary
eventoptional, and usually shouldn’t be used, unless the results is needed to be tracked elsewhere.
-
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
public func time(event: String)Parameters
eventthe event name to be timed
-
Clears all current event timers.
Declaration
Swift
public func clearTimedEvents() -
Returns the currently set super properties.
Declaration
Swift
public func currentSuperProperties() -> PropertiesReturn Value
the current super properties
-
Clears all currently set super properties.
Declaration
Swift
public 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 are: String, Int, UInt, Double, Float, [AnyObject], [String: AnyObject], Date, URL, and NSNull.
Declaration
Swift
public func registerSuperProperties(_ properties: Properties)Parameters
propertiesproperties 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 are: String, Int, UInt, Double, Float, [AnyObject], [String: AnyObject], Date, URL, and NSNull.
Declaration
Swift
public func registerSuperPropertiesOnce(_ properties: Properties, defaultValue: AnyObject? = nil)Parameters
propertiesproperties dictionary
defaultValueOptional. 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
undefinedin Mixpanel until a new value is registered.Declaration
Swift
public func unregisterSuperProperty(_ propertyName: String)Parameters
propertyNamearray of property name strings to remove
View on GitHub
MixpanelInstance Class Reference