# \[FE\&R] Sending AB Tasty events to Segment

{% hint style="info" %}
Flagship Visitor ID & Segment.io User ID

For the user matching to be achieved (and allow Flagship to target your Segment traits) the User ID sent in the Segment .identify calls must be the same value than the Flagship Visitor ID sent to the decision API.

Refer to the Segment documentation on User ID [here](https://segment.com/docs/connections/spec/identify/#user-id).
{% endhint %}

This guide explains how to configure **AB Tasty server-side events** to be forwarded to **Segment (SegmentIO)**.

{% stepper %}
{% step %}

### Configure Segment

#### Retrieve the Segment API key

1. Log into your **Segment Dashboard**
2. Select the relevant **Source**
3. Navigate to:

```
Settings → API Keys
```

4. Copy the **Write Key**

You will use this key when configuring the connector in AB Tasty.
{% endstep %}

{% step %}

### Create the Segment Connector in AB Tasty

1. Go to the **Integration Hub** in AB Tasty
2. Create a new [**SegmentIO Connector (PUSH)**](#user-content-fn-1)[^1]
3. Paste the **Segment Write Key**
4. Save the connector

Once created, AB Tasty will be able to forward **server-side events to Segment**.
{% endstep %}

{% step %}

### Visitor ID requirement

For AB Tasty to send events to Segment, **the visitor ID must be known by Segment**.

This means the visitor must first be **identified or tracked by Segment** before AB Tasty sends events.

#### Identify the Visitor in Segment

Example:

```javascript
analytics.identify('YOUR_VISITOR_ID', {
  email: "user@example.com",
  name: "John Doe"
});
```

This ensures Segment associates events with the correct user.

#### Retrieve the Visitor ID from Segment

If Segment is already running on the website, you can retrieve the visitor identifier.

#### Anonymous ID

```javascript
window.analytics.user().anonymousId();
```

#### User ID (if identified)

```javascript
window.analytics.user().userId();
```

{% endstep %}

{% step %}

### Send the Visitor ID to AB Tasty

The **same visitor ID used in Segment must be used when calling the AB Tasty Decision API**.

Example:

```
visitorId = window.analytics.user().anonymousId()
```

Then pass it to the **Decision API** request.

If the visitor ID used by AB Tasty **does not match the one known by Segment**, the event **will not be forwarded to Segment**.
{% endstep %}

{% step %}

### Event Flow Overview

```
User → Segment identifies visitor
      ↓
Visitor ID retrieved from Segment
      ↓
Decision API called with same visitor ID
      ↓
AB Tasty generates server-side event
      ↓
Event sent to Segment via connector
```

{% endstep %}
{% endstepper %}

[^1]: <img src="/files/PWWOvEV6VmImx0cOv4XB" alt="" data-size="original">


---

# Agent Instructions: Querying This Documentation

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

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.abtasty.com/flagship-deprecated/integrations/fe-and-r-segment-integration/segment-integration.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
