Mixpanel Cloud Mode Integration

Send events to Mixpanel using RudderStack cloud mode.

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.

warning

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.

A sample identify call is as shown:

rudderanalytics.identify("12345", {
  firstname: "Alex",
  city: "New Orleans",
  country: "USA",
  phone: "8005550100",
  email: "alex@example.com"
})

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:

rudderanalytics.identify("12345", {
  firstname: "Alex",
  city: "New Orleans",
  country: "USA"
}, {
  context: {
    active: false
  }
})
info
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 identify fields to the Mixpanel fields before sending them over Mixpanel’s HTTP API.

RudderStack propertyMixpanel property
traits.avatar
context.traits.avatar
$avatar
context.network.carrier$carrier
traits.city
traits.address.city
context.traits.city
context.traits.address.city
context.location.city
$city
traits.country
traits.address.country
context.traits.country
context.traits.address.country
context.location.country
$country_code
traits.createdAtOnly$created
traits.email$email
traits.firstName$first_name
context.location.geoSource$geo_source
context.page.initial_referrer
context.page.initialReferrer
$initial_referrer
context.page.initial_referring_domain
context.page.initialReferringDomain
$initial_referring_domain
traits.lastName$last_name
context.location.latitude$latitude
context.location.longitude$longitude
context.device.manufacturer$manufacturer
context.device.model$model
traits.name$name
traits.phone$phone
context.screen.height$screen_height
context.screen.width$screen_width
traits.state
traits.address.state
context.traits.state
context.traits.address.state
context.location.region
$region
context.location.timezone$timezone
context.traits.unsubscribed
traits.unsubscribed
properties.unsubscribed
$unsubscribed
traits.username
traits.userName
context.traits.username
context.traits.userName
$username
context.network.wifi$wifi

In addition to the above properties, RudderStack also maps the below properties to specific Mixpanel fields depending on the platform:

Android
RudderStack propertyMixpanel property
context.os.name$os
context.device.model$android_model
context.os.version$android_os_version
context.device.manufacturer$android_manufacturer
context.app.version$android_app_version
$android_app_version_code
properties.androidLibVersion$android_lib_version
properties.androidBrand
context.device.manufacturer
$android_brand
iOS
RudderStack propertyMixpanel property
context.os.name$os
context.device.model$ios_device_model
context.os.version$ios_version
context.app.build$ios_app_version
context.app.version$ios_app_version
properties.iosLibVersion$ios_lib_version

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:

"traits": {
  "address": {
    "city": "London"
  }
}

...

"context": {
  "traits": {
    "address": {
      "city": "Berlin"
    }
  }
}

Then, RudderStack maps city as London as the traits object gets precedence over context.traits.

Reserved Mixpanel properties

Mixpanel has some reserved properties:

  • $first_name
  • $last_name
  • $name
  • $username
  • $created
  • $email
  • $phone
  • $avatar
  • $city
  • $country_code
  • $region
  • $unsubscribed
warning
You should not create custom properties that begin with a $ sign.

Deleting a user

You can delete a user in Mixpanel using the Suppression with Delete regulation of RudderStack’s User Suppression API.

info
To delete a user, you must specify their userId in the event. Additionally, you can specify a custom identifier (optional) in the event.

A sample regulation request body for deleting a user in Mixpanel is shown below:

{
  "regulationType": "suppress_with_delete",
  "destinationIds": [
    "2FIKkByqn37FhzczP23eZmURciA"
  ],
  "users": [{
    "userId": "1hKOmRA4GRlm",
    "<customKey>": "<customValue>"
  }]
}

RudderStack internally uses the deletion API specified in the User Deletion dashboard setting. For more information on these deletion APIs, see Connection settings.

Mixpanel user deletion API

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.

warning
Deletion requests created using the Delete Profile API are not shown in this dashboard.
Mixpanel user deletion requests

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.

A sample track call is as shown:

rudderanalytics.track("track event", {
    test_prop1: 50,
    test_prop2: "prop_value"
});

Track revenue

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.)

A sample revenue track call is as shown:

rudderanalytics.track("Purchase", {
  revenue: 100,
  currency: "USD"
});

Track charge

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.

Property mappings

