Mixpanel
Mixpanel is an analytics platform that lets you track user actions with your application. It offers features like in-app A/B testing, user survey forms, and custom reports to measure customer retention. It also provides specific tools for targeted business communication and engagement with your customers.
RudderStack supports Mixpanel as a destination to which you can seamlessly send your event data.
Find the open-source transformer code for this destination in our GitHub repo.
Getting Started
Before configuring your source and destination on the RudderStack, verify if the source platform is supported by Mixpanel by referring to the table below:
| Connection Mode | Web | Mobile | Server |
|---|---|---|---|
| Device mode | Supported | - | - |
| Cloud mode | Supported | Supported | Supported |
To know more about the difference between Cloud mode and Device mode in RudderStack, read the RudderStack connection modes guide.
Once you have confirmed that the source supports sending events to Mixpanel, perform the steps below:
- From your RudderStack dashboard, add the source. From the list of destinations, select Mixpanel.
Follow our guide on How to Add a Source and Destination in RudderStack to add a source and destination in RudderStack.
- Give a name to the destination and click on Next. You should then see the following screen:
Configuration Settings
To configure Mixpanel as a destination, you need to provide your Mixpanel API Token in the Connection Settings.
Choose EU in Data Residency settings to send your event data to the Mixpanel EU server.
The following settings are applicable if you are using this destination via the web Device mode:
- Use Mixpanel People: This option sends all your
identifycalls to Mixpanel People. More information on this option can be found below. - Automatically Set all Traits as Super Properties and People properties: More information on this option can be found here.
- Page Tracking Options: For Device mode, RudderStack offers three options for
pagecalls. More information on these options can be found here. - Source Name: If set, RudderStack sends this source name to Mixpanel for every event/
page/screencall. - Cross Subdomain Cookie: If enabled, this option allows the Mixpanel cookie to persist between different pages of your application.
- Persistence Type: This option lets you choose the persistence type for your Mixpanel cookies.
- Secure Cookie: Enabling this option will mark the Mixpanel cookie as secure, i.e it will only transmit over HTTPs.
- Group Key Settings: RudderStack sends the
groupcalls to Mixpanel only if one or more group keys are specified here. For more information, check out the Group section below.
Page
We pass all the page properties that you provide through our page call along with the properties that we auto collect through our SDK to Mixpanel. The event name would be Page for page call and Screen for a screen call. A sample page call is as shown:
rudderanalytics.page();Page Web Device Mode
Rudderstack will send 1 event to Mixpanel per page call.
For Device mode, RudderStack offers the following three options for page calls:
- With Track All Pages with a Consolidated Event Name option enabled by default, RudderStack sends all the
pageandscreencalls with the nameLoaded a Pagewith the corresponding properties of the call. This allows you to leverage Mixpanel's reporting for page/screen analytics in the best possible way. Note that this option is given the highest precedence, even if the following two options (Track Categorized Pages to Mixpanel and Track Named Pages to Mixpanel) are enabled. - RudderStack tracks the categorized pages to Mixpanel. If you enable the Track Categorized Pages to Mixpanel option, RudderStack sends a
Viewed [category] Pageevent. If the page name is also present in the event, thenViewed [category page_name] Pageevent is sent. - RudderStack tracks the named pages to Mixpanel. If you enable the Track Named Pages to Mixpanel option, RudderStack will send a
Viewed [page_name] Pageevent. Note that this option has the least precedence and comes to effect only if the above two options are disabled in the RudderStack dashboard.
RudderStack expects atleast one of the three options listed above to be enabled for sending the page events to Mixpanel using device mode.
Identify
To identify a user to Mixpanel, you need to call the identify method. Mixpanel needs a unique identifier to identify a user. If you provide userId in your identify call, RudderStack will pass it to Mixpanel as distinct_id . If userId is not present, RudderStack sends an anonymousId and sets the traits that you have provided as the properties corresponding to the distinct_id.
After making this request, RudderStack merges the anonymousId and userId as a distinct_id and the new userId is mapped to alias, so that both of these users are mapped to a single entity in the Mixpanel dashboard.
A sample identify call is as shown:
rudderanalytics.identify("12345", { firstname: "Tintin", city: "Brussels", country: "Belgium", phone: "1234567890", email: "tintin@twentiethcentury.com"})Mixpanel has some reserved properties:
$first_name$last_name$name$username$created$email$phone$avatar
You can create custom properties. However, note that you should not create properties that begin with a $ sign.
Mixpanel People
Rudderstack does not send data to Mixpanel People by default, as it usually requires upgrading the Mixpanel account. You can enable the Use Mixpanel People option in the Rudderstack dashboard if you want to use this feature.
We recommend identifying the user traits without the userId if you wish to add the people properties in Mixpanel before knowing the userId. To do this, refer to the following snippet:
rudderanalytics.identify({ email: 'hello@example.com', name: 'Ian Taylor'})Currently, RudderStack supports this feature only for the native web device mode.
Track
To track user events, use the track method with the event name and the associated properties. A sample track call is as shown:
rudderanalytics.track("track event", { test_prop1: 50, test_prop2: "prop_value"});Tracking Revenue
Mixpanel allows you to track revenue. If you send revenue a property in your track call, 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: 30, currency: "USD"});Track Charge
If Use Mixpanel People is enabled in your RudderStack dashboard and you include revenue as an event property, RudderStack will track a charge for the current user.
Alias
The alias call lets you associate multiple identities of a known user. A sample alias call is as shown:
analytics.alias('userId', `previousId`);Group
The group call allows you to link an identified user with a group, such as a company, organization, or an account. It also lets you record any custom traits associated with that group like the name of the company, the number of employees, etc.
For more information on how the group call works in Mixpanel, check out Mixpanel's Group Analytics documentation.
RudderStack allows you to record the custom traits associated with a user group and send this information to Mixpanel.
A sample group call is as shown:
{ "userId": "user123", "traits": { "name": "Company", "industry": "Industry", "employees": 123 }, "context": { "traits": { "trait1": "new-val" }, "library": { "name": "http" } }, "timestamp": "2020-01-21T00:21:34.208Z"}RudderStack sends the group calls to Mixpanel only if one or more group keys are specified during the destination configuration in RudderStack, as shown:
You should also have created the group key/s of the same name in Mixpanel's project settings. To administer the group keys, navigate to your project settings and click on Add Group Key under the Group Keys section.
Sending Historic Events
Mixpanel supports historical event data import. However, note that the timestamp of the event 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.
Mapping RudderStack Properties to Mixpanel Properties
RudderStack maps the following properties to the Mixpanel properties before sending them over Mixpanel's HTTP API.
RudderStack maps these fields only in the identify requests.
| Mixpanel Property Name | RudderStack Property Name |
|---|---|
$created | traits.createdAt |
$email | traits.email |
$firstName | traits.firstName |
$lastName | traits.lastName |
$name | traits.name |
$username | traits.username |
$phone | traits.phone |
$avator | traits.avator |
ip or $ip | context.ip |
campaign_id | context.campaign.name |
$current_url | context.page.url |
$os | context.os.name |
$referrer | context.page.referrer |
$carrier | context.network.carrier |
Explicitly Setting People Properties and Super Properties
You can set all of your traits as both Super Properties and People Properties (If you have Use Mixpanel People option enabled) by enabling the Automatically set all Traits as Super Properties and People Properties option in the Rudderstack dashboard.
You can choose to filter your reports by both People Properties and Super Properties. This gives you better control over what traits you can set as a Super Property or People Property. To do this, disable the Automatically set all Traits as Super Properties and People Properties option in the dashboard and add the traits that you want to send to Mixpanel as Super Properties or People Properties in the specified fields, as shown below.
RudderStack will send all the Mixpanel's special traits as People Properties. Hence, you only need to add the properties that are not in this list.
This feature is available in the native web Device mode only.
Mixpanel Special Traits
The following table lists all the properties that RudderStack sends to Mixpanel as special traits:
| Mixpanel Properties | RudderStack Properties |
|---|---|
created | $created |
email | $email |
firstName | $first_name |
lastName | $last_name |
lastSeen | $last_seen |
name | $name |
username | $username |
phone | $phone |
Incrementing Events
If you're tracking known users, you dont need to add any extra code to increment event counts for Mixpanel People. Just add the events you want to increment and RudderStack will take care of the rest.
This feature is available in the native web Device mode only.
For each event name added, RudderStack automatically calls Mixpanel and sets a user trait as Last + <event_name>. For example, if you add Logged In to the list of increment events, RudderStack will increment a user trait called Logged In and set a trait called Last Logged In with the current date and time.
Increment works for known users only. So, if your track call is being made on the server-side, you will need to pass a userId. If your track call is being made on the client-side, you will need to identify your user first.
Incrementing Properties
To increment properties, you can specify which properties you want RudderStack to increment using the Properties to Increment in People field. RudderStack will call Mixpanel’s increment when you attach a number to the specified property. For example, 'items purchased': 5.
This feature is available in the native web Device mode only.
Cross Subdomain Cookies
- Cross Subdomain Cookie: This option will allow the Mixpanel cookie to be persisted between different pages of your application.
- Persistence Type: This option lets you choose the persistence type for your Mixpanel cookies.
- Secure Cookie: Enabling this option will mark the Mixpanel cookie as secure, i.e it will only transmit over HTTPs.
Contact Us
If you come across any issues while configuring Mixpanel with RudderStack, feel free to contact us or start a conversation on our Slack channel.