You may be eligible for $50K in Segment credit as part of the Mixpanel Startup Credit program.

Segment

Overview

Segment, a Customer Data Platform (CDP), enables you to track event data and route it to various downstream destinations. As a native partner, Mixpanel seamlessly integrates with Segment. If you use Segment for tracking, you can send your data to Mixpanel with just a few clicks.

How the Integration Works

In the simplest form, the Segment libraries (“Sources”) generate messages about what is happening in your site or app, and send them to the Segment servers. Segment then translates the content of those messages into different formats for use by other tools (which we call ‘Destinations’), and sends the translated messages to those tools. The Segment servers also archive a copy of the data, and can send data to your storage systems (such as databases, warehouses, or bulk-storage buckets).

Mixpanel is one of the supported Segment destinations. With this integration, you can easily send your data collected from your Segment source into your Mixpanel project as a downstream destination.

For detailed instructions on how to install the Segment tracking library, please refer to the Segment Getting Started Guide.

Quick Start

1. Integrate with Segment

Once you’ve installed and initialized a Segment library in your application, get your data into Mixpanel by following the instructions for setting up the Mixpanel (Actions) Destination

2. Identify Users

The next thing you need to do is identify your users, so that you can understand your users. We recommend calling identify when your user sign up and log in.

When you call Segment’s identify API, Mixpanel will set the specified userId as the Mixpanel distinct_id. Any traits you provide in the call will be applied as profile properties for the targeted user in Mixpanel.

3. Track User Actions

Lastly, track your users’ actions using Segment’s track API call, which would trigger Mixpanel’s import API and ingest an event in your project.

4. Check for Success

Open up Events View in Mixpanel to view incoming events.

Configure the Destination

We recommend using the Mixpanel Actions destination.

Once you have installed the Segment library and see tracked data in your Segment instance, get your data into your Mixpanel project by setting up a destination following the Segment documentation here.

Below is a high-level summary of the steps to setup the Mixpanel destination:

  1. In Segment, click the Catalog tab, filter for Destinations, and select Mixpanel to add the destination.

segment_catalog

  1. Select a Segment source to stream to the destination.

segment_source

  1. Set a name for the destination then choose a framework. We recommend Actions destination. (Learn more about the framework options)

segment_action_select

  1. Provide your Mixpanel project credentials in the Basic Settings, then click the toggle at the bottom to enable the destination. The project credentials are found in your project settings.

segment_enable_setting

Data Mapping

Segment’s Actions framework allows you to configure how Segment sends the data it receives from your source to Mixpanel.

Preset Actions

The Mixpanel Actions destination comes with a preset of default mappings that you can use out the box. You can find them in the “Mappings” tab of the destination settings.

Preset NameSegment TriggerMixpanel Action
Order Completed CallsEvent type = “track” and event = “Order Completed”Import Event “Order Completed”
Track CallsEvent type = “track” and event != “Order Completed”Import Event
Screen CallsEvent type = “screen”Import Event “Viewed {name}“
Identify CallsEvent type = “identify”Identify User (Simplified API /Original API) and Set Profile Properties
Page CallsEvent type = “page”Import Event “Viewed {name}“
Group CallsEvent type = “group”Identify Group

Customize Mappings

⚠️

Note that context (learn more here) is a Segment concept which does not have an equivalent in Mixpanel’s data model. If there are keys inside of the context dictionary that you need to add to your event and it is not a default property that is already in the mapping, you will need to edit the properties object to manually include it.

You can customize the preset actions mapping or create new mappings to further configure your event payload before they are sent to Mixpanel.

To edit an existing mapping, click the ”…” button in the actions table. To create a new mapping, click the “New Mapping” button in the top right of the UI.

segment_mapping

Editing or creating new mappings is done in 4 steps.

1. Set Condition

Define the conditions under which the action should run. You can specify the conditions using a combination of Event Type, Event Name, and Event Property.

Let’s say you want to create a mapping that is triggered for any events tracked on Android. In this case, we can set the condition to Event Type equal Track and Event Property platform equal android:

segment_condition

2. Sample Payload

For testing your mapping, set an example payload. You can use an existing event from your source, load a Segment-generated sample event, or create a sample payload manually.

Ensure that this example payload matches the condition you set above so that the Action applies to your expected payload. As a best practice, insert an example payload that you know should not match the condition to verify that your condition is specific enough to target only your expected payload.

Since we’re creating a mapping for any events tracked on Android, we insert a test event payload that includes the property platform set to android:

segment_sample_payload

3. Edit Mapping

Edit the mapping of the Action to configure your output payload in your desired format. In this stage, we are essentially creating a Segment payload using data that is generated from Segment’s SDK, which will then be sent to Mixpanel’s destination mapping code for additional processing.

On the left side of the UI, you can configure the output value using the available data from your Segment source payload. On the right side of the UI, you can define the property names for the Segment payload that will be sent to Mixpanel.

If we want to append “ANDROID” to the names of events coming from this Android actions mapping, specify this in the Event Name row on the left-hand side:

