# Segment (Message Metrics)

Set up Customer.io as a Segment Source to pipe data out of Customer.io and into any one of Segment’s hundreds of Destination [integrations](https://segment.com/catalog/). This integration sends data to Segment in `track()` calls. You can send any event supported by our [reporting webhooks](/integrations/api/webhooks/) to Segment.

 Disable and re-enable this integration to gain access to new features!

We updated this integration in May of 2022. If you enabled your Segment Source integration before then, disable the integration and re-enable it to gain access to new events and settings.

## Enable Customer.io as a Segment source[](#enable-customerio-as-a-segment-source)

To enable Customer.io as a Segment source, you need both a Customer.io and a Segment.com account. If you are creating a new Segment account, enter “Customer.io” in the *How Did You Hear About Us?* field.

 We send anonymous events for people who do not have an ID

If a person has an ID, we send events with the ID as the Segment `userId`. If a person has an email address but does not have an ID, we send anonymous events with the email address as the `anonymousId`.

1.  In the Segment interface, Go to *Connections*, click **Add Source**, and select **Customer.io**.
    
2.  Give your source a *Name* and a *Label*, and click **Add Source**. The Name helps you identify your source in Segment, and the label helps you organize sources in your Segment workspace.
    
    [![Segment Sources setup](https://docs.customer.io/images/segment_sources_source_setup.png)](#e87515d7b00ab132884e792df2a4faee-lightbox)
    
3.  On the *Overview* page, copy your *Write Key*.
    
    [![Segment Sources write key](https://docs.customer.io/images/segment_sources_write_key.png)](#53d2b7fcecaaa71d52510085406b002d-lightbox)
    
4.  In your Customer.io workspace, go to *Data & Integrations* > *Integrations* and select the **Segment Source** integration. You can find it in the **Data Management** category.
    
5.  Paste your *Write Key* in the field and click **Connect Segment**.
    
6.  Enable the events you want to send from Customer.io to Segment.
    
    [![Select events to send to segment](https://docs.customer.io/images/segment_source_send_events.png)](#604827534034de53920d3e6269da250e-lightbox)
    
7.  Set your integration options:
    
    *   **Send Frequency**: Determine whether to send every instance of every event or only the first time an event occurs.
    *   **Body Content**: Enable this to include your message’s body content in all of the “Sent” events we send to you.
    *   **Send segment events back to Customer.io destinations**: This setting lets you send events from Customer.io, as a Segment source, back to Customer.io as a Segment destination. In general, we suggest that you leave this feature disabled. The data you send to Segment is already available in Customer.io. [Learn more](#segment-event-loop).
    *   **Segment Data Ingestion Region**: [Set the region](https://segment.com/docs/guides/regional-segment/) you want to ingest data into.
8.  In Segment, turn on the destinations you want to send your Customer.io data to.
    

### How we map people to Segment[](#identify)

Our Segment Source integration maps a person’s `id` in Customer.io to `userId` in Segment.

If your Customer.io workspace supports both `email` and `id` as identifiersThe attributes you use to add, modify, and target people. Each unique identifier value represents an individual person in your workspace., people in your workspace can have an `email` but not an `id`. In this case, we use a person’s `email` as their `anonymousId` in Segment.

For more information about identifying people, see [Segment’s Identify API](https://segment.com/docs/connections/spec/identify/).

 Person without ID

#### Person without ID[](#Person without ID)

```javascript
cioanalytics.track("New Lead", {
  anonymousId: "peter@example.com"
  name: "Peter Gibbons",
  email: "peter@example.com"
});
```

 Person with ID

#### Person with ID[](#Person with ID)

```javascript
cioanalytics.track("New Customer", {
  userId: "97980cfea0067",
  name: "Peter Gibbons",
  email: "peter@example.com",
  plan: "premium"
});
```

### Send segment events back to Customer.io destinations[](#segment-event-loop)

We give you the option to feed events from your source back to Customer.io destinations. In general, **you should not enable this option**. The data that you send to Segment is already available in your workspace. Sending it back to your workspace simply makes this data available as events.

Rather than looping events back into your workspace, you can use our [data-driven segment builderA group of people who match a series of conditions. People enter and exit the segment automatically when they match or stop matching conditions.](/journeys/data-driven-segments/) to trigger campaigns based on your **Message Data**. You can then trigger campaigns based on the ways in which people respond to your messages *without* sending duplicate data back into your workspace.

[![Segment people based on message actions](https://docs.customer.io/images/segment-message-data.png)](#fa50d68c2e4821eec9864f6da3fbd3d3-lightbox)

### Track Payloads: confirm that your Segment Source works[](#track-payloads-confirm-that-your-segment-source-works)

You can confirm that your Customer.io Source is working by sending yourself a test campaign and checking the debugger. Customer.io can send any of our [reporting webhook](/integrations/api/webhooks/) events to Segment, reshaped specifically for Segment’s `track` calls. We’ve provided some examples below to help you understand the information that you’ll see in Segment.

If you enable the **Body Content** setting, the events below will also include a `data.content` key representing the body of your message.

 If a person doesn’t have an ID, we send `anonymousId`

The payloads below all show users with an ID, which we pass to Segment as a `userId`. If a person doesn’t have an ID, `userId` will be an empty string and the payload will include an `anonymousId` populated with the person’s email address.

Email Opened Only `sent` events contain `content`

If you enable the *Include body content in all Sent events* setting, `Email Sent` events will contain body content. For all other email events, `content` is null.

```json
{
  "context": {
    "integration": {
      "name": "customer.io",
      "version": "2.0.0"
    },
    "library": {
      "name": "unknown",
      "version": "unknown"
    },
    "traits": {
      "email": "cool.person@example.com"
    }
  },
  "event": "Email Opened",
  "integrations": {
    "Customer.io": false
  },
  "messageId": "api-1u21CJeZPJX3TdLhPNrzstyAYZa",
  "originalTimestamp": "2021-06-16T13:04:06Z",
  "properties": {
    "action_id": 16,
    "campaign_id": 1,
    "delivery_id": "dgP6xQb6xQYDAAF6FOl-vmR0E7zoPqTRiAo=",
    "journey_id": "01G2NBFT8N2MYDTT3MHWK7Z6C6",
    "subject": "Test Subject",
    "content": null, //null unless Body Content is enabled and event is Email Sent
    "recipient": "cool.person@customer.io",
    "userId": "cool-person"
  },
  "receivedAt": "2021-06-16T13:05:39.605Z",
  "sentAt": "2021-06-16T13:05:39.000Z",
  "timestamp": "2021-06-16T13:04:06.605Z",
  "type": "track",
  "userId": "cool-person",
  "writeKey": "aSOzeRCalHEDr3H5BslyxT4G35vDJBna"
}
```
SMS Sent```json
{
  "context": {
    "integration": {
      "name": "customer.io",
      "version": "2.0.0"
    },
    "library": {
      "name": "unknown",
      "version": "unknown"
    },
    "traits": {
      "email": "cool.person@example.com"
    }
  },
  "event": "SMS Sent",
  "integrations": {
    "Customer.io": false
  },
  "messageId": "api-28wdXq0yQP8jesjRYdLmj2dxiaM",
  "originalTimestamp": "2022-05-09T21:27:02.000Z",
  "properties": {
    "action_id": 41,
    "anonymousId": "cool.person@example.com",
    "campaign_id": 7,
    "content": "Hey, just testing sms segment stuff.",
    "delivery_id": "RKGZAQACAYCqt-kVejTLzrd-t9D_sQ==",
    "journey_id": "01G2NBFT8N2MYDTT3MHWK7Z6C6",
    "recipient": "15555555555",
    "userId": "cool.person@example.com"
  },
  "receivedAt": "2022-05-09T21:27:03.384Z",
  "sentAt": "2022-05-09T21:27:03.151Z",
  "timestamp": "2022-05-09T21:27:02.233Z",
  "type": "track",
  "userId": "karn@customer.io",
  "writeKey": "aSOzeRCalHEDr3H5BslyxT4G35vDJBna"
}
```
SMS Link Clicked```json
{
  "context": {
    "integration": {
      "name": "customer.io",
      "version": "2.0.0"
    },
    "library": {
      "name": "unknown",
      "version": "unknown"
    },
    "traits": {
      "email": "cool.person@example.com"
    }
  },
  "event": "SMS Link Clicked",
  "integrations": {
    "Customer.io": false
  },
  "messageId": "api-1u242Y8g1XCtEl9rEp7NwBx3K9o",
  "originalTimestamp": "2021-06-16T13:29:01Z",
  "properties": {
    "action_id": "n18",
    "campaign_id": 3,
    "delivery_id": "dgP6xQb6xQYDAAF6FQJvh4yaVoIOMGeCVp4=",
    "content": null, //null if Body Content is disabled
    "journey_id": "01G2NBFT8N2MYDTT3MHWK7Z6C6",
    "recipient": "15555555555",
    "userId": "cool.person@example.com",
    "link": {
      "id": 1,
      "url": "https://customer.io/features"
    }
  },
  "receivedAt": "2021-06-16T13:29:03.021Z",
  "sentAt": "2021-06-16T13:29:02.000Z",
  "timestamp": "2021-06-16T13:29:02.021Z",
  "type": "track",
  "userId": "cool-person",
  "writeKey": "aSOzeRCalHEDr3H5BslyxT4G35vDJBna"
}
```
Push Sent```json
{
  "context": {
    "integration": {
      "name": "customer.io",
      "version": "2.0.0"
    },
    "library": {
      "name": "unknown",
      "version": "unknown"
    },
    "traits": {
      "email": "cool.person@example.com"
    }
  },
  "event": "Push Sent",
  "integrations": {
    "Customer.io": false
  },
  "messageId": "api-1u21CJeZPJX3TdLhPNrzstyAYZa",
  "originalTimestamp": "2021-06-16T13:04:06Z",
  "properties": {
    "action_id": "n16",
    "campaign_id": 1,
    "delivery_id": "dgP6xQb6xQYDAAF6FOl-vmR0E7zoPqTRiAo=",
    "journey_id": "01G2NBFT8N2MYDTT3MHWK7Z6C6",
    "recipients": [
      {
        "device_id": "15ad6c7ddc29f1d6a28580b040ddddfb831fd009bafac1dff718be7ed4233c15",
        "device_platform": "ios"
        
      }
    ],
    "userId": "cool.person@example.com"
  },
  "receivedAt": "2021-06-16T13:05:39.605Z",
  "sentAt": "2021-06-16T13:05:39.000Z",
  "timestamp": "2021-06-16T13:04:06.605Z",
  "type": "track",
  "userId": "cool-person",
  "writeKey": "aSOzeRCalHEDr3H5BslyxT4G35vDJBna"
}
```
Slack Sent```json
{
  "context": {
    "integration": {
      "name": "customer.io",
      "version": "2.0.0"
    },
    "library": {
      "name": "unknown",
      "version": "unknown"
    },
    "traits": {
      "email": "sales@example.com"
    }
  },
  "event": "Slack Sent",
  "integrations": {
    "Customer.io": false
  },
  "messageId": "api-1u21CJeZPJX3TdLhPNrzstyAYZa",
  "originalTimestamp": "2021-06-16T13:04:06Z",
  "properties": {
    "action_id": "n16",
    "campaign_id": 1,
    "delivery_id": "dgP6xQb6xQYDAAF6FOl-vmR0E7zoPqTRiAo=",
    "journey_id": "01G2NBFT8N2MYDTT3MHWK7Z6C6",
    "recipient": "#cool-channel",
    "userId": "cool.person@example.com"
  },
  "receivedAt": "2021-06-16T13:05:39.605Z",
  "sentAt": "2021-06-16T13:05:39.000Z",
  "timestamp": "2021-06-16T13:04:06.605Z",
  "type": "track",
  "userId": "sales-team",
  "writeKey": "aSOzeRCalHEDr3H5BslyxT4G35vDJBna"
}
```
Webhook Sent```json
{
  "context": {
    "integration": {
      "name": "customer.io",
      "version": "2.0.0"
    },
    "library": {
      "name": "unknown",
      "version": "unknown"
    },
    "traits": {
      "email": "cool.person@example.com"
    }
  },
  "event": "Webhook Sent",
  "integrations": {
    "Customer.io": false
  },
  "messageId": "api-1u21MrfL8kIJwhuNanhhBbuc9gq",
  "originalTimestamp": "2021-06-16T13:05:55Z",
  "properties": {
    "action_id": "n17",
    "campaign_id": 2,
    "delivery_id": "dgP6xQb6xQYDAAF6FOsF0yqZiIo1NgezYcI=",
    "journey_id": "01G2NBFT8N2MYDTT3MHWK7Z6C6",
    "recipient": "https://example.com/webhook-url",
    "userId": "cool.person@example.com"
  },
  "receivedAt": "2021-06-16T13:07:04.404Z",
  "sentAt": "2021-06-16T13:07:04.000Z",
  "timestamp": "2021-06-16T13:05:55.404Z",
  "type": "track",
  "userId": "cool-person",
  "writeKey": "aSOzeRCalHEDr3H5BslyxT4G35vDJBna"
}
```

If events flow into your Segment debugger, you’ll know that the Source is properly enabled.

[![segment_sources_debugger.png](https://docs.customer.io/images/segment_sources_debugger.png)](#b889385926da5bc3e2f628a46932c18b-lightbox)

## Upgrade your integration[](#upgrade-your-integration)

If you had the previous iteration of this integration enabled, you were only able to send email events to Segment. To update your integration to version 2.0, disable the integration and then re-enable it. When you re-enable the integration, you’ll have access to the new event types and other settings made available in May of 2022.

[![An upgraded Segment Source integration](https://docs.customer.io/images/segment_source_send_events.png)](#604827534034de53920d3e6269da250e-lightbox)

### Differences between versions 1.0 and 2.0[](#differences-between-versions-10-and-20)

When updating from version 1.0 to 2.0, you’ll notice the following changes:

*   `version` is incremented from `1.0.0` to `2.0.0`.
*   `email_id` is no longer included in Email events. This field duplicated the `delivery_id`.
*   When you enable *Body Content* for email events, `email_subject` has changed to simply `subject`.
*   Events no longer include `action_name`, `campaign_name`, `newsletter_name`, or `transactional_message_name`. We’ve removed these items to improve performance. Instead, you can retrieve these values using the corresponding object id (ie `campaign_id`) and our [App API](/integrations/api/app/).

## Need help?[](#need-help)

*   If you run into issues enabling the Customer.io Source, finding your *Write Key*, setting up a Segment workspace, or find that your data isn’t syncing, [contact Segment’s support team](mailto:friends@segment.com).
*   Not seeing Customer.io events in the Segment debugger? [Get in touch with support](https://fly.customer.io/?support=true)!