> ## Documentation Index
> Fetch the complete documentation index at: https://docs.mixpanel.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Segment

## Overview

This integration allows you to export Cohorts of users from Mixpanel to Segment so that you can better target users across many downstream connections.

## Permissions

You must be a Mixpanel project admin to enable the Segment integration.

## Enable the Integration

This connection requires set up on both Segment and Mixpanel.

### Segment Setup

The connection requires a Segment Write Key. You can obtain this key via Segment's UI:

1. Log into your Segment workspace and click **Sources** under **Connections** in the menu bar on the left.

2. Click **Add Source** button on the right side above the sources table.

3. Search for **Mixpanel Cohorts**, select and hit next

<Frame>
  <img src="https://mintcdn.com/mixpanel-edb78807/ogXlzma9enlXzenB/images/segment1.png?fit=max&auto=format&n=ogXlzma9enlXzenB&q=85&s=9e1b93a32ccbc0a180845a2909ad6b02" alt="Segment 1 Image" width="1815" height="634" data-path="images/segment1.png" />
</Frame>

4. Create a Mixpanel Cohorts source.

<Frame>
  <img src="https://mintcdn.com/mixpanel-edb78807/ogXlzma9enlXzenB/images/segment2.png?fit=max&auto=format&n=ogXlzma9enlXzenB&q=85&s=7e613e65119dffd29f4cfc6d0628ef95" alt="Segment 2 Image" width="796" height="522" data-path="images/segment2.png" />
</Frame>

5. Copy the\*\* Write Key\*\* displayed there.

<Frame>
  <img src="https://mintcdn.com/mixpanel-edb78807/ogXlzma9enlXzenB/images/segment3.png?fit=max&auto=format&n=ogXlzma9enlXzenB&q=85&s=ae2d8b65b63e09c73d9c14aaf2660aa2" alt="Segment 3 Image" width="1581" height="527" data-path="images/segment3.png" />
</Frame>

### Mixpanel Setup

We will use the Write Key from Segment to enable the connection in Mixpanel.

1. Navigate to **Settings** in the bottom left, then select **Integrations**.
2. Then select Segment, click **Connect**, and paste the\*\* Write Key\*\* that you generated in Segment.

<Note>
  If you set a User ID Property, it should be a Mixpanel user property that matches the Segment User ID.
</Note>

<Frame>
  <img src="https://mintcdn.com/mixpanel-edb78807/ogXlzma9enlXzenB/images/segment5.png?fit=max&auto=format&n=ogXlzma9enlXzenB&q=85&s=9e26571db3b21916a0f02832db27d73d" alt="Segment 5 Image" width="1222" height="1190" data-path="images/segment5.png" />
</Frame>

3. Click **Continue** to complete the process.

## Export a Cohort

To export a Mixpanel cohort into Segment.

1. Navigate to **Lexicon**, then select the **Cohorts** tab to view all of your cohorts.

2. Select the overflow menu on cohort that you want to export and click Export to... → Segment.

<Frame>
  <img src="https://mintcdn.com/mixpanel-edb78807/ogXlzma9enlXzenB/images/segment6.png?fit=max&auto=format&n=ogXlzma9enlXzenB&q=85&s=bce8e68b33307266569ec9a576fd5a8c" alt="Segment 6 Image" width="3626" height="1100" data-path="images/segment6.png" />
</Frame>

3. Select either one-time sync or dynamic sync, Click **Start Sync**.

## Sync Types

There are two types of sync: one-time and dynamic. When you generate a one-time export or dynamic sync, it overwrites the previous export with an updated export that reflects users who qualify for the cohort at the time of export.

### One-Time

In this sync, Mixpanel sends Segment the static set of users who currently qualify for the cohort. The cohort data will not be updated in Segment after a one-time export.

### Dynamic

In dynamic sync, Mixpanel initiates sync between a cohort and Segment every 15 minutes. The exported cohort will be updated every 15 minutes to reflect the most recent list of users in a cohort.

## Verifying in Segment

Once the export completes, you can open the debugger on the source you created in Segment above and you'll see "identify" calls flowing in for each user that has been added or removed from the cohort.

<Frame>
  <img src="https://mintcdn.com/mixpanel-edb78807/ogXlzma9enlXzenB/images/segment7.png?fit=max&auto=format&n=ogXlzma9enlXzenB&q=85&s=a88b50d20383ca13686e81526d715b17" alt="Segment 7 Image" width="1612" height="1168" data-path="images/segment7.png" />
</Frame>

Mixpanel sets a property on the user's profile in Segment indicating whether they are currently part of the cohort.

We send the following identify call to Segment when a user enters the cohort:

```json theme={"system"}
{
  "type": "identify",
  "traits": {
    "Mixpanel - <Cohort Name in Mixpanel>": true,
  },
  "userId": "user@email.com" // we use the distinct_id property here
}
```

We send the following when a user exits the cohort:

```json theme={"system"}
{
  "type": "identify",
  "traits": {
    "Mixpanel - <Cohort Name in Mixpanel>": false,
  },
  "userId": "user@email.com" // we use the distinct_id property here
}
```
