Many Mixpanel customers successfully integrate using Segment. This integration collects your data within Segment and then passes that data along to Mixpanel, which means you'll primarily be using Segment's methods in your implementation rather than Mixpanel’s native libraries. Segment wraps Mixpanel’s libraries, so you can still access native Mixpanel functions if Segment methods don’t accomplish your goals.
The Segment-Mixpanel integration is handled primarily by Segment, but that being said, it’s a good idea to take a look at documentation on both sides to understand some of Mixpanel’s nuances and how to structure Segment data so that you have maximum flexibility when creating reports in Mixpanel.
What to Track
As with any Mixpanel integration, think carefully early on about what Events you'd like to track using Segment, and give those Events consistent and clear names.
Mixpanel allows you to send information along with Events, providing additional detail about the Event itself or the person performing that Event. These bits of information are called Properties. Mixpanel has three types of Properties: Event Properties, sent with a single Event; Super Properties, sent with every Event; and User Profile Properties, set on User Profiles. Learn more about Event Properties, Super Properties, and User Properties in Mixpanel.
If you’re using one of Segment’s client-side libraries, user specific details should be collected as Traits, which are the Segment equivalent of Mixpanel’s Super and User Properties combined. By default, each key-value pair in the Trait object will be registered as a Super Property in Mixpanel. And if you’ve enabled Mixpanel People in your Segment settings, these Traits will automatically be set as User properties as well.
Review the resources in Mixpanel's Getting Started Guide to get a sense of how Mixpanel structures its Event data so you can set up your Segment tracking with these concepts in mind.
Managing User Identity
It’s important to send data to Mixpanel with consistent unique identifiers that represent your individual users so that you can track them throughout their lifetime on any device. Note that Mixpanel's client-side libraries assign a unique identifier for users (called the distinct_id) automatically when they first engage with your app.
Debugging this setup can get complex when you are passing Events through a service like Segment first, so before implementation, review Mixpanel’s identity management documentation.
Once you understand how Mixpanel handles user identity, check out Segment’s documentation on using the alias function for a complete view of identity management on Mixpanel with a Segment integration.
During implementation, ensure Event tracking is functioning as expected with Segment by testing activity and monitoring the Events that come into the Live View tab in your Mixpanel project and Segment’s Live Debugger. The Mixpanel Live View report allows you to see Events arrive in your project in real time and examine the exact properties that are sent with them to ensure you implemented correctly.
Segment Integration Guide
For additional information on getting started, visit Segment’s Mixpanel documentation.
I can’t see my Segment data in Mixpanel
This could be due to several reasons:
- Storing data in the EU: A common issue is that the data in Segment is enabled to be sent to an EU endpoint but the Mixpanel data is still being stored outside of the EU. Both endpoints for Segment and Mixpanel need to point to the EU as described here: https://segment.com/docs/connections/destinations/catalog/mixpanel/#enable-european-union-endpoint
If you have an existing Mixpanel project, you might need to have your data migrated to the EU. Please find further information here.
- Cloud implementation vs. device implementation: Segment can be implemented via a cloud-based implementation or as an SDK on the device directly. Device implementation will send the data to Mixpanel directly while the cloud implementation will send it to Segment first. You can confirm your implementation by querying for the Mixpanel library property of the events in your project:
- Cloud Mode will show as Mixpanel Library: Segment: analytics.js
- Device Mode will show as Mixpanel Library: Segment: web
- No user profile data in Mixpanel: Segment doesn’t track Mixpanel People by default; this is a setting you need to enable in your Segment settings. To enable Mixpanel People, change the “Use Mixpanel People” setting in your Segment Settings UI.
I see events counted multiple times in Mixpanel
Mixpanel SDKs assign an insert_id to each tracked event: https://developer.mixpanel.com/docs/http#section-event-deduplication
This allows Mixpanel to ensure no event is tracked more than once and events will be deduplicated based on the insert_id. Segment does not assign an insert_id to events. If the ingestion of an event is not confirmed by Mixpanel’s servers fast enough, Segment will retry to send the event.
This can lead to duplicate events in Mixpanel, they will likely have different insert_ids as Mixpanel assigns each event without an insert_id a unique new one. This behavior can be caused by sending huge batches of data at the same time and can be avoided by reducing the batch size and frequency of event sending from Segment to Mixpanel.
Identify/Alias with Segment
- If users are in device mode, please note that this is like a regular Mixpanel implementation. Mixpanel will generate distinct_ids (it will not use Segment’s anonymous_id as a distinct_id).
- If users are in cloud mode, think of it as a server-side implementation. Mixpanel does not play any part in generating distinct_ids. This is left up to Segment and the user’s implementation.
- The Segment alias method analytics.alias() acts the same as the Mixpanel alias method.
- The Segment identify method analytics.identify() does the same as the Mixpanel identify method plus more. It will update the distinct_id of the cookie (in device mode) and if you send an object as the second argument in the identify call, it will automatically trigger a people.set() as well and it will set those user properties as super properties.
- Please find Segment's Alias docs here and Identify docs here.
Register super properties with Mixpanel
Super properties can only be set when you are running in device mode. The super properties are automatically set with every property you pass into the analytics.identify() method. To have more control over the super properties you set, you can explicitly set super properties in your Segment settings.
Page tracks from Segment to Mixpanel
Page calls are automatically tracked via Segment. These can be tracked from Segment to Mixpanel as Loaded a Page or Loaded a Screen. To turn them off, you need to configure this in your Segment settings.
Integrating Group Analytics via Segment
- Update the Group Identifier Traits in your Segment settings:
- Update your Group Keys in your Mixpanel settings:
- Make sure the “Key” row matches the input for “Group Identifier Traits” in Segment.
- Include the key as a property on your event tracking - if you're using Segment's Device Mode, you can declare the key as a super property, meaning the property will be added to all client-side events. If you're using Segment's Cloud Mode, you cannot declare super properties and will thus have to include the key on every event tracking call you want to be compatible with group analytics
- When you track a group call in Segment (which will create a group profile and update group profile properties), Mixpanel only uses the key that’s specified in the second argument that matches the “Group Identifier Trait” in Segment and “Key” column in Mixpanel:
Different MTU count
- In Mixpanel, one MTU is defined as one unique user who performs at least one and not more than 1,000 events within a calendar month. MTUs are calculated per project.
- In Segment, MTUs are calculated based on the number of unique user_ids plus unique anonymous_ids that appear in any call to Segment in a given month. Object-based sources do not count towards your MTU count.
Resetting the Mixpanel cookie
Segments analytics.reset() method is not mapped to the Mixpanel reset method. You can clear the cookie manually with window.mixpanel.cookie.clear().
Validate requests Segment is sending to Mixpanel
For debugging purposes, it can be useful to see exactly what Segment is sending to Mixpanel. You can validate this data through the Segment debugger. In the Segment debugger, you can select the event you are looking to validate:
Click the “Validate” button in the top right corner and choose “Mixpanel” as the destination. After the event has been sent, you can click to view the request from Segment to grab the data payload:
You can then copy the data payload and decode it in a base64 decoder to see the JSON event that was sent to Mixpanel.