# Campaign for syncing Mixpanel cohorts

Send cohort data from Mixpanel to Customer.io Journeys so you can add people, index events, and more.

In Mixpanel, you can organize users into [cohorts](https://docs.mixpanel.com/docs/users/cohorts), which are akin to segments in Customer.io. Mixpanel cohorts compile users based on criteria like what events they’ve performed. You can send cohort data from Mixpanel to Customer.io through webhooks, and you can trigger campaigns to update people, index events, and more. Visit [Mixpanel’s documentation on webhooks](https://docs.mixpanel.com/docs/cohort-sync) for more info.

## Before you begin[](#before-you-begin)

### Mixpanel[](#mixpanel)

You must have a paid Mixpanel plan to create custom webhooks. View other [prerequisites](https://docs.mixpanel.com/docs/cohort-sync/webhooks) here.

### Customer.io[](#customerio)

In your Customer.io workspace, [create a webhook-triggered campaign](/journeys/webhook-triggered-campaigns/). Select the trigger block then choose **Webhook**. Next, [set up a custom webhook in Mixpanel](#set-up-mixpanel).

## Set up Mixpanel[](#set-up-mixpanel)

1.  Log into Mixpanel.
2.  Go to *Data Management > Integrations* in the top navigation.
3.  Select **Custom Webhooks** from the list of integration options.
    
    [![webhook-campaign-mixpanel-connection.png](https://docs.customer.io/images/webhook-campaign-mixpanel-connection.png)](#7e773e0c7a172fa66073b89d148cda4e-lightbox)
    
4.  Create a **Connection**. If you already have connections, select the connection dropdown then click **Add Connection** at the bottom.
    1.  Provide a name. Then copy/paste the URL under Trigger Conditions from your campaign in Customer.io.
    2.  Enter your [Track API credentials](https://fly.customer.io/settings/api_credentials) under *Username* and *Password*. Make sure you use credentials for the correct workspace.
5.  Go to *Data Management > Cohorts*. Create a cohort you want to send to your workspace or select an existing cohort.
6.  Click the three dots  followed by **Export to…**. Choose the name of your custom webhook then the sync frequency: one time or recurring. Click **Begin Sync** when you’re done. This will populate test data in your workspace to help you set up your workflow.

 Mixpanel will not send more than 1,000 users per call. For info on retries, custom properties, and more, visit [Mixpanel’s documentation](https://docs.mixpanel.com/docs/cohort-sync/webhooks#faq).

## Finish setting up your webhook-triggered campaign[](#set-up-campaign)

1.  Go to your webhook-triggered campaign.
    
2.  Drag a **Send and Receive Data** block onto the canvas. We refer to this as a *Webhook Action*.
    
3.  Click **Add Request** in the left hand pane.
    
4.  Create a **POST** request targeting [our track v2 endpoint for multiple requests](/integrations/api/track/#operation/batch). If you’re in the EU, make sure you use our endpoint with `track-eu` in the URL.
    
    [![webhook-campaign-mixpanel-send-data-1.png](https://docs.customer.io/images/webhook-campaign-mixpanel-send-data-1.png)](#f2aa9b2d06b87ca5fc587576c5460ed3-lightbox)
    
5.  Add your [Track API credentials](https://fly.customer.io/settings/api_credentials) to the `Authorization` header: Basic {{ ‘siteID:appKEY’ | base64 }}. Make sure you use credentials for the correct workspace; these need to match those you added to Mixpanel.
    
6.  Add the following JSON to the body:
    
    ```TEXT
        { 
            "batch": [ 
                {% for items in trigger.parameters.members %}
                    {
                        "type": "person",
                        "identifiers": {
                            "id": "{{items.<id>}}"
                        },
                        "action": "event",
                        "name": "{{ trigger.parameters.mixpanel_cohort_name }}",
                        "attributes":  {{ items | to_json }}
                    }
                    {% unless forloop.last %},
                    {% endunless %}
                {% endfor %}
            ]
        }
    ```
    
    Make sure your identifiers match your *General workspace settings*. For instance, if you identify people by email, you’ll want to replace with `email`.
    
    On the left, you’ll see the test data sent from setting up your cohort in Mixpanel.
    
7.  Click **Save**.
    
8.  Click **Review items** if you have outstanding steps to complete.
    
9.  Then click **Start Campaign** to review your settings and go live!
    
10.  If you set up your cohort to send once, go back to Mixpanel and export the cohort again.
    

After the webhook triggers the campaign, you’ll see new people and events created in your workspace. New people are identified based on the `id` provided in the payload. An event with the cohort name and attributes will be added to your Data Index and associated with all people in this payload.

[![webhook-campaign-mixpanel-new-person-and-event.png](https://docs.customer.io/images/webhook-campaign-mixpanel-new-person-and-event.png)](#1d51359c675799b05035db0711c5eac5-lightbox)

### Add event attributes to people’s profiles[](#add-event-data-to-people)

You add event data to people in a couple of ways:

*   You can add a [**Create/update person action**](/journeys/create-update-person/) after the webhook action in this campaign.
*   You can create a [**campaign triggered by an event**](/journeys/campaign-triggers/#event-trigger) (the cohort in this case) to craft a new workflow that could also include updating profiles based on event data.

## Create a segment from a Mixpanel cohort[](#create-a-segment-from-a-mixpanel-cohort)

After you send cohort data from [Mixpanel](#set-up-mixpanel) to [Customer.io](#set-up-campaign) through a webhook-triggered campaign, you can create segments that correspond to these cohorts to track the population over time.

To create a segment that targets a Mixpanel cohort:

1.  Go to  *Segments*.
2.  Click **Create Segment**.
3.  Give your segment a name and description so you know which cohort it relates to.
4.  Choose *Data-driven segment* so that your segment audience stays in sync with your cohort data from Mixpanel.
5.  Recall that cohort data comes over as an event. Select *Add condition or group* then choose **Event** from the dropdown.
    
    [![webhook-campaign-mixpanel-segment.png](https://docs.customer.io/images/webhook-campaign-mixpanel-segment.png)](#0f572dd6be139b5b54a7a558ce4f1a31-lightbox)
    
6.  In the event\_name field, select your cohort name.
7.  Then choose whether you want to target people who have or have not performed this event. Hover over the condition and click **Refine** to filter the audience further.
8.  **Save** your changes.

You can use this to trigger a campaign, but to reference any event attributes (attributes of the cohort in this case) in messages, you’ll need to create an [event-triggered campaign](/journeys/campaign-triggers/#event-trigger) or [store event data on people’s profiles](#add-event-data-to-people).