MixpanelInstance
open class MixpanelInstance : CustomDebugStringConvertible, FlushDelegate, AEDelegate
The class that represents the Mixpanel Instance
-
apiToken string that identifies the project to track data to
Declaration
Swift
open var apiToken: String
-
The a MixpanelDelegate object that gives control over Mixpanel network activity.
Declaration
Swift
open weak var delegate: MixpanelDelegate?
-
distinctId string that uniquely identifies the current user.
Declaration
Swift
open var distinctId: String
-
anonymousId string that uniquely identifies the device.
Declaration
Swift
open var anonymousId: String?
-
userId string that identify is called with.
Declaration
Swift
open var userId: String?
-
hadPersistedDistinctId is a boolean value which specifies that the stored distinct_id already exists in persistence
Declaration
Swift
open var hadPersistedDistinctId: Bool?
-
alias string that uniquely identifies the current user.
Declaration
Swift
open var alias: String?
-
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: Bool
-
This allows enabling or disabling collecting common mobile events,
Declaration
Swift
open var trackAutomaticEventsEnabled: Bool
-
Flush timer’s interval. Setting a flush interval of 0 will turn off the flush timer and you need to call the flush() API manually to upload queued data to the Mixpanel server.
Declaration
Swift
open var flushInterval: Double { get set }
-
Control whether the library should flush data to Mixpanel when the app enters the background. Defaults to true.
Declaration
Swift
open var flushOnBackground: Bool { get set }
-
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 { get set }
-
The
flushBatchSize
property determines the number of events sent in a single network request to the Mixpanel server. By configuring this value, you can optimize network usage and manage the frequency of communication between the client and the server. The maximum size is 50; any value over 50 will default to 50.Declaration
Swift
open var flushBatchSize: Int { get set }
-
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: String { get set }
-
The a MixpanelProxyServerDelegate object that gives config control over Proxy Server’s network activity.
Declaration
Swift
open weak var proxyServerDelegate: MixpanelProxyServerDelegate?
-
Declaration
Swift
open var debugDescription: String { get }
-
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 { get set }
-
A unique identifier for this MixpanelInstance
Declaration
Swift
public let name: String
-
Undocumented
Declaration
Swift
open var minimumSessionDuration: UInt64 { get set }
-
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 { get set }
-
Sets the distinct ID of the current user.
Mixpanel uses a randomly generated persistent UUID as the default local distinct ID.
If you want to use a unique persistent UUID, you can define the
MIXPANEL_UNIQUE_DISTINCT_ID
flag in yourActive Compilation Conditions
build settings. It then uses the IFV String (UIDevice.current().identifierForVendor
) as the default local 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 an IFV, we will fall back to generating a random persistent UUID.For tracking events, you do not need to call
identify:
. However, Mixpanel User profiles always requires an explicit call toidentify:
. If calls are made toset:
,increment
or otherPeople
methods 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, usePeople: Bool = true, completion: (() -> Void)? = nil)
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.
completion
an optional completion handler for when the identify has completed.
-
The alias method creates an alias which Mixpanel will use to remap one id to another. Multiple aliases can point to the same identifier.
Please note: With Mixpanel Identity Merge enabled, calling alias is no longer required but can be used to merge two IDs in scenarios where identify() would fail
mixpanelInstance.createAlias("New ID", distinctId: mixpanelInstance.distinctId)
You can add multiple id aliases to the existing id
mixpanelInstance.createAlias("Newer ID", distinctId: mixpanelInstance.distinctId)
Declaration
Swift
public func createAlias(_ alias: String, distinctId: String, usePeople: Bool = true, andIdentify: Bool = true, completion: (() -> Void)? = nil)
Parameters
alias
A unique identifier that you want to use as an identifier for this user.
distinctId
The current user identifier.
usePeople
boolean that controls whether or not to set the people distinctId to the event distinctId.
andIdentify
an optional boolean that controls whether or not to call ‘identify’ with your current user identifier(not alias). Default to true for keeping your signup funnels working correctly in most cases.
completion
an optional completion handler for when the createAlias has completed. 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
public func reset(completion: (() -> Void)? = nil)
Parameters
completion
an optional completion handler for when the reset has completed.
-
Undocumented
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 (sinceflushOnBackground
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
public func flush(performFullFlush: Bool = false, completion: (() -> Void)? = nil)
Parameters
performFullFlush
A optional boolean value indicating whether a full flush should be performed. If
true
, a full flush will be triggered, sending all events to the server. Default tofalse
, a partial flush will be executed for reducing memory footprint.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
public 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
public func trackWithGroups(event: String?, properties: Properties? = nil, groups: Properties?)
Parameters
event
event name
properties
properties dictionary
groups
groups dictionary
-
Undocumented
Declaration
Swift
public 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
public 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
public 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
public func clearTimedEvents()
-
Clears the event timer for the named event.
Declaration
Swift
public func clearTimedEvent(event: String)
Parameters
event
the name of the event to clear the timer for
-
Returns the currently set super properties.
Declaration
Swift
public func currentSuperProperties() -> [String : Any]
Return 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 need to conform to MixpanelType. MixpanelType can be either String, Int, UInt, Double, Float, Bool, [MixpanelType], [String: MixpanelType], Date, URL, or NSNull.
Declaration
Swift
public 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
public 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
public 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
public 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
public 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
public 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
public 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
public 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
public 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
public func hasOptedOutTracking() -> Bool
Return Value
the current super opted out tracking status