Send events to Mixpanel using RudderStack cloud mode.
8 minute read
After you have successfully instrumented Mixpanel as a destination in RudderStack, follow this guide to correctly send your events to Mixpanel in cloud mode.
Find the open source transformer code for this destination in the GitHub repository.
Identify
You can use the identify call to create or update a user in Mixpanel.
Mixpanel needs an identifier to uniquely identify a user. If you pass userId and anonymousId along with the Mixpanel API Secret (in the dashboard settings), then RudderStack first makes an identify call to Mixpanel using the userId and the traits. RudderStack then passes the userId and anonymousId via Mixpanel’s Merge Identities feature, so that the two identifiers are glued to a single user profile.
Note the following when sending events to Mixpanel in cloud mode:
You can only create a new user in Mixpanel using identify events if you have selected the Simplified ID Merge dashboard setting. To perform identity merging, you need to use the track or page/screen calls.
When sending events to Mixpanel with Simplified ID Merge, RudderStack recommends passing deviceId generated by the Mixpanel SDK as anonymousId in the RudderStack server-side calls to merge two profiles together successfully. For more information, see Mixpanel User Profiles documentation.
You can prevent the $last_seen attribute getting updated with incorrect times by setting active to false in the context object, as shown in the following snippet:
Setting active to false sets Mixpanel’s $ignore_time attribute to true. This way, you can bypass the “Last Seen” date property.
Property mappings
When sending events in cloud mode, RudderStack maps the following properties to the Mixpanel properties before sending them over Mixpanel’s HTTP API.
RudderStack property
Mixpanel property
traits.createdAt
$created
traits.email
$email
traits.firstName
$firstName
traits.lastName
$lastName
traits.name
$name
traits.username
$username
traits.phone
$phone
traits.avatar
$avatar
context.ip request_ip
ip or $ip
context.campaign.name
campaign_id
context.page.url
$current_url
context.os.name
$os
context.page.referrer
$referrer
context.network.carrier
$carrier
address.city
$city
address.country
$country_code
address.region
$region
context.location.latitude
$latitude
context.location.longitude
$longitude
context.page.manufacturer
$manufacturer
context.device.model
$model
context.screen.width
$screen_width
context.screen.height
$screen_height
context.network.wifi
$wifi
context.location.geoSource
$geoSource
context.traits.unsubscribed
$unsubscribed
traits.unsubscribed
$unsubscribed
properties.unsubscribed
$unsubscribed
context.location.timezone
$timezone
Properties to set only once
RudderStack lets you set the identify traits as Mixpanel properties whose values you do not want to change at the user profile level, that is, Mixpanel will not overwrite the existing property values. See Mixpanel documentation for more information on this feature.
To use this feature, add the identify traits in the Properties to set only once setting.
RudderStack expects the traits specified in the above field to be present in the message.traits or message.context.traits (message.traits has higher precedence) object within the identify event.
For example, if your identify event contains the following and you specify address.city in the Properties to set only once field:
RudderStack internally uses the deletion API specified in the User Deletion dashboard setting. For more information on these deletion APIs, see Connection settings.
To see the deletion requests created by RudderStack using the Delete Profile and Associated Events option, log in to your Mixpanel dashboard and navigate to Organization Settings > Data & Privacy.
Deletion requests created using the Delete Profile API are not shown in this dashboard.
Track
To track user events, use the track method with the event name and the associated properties.
When you select Simplified ID Merge in the Identity Merge dashboard setting, RudderStack sets the event’s userId and anonymousId using Mixpanel’s Simplified ID Merge API so that the two identifiers are glued to a single user profile.
Mixpanel lets you track revenue events. If you send revenue as a property in your track event, RudderStack tracks it as a revenue event.
Revenue tracking is done with a distinct_id (userId that you provide in your identify call; if userId is not present then it will be associated with an anonymousId.)
If Use Mixpanel People setting is toggled on in your RudderStack dashboard and you include revenue as an event property, RudderStack will track a charge for the current user.
Page
RudderStack passes all page properties that you provide via the page call to Mixpanel, along with the other default properties. It sets the event name as Page for a page call and Screen for a screen call.
When you select Simplified ID Merge in the Identity Merge dashboard setting, RudderStack sets the event’s userId and anonymousId using Mixpanel’s Simplified ID Merge API so that the two identifiers are glued to a single user profile.
A sample page call is shown below:
rudderanalytics.page();
Screen
The screen method lets you record whenever a user sees their mobile screen along with any optional properties about the viewed screen.
The alias call lets you associate multiple identities of a known user.
The alias call is deprecated with the Simplified ID Merge dashboard setting.
A sample alias call is as shown:
analytics.alias('userId',`previousId`);
Group
The group call lets you link an identified user with a group such as a company, organization, or an account, and record any traits associated with that group, for example, company name, number of employees, etc. For more information on how the group call works in Mixpanel, see Mixpanel’s Group Analytics documentation.
RudderStack lets you record the custom traits associated with a user group and send this information to Mixpanel.
You can create group keys in the Mixpanel project settings, which act as the group identifiers in Mixpanel. To successfully send a group call to Mixpanel, you must specify at least one group key in the Group Key RudderStack dashboard setting:
Note the following:
If you map the groupId as a group key, RudderStack looks up its value in the following priority order:
In message.groupId
In message.traits.groupId
If you map any other field as a group key, RudderStack looks up its value in message.traits.groupKey.
You can specify multiple values for a group key and send them in an array in the group event payload.
Send historic events
Mixpanel supports importing historical event data. However, note that the event timestamp should be within the last 5 years. Mixpanel rejects any data older than this duration. To send historic events, provide the timestamp in the timestamp field of the message. RudderStack will then send the event with the same timestamp to Mixpanel.
Mixpanel special traits
The following table lists all properties that RudderStack sends to Mixpanel as special traits:
RudderStack Properties
Mixpanel Properties
created
$created
email
$email
firstName
$first_name
lastName
$last_name
lastSeen
$last_seen
name
$name
username
$username
phone
$phone
city/address.city
$city
region/address.state
$region
country/address.country
$country_code
Send UTM parameters to Mixpanel
This section is applicable for track, page, and screen events.
RudderStack maps the following keys (derived from the event’s context.campaign object) to the Mixpanel standard UTM parameters:
RudderStack property
Mixpanel UTM parameter
name
utm_campaign
source
utm_source
medium
utm_medium
content
utm_content
term
utm_term
Any contextual fields apart from the ones mentioned above are sent as utm_{key} to Mixpanel. An example is shown below:
This site uses cookies to improve your experience while you navigate through the website. Out of
these
cookies, the cookies that are categorized as necessary are stored on your browser as they are as
essential
for the working of basic functionalities of the website. We also use third-party cookies that
help
us
analyze and understand how you use this website. These cookies will be stored in your browser
only
with
your
consent. You also have the option to opt-out of these cookies. But opting out of some of these
cookies
may
have an effect on your browsing experience.
Necessary
Always Enabled
Necessary cookies are absolutely essential for the website to function properly. This
category only includes cookies that ensures basic functionalities and security
features of the website. These cookies do not store any personal information.
This site uses cookies to improve your experience. If you want to
learn more about cookies and why we use them, visit our cookie
policy. We'll assume you're ok with this, but you can opt-out if you wish Cookie Settings.