Constructor
new Mixpanel()
- Source:
Classes
- Mixpanel
Methods
(async, static) init(token, trackAutomaticEvents, Optional)
Parameters:
Name |
Type |
Description |
token |
string
|
your project token. |
trackAutomaticEvents |
boolean
|
Whether or not to automatically track common mobile events |
Optional |
boolean
|
Whether or not Mixpanel can start tracking by default. See optOutTracking() |
- Deprecated:
- Source:
addGroup(groupKey, groupID)
Add a group to this user's membership for a particular group key
Parameters:
Name |
Type |
Description |
groupKey |
string
|
The property name associated with this group type (must already have been set up). |
groupID |
object
|
The new group the user belongs to. |
- Source:
alias(alias, distinctId)
Parameters:
Name |
Type |
Description |
alias |
string
|
A unique identifier that you want to use as an identifier for this user. |
distinctId |
string
|
the current distinct_id that alias will be mapped to. |
- Deprecated:
- Source:
clearSuperProperties()
Erase all currently registered superProperties.
Future tracking calls to Mixpanel will not contain the specific
superProperties registered before the clearSuperProperties method was called.
To remove a single superProperty, use unregisterSuperProperty()
- Source:
deleteGroup(groupKey, groupID)
Permanently deletes this group's record from Group Analytics.
Parameters:
Name |
Type |
Description |
groupKey |
string
|
String identifying the type of group (must be already in use as a group key) |
groupID |
object
|
Object identifying the specific group
Calling deleteGroup deletes an entire record completely. Any future calls
to Group Analytics using the same group value will create and store new values. |
- Source:
eventElapsedTime(eventName) → {Promise.<number>}
Retrieves the time elapsed for the named event since timeEvent() was called.
Parameters:
Name |
Type |
Description |
eventName |
string
|
the name of the event to be tracked that was previously called with timeEvent() |
- Source:
Returns:
Time elapsed since timeEvent(String) was called for the given eventName.
-
Type
-
Promise.<number>
flush()
Push all queued Mixpanel events and People Analytics changes to Mixpanel servers.
Events and People messages are pushed gradually throughout
the lifetime of your application. This means that to ensure that all messages
are sent to Mixpanel when your application is shut down, you will
need to call flush() to let the Mixpanel library know it should
send all remaining messages to the server.
- Source:
getDeviceId() → {Promise.<string>}
Returns the current device id of the device.
This id automatically generated by the library and regenerated when logout or reset is called.
example of usage:
const deviceId = await mixpanel.getDeviceId();
- Source:
Returns:
A Promise to the device id
-
Type
-
Promise.<string>
getDistinctId() → {Promise.<string>}
Returns the current distinct id of the user.
This is either the id automatically generated by the library or the id that has been passed by a call to identify().
example of usage:
const distinctId = await mixpanel.getDistinctId();
- Source:
Returns:
A Promise to the distinct id associated with Mixpanel event and People Analytics
-
Type
-
Promise.<string>
getGroup(groupKey, groupID)
Returns a MixpanelGroup object that can be used to set and increment
Group Analytics properties.
Parameters:
Name |
Type |
Description |
groupKey |
string
|
String identifying the type of group (must be already in use as a group key) |
groupID |
object
|
Object identifying the specific group |
- Source:
Returns:
an instance of MixpanelGroup that you can use to update
records in Mixpanel Group Analytics
getPeople() → {People}
Returns a Mixpanel People object that can be used to set and increment
People Analytics properties.
- Source:
Returns:
an instance of People that you can use to update
records in Mixpanel People Analytics
-
Type
-
People
getSuperProperties() → {Promise.<object>}
Returns a json object of the user's current super properties
SuperProperties are a collection of properties that will be sent with every event to Mixpanel,
and persist beyond the lifetime of your application.
- Source:
Returns:
Super properties for this Mixpanel instance.
-
Type
-
Promise.<object>
hasOptedOutTracking() → {Promise.<boolean>}
Will return true if the user has opted out from tracking.
- Source:
Returns:
true if user has opted out from tracking. Defaults to false.
-
Type
-
Promise.<boolean>
identify(distinctId) → {Promise}
Associate all future calls to track() with the user identified by
the given distinct id.
Calls to track() made before corresponding calls to identify
will use an anonymous locally generated distinct id, which means it is best to call identify
early to ensure that your Mixpanel funnels and retention analytics can continue to track the
user throughout their lifetime. We recommend calling identify when the user authenticates.
Once identify is called, the local distinct id persists across restarts of
your application.
Parameters:
Name |
Type |
Description |
distinctId |
string
|
a string uniquely identifying this user. Events sent to
Mixpanel using the same disinct_id will be considered associated with the
same visitor/customer for retention and funnel reporting, so be sure that the given
value is globally unique for each individual user you intend to track. |
- Source:
Returns:
A promise that resolves when the identify is successful.
It does not return any value.
-
Type
-
Promise
(async) init(optOutTrackingDefault, superProperties, serverURL)
Initializes Mixpanel
Parameters:
Name |
Type |
Default |
Description |
optOutTrackingDefault |
boolean
|
|
Optional Whether or not Mixpanel can start tracking by default. See optOutTracking() |
superProperties |
object
|
|
Optional A Map containing the key value pairs of the super properties to register |
serverURL |
string
|
https://api.mixpanel.com
|
Optional Set the base URL used for Mixpanel API requests. See setServerURL() |
- Source:
optInTracking()
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.
- Source:
optOutTracking()
Use this method to opt-out a user from tracking. Events and people updates that haven't been
flushed yet will be deleted. Use flush() before calling this method if you want
to send all the queues to Mixpanel before.
This method will also remove any user-related information from the device.
- Source:
registerSuperProperties(properties)
Register properties that will be sent with every subsequent call to track().
SuperProperties are a collection of properties that will be sent with every event to Mixpanel,
and persist beyond the lifetime of your application.
Setting a superProperty with registerSuperProperties will store a new superProperty,
possibly overwriting any existing superProperty with the same name (to set a
superProperty only if it is currently unset, use registerSuperPropertiesOnce())
SuperProperties will persist even if your application is taken completely out of memory.
to remove a superProperty, call unregisterSuperProperty() or clearSuperProperties()
Parameters:
Name |
Type |
Description |
properties |
object
|
A Map containing super properties to register |
- Source:
registerSuperPropertiesOnce(properties)
Register super properties for events, only if no other super property with the
same names has already been registered.
Calling registerSuperPropertiesOnce will never overwrite existing properties.
Parameters:
Name |
Type |
Description |
properties |
object
|
A Map containing the super properties to register. |
- Source:
removeGroup(groupKey, groupID)
Remove a group from this user's membership for a particular group key
Parameters:
Name |
Type |
Description |
groupKey |
string
|
The property name associated with this group type (must already have been set up). |
groupID |
object
|
The group value to remove. |
- Source:
reset()
Clear super properties and generates a new random distinctId for this instance.
Useful for clearing data when a user logs out.
- Source:
setFlushBatchSize(flushBatchSize)
Set 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.
Parameters:
Name |
Type |
Description |
flushBatchSize |
integer
|
whether to automatically send the client IP Address.
Defaults to true. |
- Source:
setFlushOnBackground(flushOnBackground)
This allows enabling or disabling whether or not Mixpanel flushes events
when the app enters the background on iOS. This is set to true by default.
Parameters:
Name |
Type |
Description |
flushOnBackground |
boolean
|
whether to enable logging |
- Source:
setGroup(groupKey, groupID)
Set the group this user belongs to.
Parameters:
Name |
Type |
Description |
groupKey |
string
|
The property name associated with this group type (must already have been set up). |
groupID |
object
|
The group the user belongs to. |
- Source:
setLoggingEnabled(loggingEnabled)
This allows enabling or disabling of all Mixpanel logs at run time.
All logging is disabled by default. Usually, this is only required if
you are running into issues with the SDK that you want to debug
Parameters:
Name |
Type |
Description |
loggingEnabled |
boolean
|
whether to enable logging |
- Source:
setServerURL(serverURL)
Set the base URL used for Mixpanel API requests.
Useful if you need to proxy Mixpanel requests. Defaults to https://api.mixpanel.com.
To route data to Mixpanel's EU servers, set to https://api-eu.mixpanel.com
Parameters:
Name |
Type |
Description |
serverURL |
string
|
the base URL used for Mixpanel API requests |
- Source:
setUseIpAddressForGeolocation(useIpAddressForGeolocation)
This controls whether to automatically send the client IP Address as part of event tracking.
With an IP address, geo-location is possible down to neighborhoods within a city,
although the Mixpanel Dashboard will just show you city level location specificity.
Parameters:
Name |
Type |
Description |
useIpAddressForGeolocation |
boolean
|
whether to automatically send the client IP Address.
Defaults to true. |
- Source:
timeEvent(eventName)
Begin timing of an event. Calling timeEvent("Thing") will not send an event, but
when you eventually call track("Thing"), your tracked event will be sent with a "$duration"
property, representing the number of seconds between your calls.
Parameters:
Name |
Type |
Description |
eventName |
string
|
the name of the event to track with timing. |
- Source:
track(eventName, properties)
Track an event.
Every call to track eventually results in a data point sent to Mixpanel. These data points
are what are measured, counted, and broken down to create your Mixpanel reports. Events
have a string name, and an optional set of name/value pairs that describe the properties of
that event.
Parameters:
Name |
Type |
Description |
eventName |
string
|
The name of the event to send |
properties |
object
|
A Map containing the key value pairs of the properties to include in this event.
Pass null if no extra properties exist. |
- Source:
trackWithGroups(eventName, properties, groups)
Track an event with specific groups.
Every call to track eventually results in a data point sent to Mixpanel. These data points
are what are measured, counted, and broken down to create your Mixpanel reports. Events
have a string name, and an optional set of name/value pairs that describe the properties of
that event. Group key/value pairs are upserted into the property map before tracking.
Parameters:
Name |
Type |
Description |
eventName |
string
|
The name of the event to send |
properties |
object
|
A Map containing the key value pairs of the properties to include in this event.
Pass null if no extra properties exist. |
groups |
object
|
A Map containing the group key value pairs for this event. |
- Source:
unregisterSuperProperty(propertyName)
Remove a single superProperty, so that it will not be sent with future calls to track().
If there is a superProperty registered with the given name, it will be permanently
removed from the existing superProperties.
To clear all superProperties, use clearSuperProperties()
Parameters:
Name |
Type |
Description |
propertyName |
string
|
name of the property to unregister |
- Source: