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

# Segment

> Sync rich customer data from your data warehouse to hundreds of SaaS tools via Segment's large integration library

## Overview

Besides the ability to track first-party customer data, Segment offers robust integrations with the most popular SaaS tools. With our Segment integration, you can automatically sync enriched customer data from your data warehouse with Segment to send this data to downstream tools that Hightouch doesn't already integrate with.

## Supported syncing

| Sync Type | Description | Supported Sync Modes | API Reference |
| - | - | - | - |
| **Track (Generic) events** | Sends events of different names when a record is added, changed, or removed in the query results | Insert | [Track specs](https://segment.com/docs/connections/spec/track/) |
| **Track (Segment Entered / Exited) events** | Sends the event "Segment Entered" when a record is added and "Segment Existed" when a record is removed | Insert | [Track specs](https://segment.com/docs/connections/spec/track/) |
| **Identify events** | Sends an identify event with related properties of the user | Insert | [Identify specs](https://segment.com/docs/connections/spec/identify/) |
| **Group events** | Sends a group event to associate a user to a group | Insert | [Group specs](https://segment.com/docs/connections/spec/group/) |

> [!WARNING]
>
> To ensure syncs send each event, your event model must use a truly unique [primary key](https://docs.hightouch.com/getting-started/concepts.md#unique-primary-key-requirement). See the [events syncs](https://docs.hightouch.com/syncs/types-and-modes.md#event-syncs) documentation for more information.

For more information about sync modes, refer to the [sync modes](https://docs.hightouch.com/syncs/types-and-modes.md#sync-modes) docs.

## Connect to Segment

Go to the [**Destinations** overview page](https://app.hightouch.com/destinations?from=docs) and click the **Add destination** button. Select **Segment** and click **Continue**. You can then authenticate Hightouch to Segment using a Segment **Write Key**.

To retrieve the write key for your Segment destination in Hightouch:

1. Create a new HTTP API source in Segment using [these instructions](https://segment.com/docs/connections/sources/#create-a-source).
2. Navigate to **Source Settings > API Keys** and copy the **Write Key**.

![Write Key in Segment UI](https://mintcdn.com/hightouch-3c037897/L_vQfA0JQEpeGUUo/images/destinations/destination-segment-write-key.png?fit=max\&auto=format\&n=L_vQfA0JQEpeGUUo\&q=85\&s=bed8981e613fb2b3b0bfb1d04f103b01)

## Sync configuration

Once you've set up your Segment destination and have a [model](https://docs.hightouch.com/getting-started/concepts.md#models) to pull data from, you can set up your sync configuration to begin syncing data. Go to the [**Syncs** overview page](https://app.hightouch.com/syncs?from=docs) and click the **Add sync** button to begin. Then, select the relevant model and the Segment destination you want to sync to.

### User and anonymous IDs

You need to include send either the user or anonymous ID to Segment to identify the user associated with the event.

### Field mapping

You can sync columns from your source into user (identify) or event (track) properties.

### Sending initial results (Track events only)

For the two track event types, Hightouch lets you choose whether to:

* Send the initial set of results as track events as Entered / Added events
* Or, only send the changes between the results in the subsequent syncs as track events

Checking the **Send events for initial result set** checkbox results in a large amount of events being sent in the first sync.

Hightouch always send the initial results set when sending Identify and Group events.

### Event names and timestamps (Generic track events only)

For the generic track mode, there are further settings that are needed to determine which event name Hightouch sends to Segment for each added, changed, and removed record.

![Setting event names in the Hightouch UI](https://mintcdn.com/hightouch-3c037897/L_vQfA0JQEpeGUUo/images/destinations/destination-segment-event-names.png?fit=max\&auto=format\&n=L_vQfA0JQEpeGUUo\&q=85\&s=0dfa654992bdeba06e7b778382c88b60)

In the preceding screenshot, Hightouch sends Segment:

* A "User Signed Up" event when a record is added to the query results
* A "User Changed Subscription" event when a record is changed in the query results
* A "User Deleted Account" event when a record is removed in the query results

Hightouch allows you to send a timestamp that the event occurred for generic track events. This is useful for backfilling historical events.

Hightouch also lets you to send a message ID for each record to ensure that the event is deduplicated within Segment in the case that the same event erroneously gets sent twice.

## Tips and troubleshooting

To see the exact API requests and responses from each sync run, use the [live debugger](https://docs.hightouch.com/syncs/debugger.md). To get notified by Slack, PagerDuty, SMS, or email when a sync fails, set up [sync alerts](https://docs.hightouch.com/syncs/alerting.md). If you run into an issue this page doesn't cover, [contact support](#pylon-chat).

## Common errors

### Large payload issues

Segment returns a `400 Bad Request` error if your batch payload exceeds the limitations. You can find more information in [Segment's documentation](https://segment.com/docs/connections/sources/catalog/libraries/server/http-api/#errors). Adjust your batch configuration accordingly.