Click here to view the track event mappings for specific Mixpanel fields:
RudderStack propertyMixpanel property
context.ip
request_ip
ip or $ip
context.campaign.namecampaign_id or $campaign_id
userId$user_id
context.page.url$current_url
context.os.name$os
context.page.referrer$referrer
context.screen.height$screen_height
context.screen.width$scren_width
context.screen.density$screen_dpi
context.campaign.nameutm_campaign
context.campaign.sourceutm_source
context.campaign.mediumutm_medium
context.campaign.termutm_term
context.campaign.contentutm_content
context.campaign.testutm_test
context.network.carrier$carrier
context.os.version$os_version
context.device.name$device
context.device.manufacturer$manufacturer
context.device.model$model
mp_device_model
context.network.wifi$wifi
context.network.bluetooth$bluetooth_enabled
properties.bluetoothVersion$bluetooth_version
context.library.namemp_lib
context.page.initialReferrer$initial_referrer
context.page.initialReferringDomain$initial_referring_domain
properties.mpProcessingTimeMsmp_processing_time_ms
context.app.build
properties.appBuildNumber
$app_build_number
context.app.version
properties.appBuildVersionString
$app_version_string
properties.brand
device.manufacturer
$brand
properties.radio$radio
properties.libVersion$lib_version
properties.searchEngine$search_engine
properties.mpKeyword$mp_keyword
properties.hasNfc$has_nfc
properties.hasTelephone$has_telephone
properties.googlePlayServices$google_play_services
messageId$insert_id
sessionId$session_id

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();

Property mappings

Click here to view the page event mappings for specific Mixpanel fields:
RudderStack propertyMixpanel property
context.ip
request_ip
ip or $ip
context.campaign.namecampaign_id or $campaign_id
userId$user_id
context.page.url$current_url
context.os.name$os
context.page.referrer$referrer
context.screen.height$screen_height
context.screen.width$scren_width
context.screen.density$screen_dpi
context.campaign.nameutm_campaign
context.campaign.sourceutm_source
context.campaign.mediumutm_medium
context.campaign.termutm_term
context.campaign.contentutm_content
context.campaign.testutm_test
context.network.carrier$carrier
context.os.version$os_version
context.device.name$device
context.device.manufacturer$manufacturer
context.device.model$model
mp_device_model
context.network.wifi$wifi
context.network.bluetooth$bluetooth_enabled
properties.bluetoothVersion$bluetooth_version
context.library.namemp_lib
context.page.initialReferrer$initial_referrer
context.page.initialReferringDomain$initial_referring_domain
properties.mpProcessingTimeMsmp_processing_time_ms
context.app.build
properties.appBuildNumber
$app_build_number
context.app.version
properties.appBuildVersionString
$app_version_string
properties.brand
device.manufacturer
$brand
properties.radio$radio
properties.libVersion$lib_version
properties.searchEngine$search_engine
properties.mpKeyword$mp_keyword
properties.hasNfc$has_nfc
properties.hasTelephone$has_telephone
properties.googlePlayServices$google_play_services
messageId$insert_id
sessionId$session_id

Screen

The screen method lets you record whenever a user sees their mobile screen along with any optional properties about the viewed screen.

A sample screen call is shown below:

[[RSClient sharedInstance] screen:@"Sample Screen Name" properties:@{@"prop_key" : @"prop_value"}];

Alias

The alias call lets you associate multiple identities of a known user.

warning
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.

A sample group call is shown below:

rudderanalytics.group(
  "sample_group_id", {
    name: "Tech group",
    industry: "Technology",
    employees: 100,
  }
);

Group key

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:

Mixpanel group key settings
warning

Note the following:

  • If you map the groupId as a group key, RudderStack looks up its value in the following priority order:
    1. In message.groupId
    2. 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 PropertiesMixpanel 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

info
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 propertyMixpanel UTM parameter
nameutm_campaign
sourceutm_source
mediumutm_medium
contentutm_content
termutm_term

Any contextual fields apart from the ones mentioned above are sent as utm_{key} to Mixpanel. An example is shown below:

In the above example, RudderStack sends utm_keyword as a custom UTM parameter to Mixpanel.

Increment properties in Mixpanel People

To increment properties in Mixpanel People, you can add them in the Properties to Increment in People dashboard setting.

RudderStack calls Mixpanel’s increment when you attach a number to the specified property. For example, 'items purchased': 5.

FAQ

Can I pass null and empty values for the properties?

Yes, RudderStack supports passing empty or null values for the properties sent to Mixpanel.

Why am I getting the ‘Request Header Fields Too Large’ error?

Mixpanel imposes certain limitations on its API requests such as:

  • Any GET request URL above 19K characters (around 19 KB+) is blocked.
  • The header size more than 15KB is not allowed.
  • The body of the request more than 20MB is not allowed.
  • Each event can have up to 255 event properties.

If your requests are larger than the above-mentioned limits, you will get a ‘Request Header Fields Too Large’ error.

See Mixpanel’s Community FAQ for more information.


Questions? Contact us by email or on Slack