> For the complete documentation index, see [llms.txt](https://docs.stackai.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.stackai.com/integrations/catalog/segment.md).

# Segment

Segment is a customer data platform. Identify users, send track events, bulk-import historical events, and manage workspace sources and destinations from your AI workflows.

## Connectors

Choose the connector that matches your authentication method. The options below use the names shown in StackAI.

| Connector                  | Authentication   |
| -------------------------- | ---------------- |
| Segment (Write Key)        | Source Write Key |
| Segment (Public API Token) | Public API Token |

### Segment (Write Key)

Send identify, track, and batch events to a Segment source.

#### Set up in Segment

1. Prepare the Segment account or service that the workflow will access. Grant access to the required resources and operations.
2. **Source Write Key:** The write key of the Segment source that should receive events (Connections -> Sources -> your HTTP API source -> Settings -> API Keys). Segment accepts events sent with a wrong key or region without an error and then drops them, so copy the key exactly.

#### Set up in StackAI

1. Open **Settings → Connections**, add a connection, and select **Segment (Write Key)**.
2. Enter the credentials and connection details in the fields below.
3. Save the connection and check its connection status. Select this saved connection when configuring an action or feature that uses it.

**Connection fields**

| StackAI field    | Required                 | What to enter                                                                                                                                                                                                                                                                                                                                |
| ---------------- | ------------------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Source Write Key | Yes                      | The write key of the Segment source that should receive events (Connections -> Sources -> your HTTP API source -> Settings -> API Keys). Segment accepts events sent with a wrong key or region without an error and then drops them, so copy the key exactly. [Provider instructions](https://segment.com/docs/connections/find-writekey/). |
| Region           | Optional / as applicable | Your Segment workspace region: 'us' (default) or 'eu'. The connection check cannot catch a wrong region: Segment accepts those events and drops them.                                                                                                                                                                                        |

### Segment (Public API Token)

Manage Segment sources and destinations in your workspace.

#### Set up in Segment

1. Prepare the Segment account or service that the workflow will access. Grant access to the required resources and operations.
2. **Public API Token:** A Segment Public API token (Settings -> Workspace settings -> Access Management -> Tokens -> Create token -> Public API). Its role decides which sources and destinations it can read and create.

#### Set up in StackAI

1. Open **Settings → Connections**, add a connection, and select **Segment (Public API Token)**.
2. Enter the credentials and connection details in the fields below.
3. Save the connection and check its connection status. Select this saved connection when configuring an action or feature that uses it.

**Connection fields**

| StackAI field    | Required                 | What to enter                                                                                                                                                                                                                                                                 |
| ---------------- | ------------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Public API Token | Yes                      | A Segment Public API token (Settings -> Workspace settings -> Access Management -> Tokens -> Create token -> Public API). Its role decides which sources and destinations it can read and create. [Provider instructions](https://docs.segmentapis.com/tag/Getting-Started/). |
| Region           | Optional / as applicable | Your Segment workspace region: 'us' (default) or 'eu'.                                                                                                                                                                                                                        |

### Verify the connection

Check that the connection is healthy. Then run a read operation against a resource the connected account can access. A successful connection check confirms authentication; it does not guarantee permission for every action.

If access is denied, check the credential or OAuth permissions, the selected account or environment, and access to the specific resource. Update expired credentials or reconnect after permissions change.

## Use an action

1. Add the required **Segment** action to the workflow.
2. Select a connection when the action requests one.
3. Complete the required fields. Use the reference picker when a value comes from another workflow step.
4. Run the workflow and inspect the action’s output. Check the result before using it in a later step.

## Actions

### Identify User

Record who a user is and their traits in Segment.

#### Inputs

| Field               | Type     | Required | Description                                                                                                                               |
| ------------------- | -------- | -------- | ----------------------------------------------------------------------------------------------------------------------------------------- |
| User ID             | string   | No       | Your own ID for the user. Provide this, an anonymous ID, or both.                                                                         |
| Anonymous ID        | string   | No       | A temporary ID for a user you cannot identify yet.                                                                                        |
| Timestamp           | datetime | No       | When it happened. Leave empty for now; set it to import historical data.                                                                  |
| Context             | object   | No       | Extra context such as ip, locale, or page.                                                                                                |
| Destinations Filter | object   | No       | Turn specific destinations on or off for this message.                                                                                    |
| Message ID          | string   | No       | Unique ID Segment uses to drop duplicates. Generated if empty. Set it so a failed run can be retried without recording the message twice. |
| Traits              | object   | No       | What you know about the user, such as email, name, or plan.                                                                               |

#### Outputs

| Field      | Type    | Description                                             |
| ---------- | ------- | ------------------------------------------------------- |
| Accepted   | boolean | Segment accepted the message for processing.            |
| Message ID | string  | The message ID, for finding it in the Segment debugger. |

### Send Track Event

Record an action a user performed in Segment.

#### Inputs

| Field               | Type     | Required | Description                                                                                                                               |
| ------------------- | -------- | -------- | ----------------------------------------------------------------------------------------------------------------------------------------- |
| User ID             | string   | No       | Your own ID for the user. Provide this, an anonymous ID, or both.                                                                         |
| Anonymous ID        | string   | No       | A temporary ID for a user you cannot identify yet.                                                                                        |
| Timestamp           | datetime | No       | When it happened. Leave empty for now; set it to import historical data.                                                                  |
| Context             | object   | No       | Extra context such as ip, locale, or page.                                                                                                |
| Destinations Filter | object   | No       | Turn specific destinations on or off for this message.                                                                                    |
| Message ID          | string   | No       | Unique ID Segment uses to drop duplicates. Generated if empty. Set it so a failed run can be retried without recording the message twice. |
| Event Name          | string   | Yes      | The action the user performed, such as 'Order Completed'.                                                                                 |
| Properties          | object   | No       | Details about the event, such as revenue or product name.                                                                                 |

#### Outputs

| Field      | Type    | Description                                             |
| ---------- | ------- | ------------------------------------------------------- |
| Accepted   | boolean | Segment accepted the message for processing.            |
| Message ID | string  | The message ID, for finding it in the Segment debugger. |

### Batch Import Events

Send up to 2500 identify, track, page, screen, or group calls at once.

#### Inputs

| Field               | Type          | Required | Description                                                                                                  |
| ------------------- | ------------- | -------- | ------------------------------------------------------------------------------------------------------------ |
| Events              | object\_array | Yes      | Up to 2500 identify, track, page, screen, or group calls. Set a timestamp on each to import historical data. |
| Shared Context      | object        | No       | Context merged into every event, such as device or library.                                                  |
| Destinations Filter | object        | No       | Turn specific destinations on or off for every event.                                                        |

#### Outputs

| Field       | Type          | Description                                   |
| ----------- | ------------- | --------------------------------------------- |
| Accepted    | boolean       | Segment accepted the batch for processing.    |
| Event Count | integer       | How many events were sent.                    |
| Message IDs | string\_array | The message ID of each event, in input order. |

### List Sources

List the sources in your Segment workspace.

#### Inputs

| Field | Type    | Required | Description                                        |
| ----- | ------- | -------- | -------------------------------------------------- |
| Limit | integer | No       | Maximum sources to return (default 100, max 1000). |

#### Outputs

| Field         | Type        | Description                                              |
| ------------- | ----------- | -------------------------------------------------------- |
| Sources       | dict\_array | The workspace's sources.                                 |
| Total Entries | integer     | Total sources in the workspace, when Segment reports it. |
| Has More      | boolean     | True if more sources exist beyond the returned set.      |

### Create Destination

Connect a new destination to one of your Segment sources.

#### Inputs

| Field            | Type            | Required | Description                                                                                                  |
| ---------------- | --------------- | -------- | ------------------------------------------------------------------------------------------------------------ |
| Source           | select (string) | Yes      | The source whose data the destination receives. Options load from the selected connection.                   |
| Destination Type | select (string) | Yes      | The kind of destination to create, such as Amplitude or Webhooks. Options load from the selected connection. |
| Settings         | secret          | Yes      | The destination's settings, such as its API key. Use {} if it needs none.                                    |
| Name             | string          | No       | Display name for the destination in Segment.                                                                 |
| Enabled          | boolean         | No       | Start sending data right away. Off by default so you can check settings first. Default: false.               |

#### Outputs

| Field               | Type    | Description                                      |
| ------------------- | ------- | ------------------------------------------------ |
| Destination ID      | string  | ID of the created destination.                   |
| Name                | string  | Display name of the destination.                 |
| Enabled             | boolean | Whether the destination is receiving data.       |
| Source ID           | string  | The source the destination is connected to.      |
| Destination Type ID | string  | Catalog ID of the destination type.              |
| Destination Type    | string  | Name of the destination type, such as Amplitude. |

## Important behavior

Actions that create, update, send, or delete data can change the connected service. Review their inputs before running them. A retry can repeat an operation; consider this when configuring retries for actions that change data.

The catalog lists the fields and capabilities available in the supplied provider definition. Availability can also depend on your deployment and organization’s Feature Access settings.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.stackai.com/integrations/catalog/segment.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