segment_mapping_name

To include the messageId from the sample Segment payload as a Mixpanel event property called “Segment Message ID”, edit the Event Properties mapping:

segment_mapping_properties

By default, the track preset takes the entire properties object from the Segment payload and uses it to generate “Event Properties” for the Mixpanel event payload. To edit the event properties mapping, you will need to manually define each property key-value pairs manually. segment_mapping_properties_edit

4. Preview Payload

Once you are done with configuring the mapping, preview how your sample payload is mapped through the Action by expanding on the “Event context”. You can also ingest the sample payload into Mixpanel to see how it will appear in your project by clicking “Send test event to destination”.

Note that while the Event Content tab is helpful for showing how your properties are getting mapped through the Action, your payload will go through additional processing before getting ingested in Mixpanel. Send the test payload to destination in order to preview how your event will appear inside your project.

segment_test_event

Implementing Group Analytics using Segment

There are 4 parts to implementing Group Analytics via Segment. Learn more about Group Analytics here and the Segment Group Spec here.

1. Define the Group Key in Mixpanel

Create the Group Key in Mixpanel Project Settings. In this example, we are setting company_id as the group key.

1groupkey_projectsettings

2. Configure your Group Actions Mapping

If a Group Key mapping is not specified, Segment will use $group_id as the group key by default. In this case, set your group key in Mixpanel to $group_id.

Edit the Group action preset or create a new action mapping to target your group calls. You should manually type in the group key in the mapping to the same as it appears in the Mixpanel settings.

Additionally, make sure the “Group ID” is mapped to the value of the groupId.

Since we set the group key to company_id earlier, we manually enter it as the Group Key in the mapping. The groupId is the default key that Segment uses as the identifier for a group, so we map it to the Group ID.

segment_group_mapping

3. Create Group Profiles

Calling Segment SDK function analytics.group() will create Group Profile/Group Profile Properties in Mixpanel.

//the groupId is "some_company"
//the second argument contain 3 group profile properties to be set
analytics.group("some_company", {
    "$name": "some_companys_name",
    "employees": 100,
    "id": "some_company"
})

Example Group Profile/Group Profile Properties created from the group method above:

4groupprofile

4. Add Group Key as a User Profile Property

In order to use Group Profile Properties when analyzing User Profiles, the user profile must have the Group Key/Group ID Value as a profile property.

Declare the Group Key in the identify method as a profile property (trait): 5identify

5. Add Group Key as an Event Property to Events

In order to connect events to a Group, the event must have the Group Key/Group ID Value as an event property.

The Group Key must be explicitly declared as an event property on every event track call in order for the event to be compatible with Group Analytics.

6trackcall

If you are using Segment Device Mode (Classic destination):

  • Declare the Group Key as a Super Property so that the Group Key is sent in as an Event Property to client-side events.
  • By default, all traits specified in the identify call will be registered as super properties. This means if you have the “Automatically set all Traits as Super Properties and People Properties” setting turned on, all traits specified in the identify call will be added as both a super property and profile property for the user.

Debugging

For debugging purposes, it can be useful to see exactly what Segment is sending to Mixpanel. You can validate this data through the Segment Source Debugger. In the Segment Source Debugger, you can select the event you are looking to validate:

yGK1yH7zGy_cv5hLBEHgdU9oMyALishD6S0kObRRJANGxbjIEL

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: pasted image 0 (1)

You can then copy the data payload and decode it in a base64 decoder to see the JSON event that was sent to Mixpanel.

Startup Credit Program

Mixpanel offers $50K in credits to eligible startups. Because of our Segment partnership, we’re also able to offer startups $50k in Segment credits. This gives startups the runway to use both tools for free.

Once you create your Segment and Mixpanel accounts, you can fill out this form and Segment will get back to you within 48 hours to confirm your credits are applied.

Startup eligibility requirements:

  • Founded less than 2 years ago
  • Raised no more than $8MM USD in total funding

FAQ

1. Why are my Segment data not appearing in my project?

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. 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 (Only applies to Classic destination; Action is cloud-mode only): 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 (Classic destination only): Segment does not 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.

2. Why are there duplicated Segment events in my project?

Mixpanel SDKs assign an $insert_id to each tracked event.

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.

3. How do I register super properties using Segment?

Super properties can only be set when you are running in device mode and using the Classic destination. 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.

4. How do I track page views using Segment?

In analytics.js, a Page call is included in the initialization snippet by default right after analytics.load(). Otherwise, you will want you will want to call analytics.page() manually to track page view.

For the Preset Action, the default Event Name mapping for page call is Viewed {name}. To consolidate event names (e.g. “Page Viewed” or “Loaded a Page”), modify the Event Name mapping.

segment_page_name_mapping

5. How can I filter for events that originate from Segment in my project?

Events coming from Segment are marked with the event property mp_lib (Mixpanel Library) set to the name of the Segment SDK used to generate the event. For example, events sent using Segment’s Javascript SDK will have the mp_lib property set to Segment: analytics.js.

Was this page useful?