# Customer.io Destination

## Destination Info

* Accepts [Page](/docs/segment/connections/spec/page), [Identify](/docs/segment/connections/spec/identify), [Track](/docs/segment/connections/spec/track) calls.
* Refer to it as **Customer.io** in the [Integrations object.](/docs/segment/guides/filtering-data/#filtering-with-the-integrations-object)

### Components

* Browser
* Server

## Connection Modes

[Learn more about connection modes.](/docs/segment/connections/destinations/#connection-modes)

### Device-Mode

* web: yes
* mobile: no
* server: no

### Cloud-Mode

* web: yes
* mobile: yes
* server: yes

> \[!WARNING]
>
> A new version of this destination is available. See [Customer.io (Actions)](/docs/segment/connections/destinations/catalog/actions-customerio/) for more information.

[Customer.io](https://customer.io/) helps you send automated email, push, SMS, and webhooks based on your customers' activities in your app or product. It makes conversion tracking, optimization and re-marketing easier. The `analytics.js` Customer.io Destination is open-source. You can browse the code [on GitHub](https://github.com/segmentio/analytics.js-integrations/tree/master/integrations/customerio).

> \[!TIP]
>
> **Good to know**: This page is about the Customer.io Segment destination, which receives data from Segment. There's also a page about the [Customer.io Segment source](/docs/segment/connections/sources/catalog/cloud-apps/customer-io/), which sends data *to* Segment!

## Getting Started

You can follow the setup guide through Segment using the steps below, or you can automatically sync your Customer.io connection settings to your Segment source using the flow in your Customer.io workspace's Integrations page.

1. From the Segment web app, click **Connections** > **Destinations**.
2. Search for "Customer.io", select it, and then click **Configure Customer.io**.
3. Select the data sources you want to connect to Customer.io and click **Next**.
4. Enter your *Destination Name* and select your **Connection Mode**—Cloud Mode or Device Mode. Click **Save**.
5. Under *Connection Settings*, enter your Customer.io workspace **API Key** and **Site ID**. You'll find your Site ID and API Key in Customer.io under **[Settings > Workspace Settings > API Credentials](https://fly.customer.io/workspaces/last/settings/api_credentials)**. You can use any Site ID/API Key pair with Segment. You may even want to Create a new Track API Key just for this integration.

![Customer.io interface showing tracking API keys with options to create new keys.](https://docs-resources.prod.twilio.com/c2f414630d126aaad59f5f01ebf094753cd6a350b3deb7d775da951459b61a3b.png)

## Page

If you're not familiar with the Segment Specs, take a look to understand what the [Page method](/docs/segment/connections/spec/page/) does. An example call would look like:

```javascript
analytics.page();
```

Page events send to Customer.io as a `Page View` event where names and properties are optional. In the Customer.io "Activity Logs", the event will have "Activity Type" set to "Page View" and "Activity Name" set to the page name. If there is no page name, "Activity Name" defaults to the page URL.

## Screen

If you're not familiar with the Segment Specs, take a look to understand what the [Screen method](/docs/segment/connections/spec/screen/) does. An example call would look like:

```objc
[[SEGAnalytics sharedAnalytics] screen:@"Home"];
```

Screen events send to Customer.io as a custom event. In the Customer.io "Activity Logs", "Activity Type" is `event` and "Activity Value" sets to `Viewed {screen name} Screen`. For the earlier example the "Activity Value" will be `Viewed Home Screen`. If there is no screen name, then "Activity Value" will be `Viewed Undefined Screen`.

## Identify

If you're not familiar with the Segment Specs, take a look to understand what the [Identify method](/docs/segment/connections/spec/identify/) does. An example call looks like this:

```javascript
analytics.identify('userId123', {
  email: 'john.doe@example.com'
});
```

When you identify a new user, Customer.io adds the user to your Customer.io workspace. If the user exists, the identify request updates the existing person's attributes.

If your Customer.io workspace supports both `email` and `id` as identifiers (the default setting as of June 2021), you can identify people either by a database identifier (called `id` in Customer.io) or the `email` trait.

This provides a path to identify people who enter your system as leads (by email) and then assign them an ID in Customer.io when they become a customer or user.

* If you don't have an ID, pass a person's email address as the `userId` in the identify call. Customer.io maps this value to a person's `email` attribute.
* If you have an ID, set the `userId` in the identify call to the person's ID and pass `email` as a trait. This sets both a person's `id` and `email` attributes in Customer.io. If you previously identified a person by `email`, your request updates that person and assigns them an `id`.

### Updating people

When Customer.io recognizes either the `id` or `email` in your request, your identify request updates that person.

```javascript
analytics.identify('userId123', {
  email: 'john.doe@example.com',
  fav_food: 'pizza'
});
```

If you want to change the `id` or `email` you've assigned a person in Customer.io, you have to pass a person's `cio_id`, in the format `cio_<cio_id value>` as the `userId` in your identify call. Currently, you must retrieve this value from a person's page in the Customer.io interface. In the future, you'll be able to do that using this call from Customer.io API.

```javascript
analytics.identify('cio_<cio_id value>', {
  email: 'new.email@example.com',
  id: 'new-id-value'
});
```

### Unsubscribing Users

To unsubscribe a user, simply pass `unsubscribed: true` in an identify call. Be sure the `id` and/or `email` values match the values in Customer.io. You can find these values in Customer.io by selecting a person on the *People* page, and clicking *Attributes*. Here is an example that unsubscribes a user:

```javascript
analytics.identify('userId123', {
    email: 'john.doe@example.com',
    unsubscribed: true
  }
)
```

### Identifying people in workspaces that only support ID

In older workspaces, or workspaces using Customer.io's "classic" settings, you can only identify people by ID.

You do not need to pass an email address unless you want to send emails. If you want to send emails, you must provide the email address as a trait labeled `email`.

## Track

If you're not familiar with the Segment Specs, take a look to understand what the [Track method](/docs/segment/connections/spec/track/) does. An example call would look like:

```javascript
analytics.track('Clicked Button');
```

Track events send to Customer.io as `custom events`. In the Customer.io "Activity Logs", "Activity Type" sets to `event` and "Activity Name" sets to the event name.

## Device token setup

Set `device.token` before you send the `Application Installed`, `Application Uninstalled`, or `Application Opened` events to Segment. For more on why you'd want to send `device.token`, see Customer.io's [device token documentation](https://customer.io/docs/journeys/device-tokens/#what-is-a-device-token). You'll likely need to extract this value from your push notification provider.

For that, you need to make the following calls:

* For Android, you need to make a call to `putDeviceToken` when Segment client initializes.
  * Read [more here](/docs/segment/connections/sources/catalog/libraries/mobile/android/#how-should-i-use-outbounds-push-notifications) for adding tokens for Android devices
* For iOS, you need to make a call to `segment.registeredForRemoteNotifications` when you receive the `didRegisterForRemoteNotificationsWithDeviceToken` event.
  * Read [more here](/docs/segment/connections/sources/catalog/libraries/mobile/ios/#how-do-i-use-push-notifications) for adding tokens for iOS devices

## Application Installed

[Application Installed](/docs/segment/connections/spec/mobile/#application-installed) events will add or update a device in the person's Customer.io profile using the Customer.io [Add or update a customer device](https://customer.io/docs/api/#operation/add_device) API endpoint. Note, you must pass a device token in your event payload using a `context.device.token` property. See more on Contextual properties [in the Spec: Common](/docs/segment/connections/spec/common/#context) docs.

```js
{
"action": "track",
"userId": "019mr8mf4r",
"event": "Application Installed",
"properties": {
  "version": "1.2.3",
  "build": 1234
},
"context": {
  "device": {
    "token": "ff15bc0c20c4aa6cd50854ff165fd265c838e5405bfeb9571066395b8c9da449",
    "type": "ios"
  }
}
}
```

## Application Opened

[Application Opened](/docs/segment/connections/spec/mobile/#application-opened) events will add or update a device in the person's Customer.io profile using the same endpoint as above. If a device already exists, Customer.io will update its `last_used_at` timestamp. Again, make sure you pass a device token in your event payload using a `context.device.token` property. See more on [Contextual properties](/docs/segment/connections/spec/common/#context).

```js
{
"action": "track",
"userId": "019mr8mf4r",
"event": "Application Opened",
"properties": {
  "version": "1.2.3",
  "build": 1234
},
"context": {
  "device": {
    "token": "ff15bc0c20c4aa6cd50854ff165fd265c838e5405bfeb9571066395b8c9da449",
    "type": "ios"
  }
}
}
```

## Application Uninstalled

[Application Uninstalled](/docs/segment/connections/spec/mobile/#application-installed) events will remove the device from the person's Customer.io profile using [this](https://customer.io/docs/api/#operation/delete_device) API endpoint. Note, you must pass a device token in your event payload using a `context.device.token` property. See more on [Contextual properties](/docs/segment/connections/spec/common/#context).

```js
{
"action": "track",
"userId": "019mr8mf4r",
"event": "Application Uninstalled",
"properties": {
  "version": "1.2.3",
  "build": 1234
},
"context": {
  "device": {
    "token": "ff15bc0c20c4aa6cd50854ff165fd265c838e5405bfeb9571066395b8c9da449",
    "type": "ios"
  }
}
}
```

### Sending Data from Customer.io

You can enable Customer.io as a Segment Source to send [email events](/docs/segment/connections/spec/email/) to other tools on the Segment platform. These events are sent as track calls to the other destinations you've turned on.

To enable this feature:

1. In Customer.io go to **[Data & Integrations\*\* > **Integrations** > \*\*Segment (Message Activity)](https://fly.customer.io/workspaces/last/journeys/integrations/segment_out)**.
2. Add your *Segment Write Key* and click **Connect Segment**.
3. Select the events you want to send to Segment. When you're done configuring the integration, make sure the *Integration State* is set to **Enabled**.
4. Click **Save and Enable Integration**.

![Customer.io integration settings with Segment, showing event selection and options.](https://docs-resources.prod.twilio.com/4a2cf63983f39fd818bd487a70f7c63b5c7caac0bd2a49de0bf7e04f5a182ddf.png)

## Best Practices

### Rate Limits

Customer.io's [Track API](https://docs.customer.io/integrations/api/track/#tag/trackLimit) has a rate limit of 1000 requests per second. It's not strictly enforced, but consistently exceeding it may lead to throttling, especially during periods of high system load. If Customer.io detects a sustained high volume that could impact other customers, they may contact you to help adjust your integration.

If you use Segment's [HTTP API](/docs/segment/connections/sources/catalog/libraries/server/http-api) to send batches of events to Customer.io, you can throttle the `import` to keep your requests under this rate limit.

## Troubleshooting

### No Events in Customer.io from the Browser

Remember that before Segment can send events to Customer.io from client-side JavaScript, the current user must identify with their `userId`. The user's email address is only used to identify them if that is the ID on record for them in Customer.io.
Verify that your Customer.io workspace doesn't have any filters configured, as these filters could prevent campaigns from triggering.

### Page events not associated with user

Page events will associate to a user if the user has been previously identified in Customer.io. If you identify a user after making Page calls, the previous page events won't associate to the user in Customer.io.

## Engage

You can send computed traits and audiences generated using [Engage](/docs/segment/engage) to this destination as a **user property**.

For user-property destinations, an [identify](/docs/segment/connections/spec/identify/) call sends to the destination for each user that's added and removed. The property name is the snake\_cased version of the audience name, with a true/false value to indicate membership. For example, when a user first completes an order in the last 30 days, Engage sends an Identify call with the property `order_completed_last_30days: true`. When the user no longer satisfies this condition (for example, it's been more than 30 days since their last order), Engage sets that value to `false`.

> \[!TIP]
>
> Customer.io requires you to pass an identifier value (ID or email, depending on your workspace settings), when you sync Audiences or Computed Traits.

When you first create an audience, Engage sends an Identify call for every user in that audience. Later audience syncs only send updates for users whose membership has changed since the last sync.

## Settings

Segment lets you change these destination settings from the Segment app without having to touch any code.

| Field                  | Description                                                                                                                                                                                                                                                                                                                                                     | Required | Type    |
| ---------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------- | ------- |
| API Key                | You can find your API Key in Customer.io > Integrations > Segment Destination. It should be 20 or 64 characters long, and look something like this: 91837a6c9e8b49d0ef71. An API Key is required if you're using our server-side or mobile libraries. For more details you can view the \[Customer.io Docs]\(https://customer.io/docs/en/segment-destination).  | No       | string  |
| Convert To Unix Time   | If true, timestamps are converted to Unix Time.                                                                                                                                                                                                                                                                                                                 | No       | boolean |
| Customer.io Datacenter | Choose your Customer.io gateway for data residency.                                                                                                                                                                                                                                                                                                             | No       | select  |
| Site ID                | You can find your Site ID on the Customer.io \[Integration page]\(https://fly.customer.io/account/customerio\_integration).                                                                                                                                                                                                                                     | Yes      | string  |
