# Your first integration

> A step-by-step path from zero to a working Events API integration, for developers implementing Segmentify for the first time.

This page takes you from nothing to a working integration. It assumes you are calling the Events API yourself, from a backend or an app. If you use a Segmentify SDK, the SDK does all of this for you.

## How it works

Segmentify learns from what visitors do. Your side reports each action (a page viewed, a product added to the basket, an order placed) as an **event**. Every event goes to the same endpoint, and the `name` field says what kind of event it is.

The response to an event can carry content to show: product recommendations, popups, search results. So the Events API is both how you send data and how you receive campaigns.

## Before you start

Have these four things ready. The API key and data center are under **Settings > Integrations** in the Segmentify panel; the domain, languages and currencies are part of your account settings.

| You need | Why |
| --- | --- |
| API key | Identifies your account. Sent as the `apiKey` query parameter. |
| Data center | The host your account lives on, for example `per2` or `gandalf-eu`. A key sent to another data center is not found. |
| Registered domain | Every request must carry your domain in the `Origin` header (or `Referer`). |
| Languages and currencies | `lang` and `currency` in an event must be ones configured for your account. |

## Step 1: Get a user ID and a session ID

Every event must carry a `userId` and a `sessionId`. Ask the API for two keys:

```bash
curl "https://{dataCenter}.segmentify.com/get/key?count=2"
```

```json
["-428194869725151232", "-428194869725151231"]
```

Use the first as `userId` and the second as `sessionId`.

- Store `userId` for as long as you can (a long-lived cookie, app storage). It is how Segmentify recognises a returning visitor.
- Create a new `sessionId` for each visit: call `/get/key?count=1` when a known visitor comes back.

You can also use your own IDs. Any string works if it is unique per user and per session. See [Session Management](/events/session-management/).

## Step 2: Send your first event

Send a home page view in test mode:

```bash
curl -X POST "https://{dataCenter}.segmentify.com/add/events/v1.json?apiKey={apiKey}" \
  -H "Content-Type: application/json" \
  -H "Origin: https://www.yourdomain.com" \
  -d '[{
    "name": "PAGE_VIEW",
    "userId": "-428194869725151232",
    "sessionId": "-428194869725151231",
    "category": "Home Page",
    "lang": "EN",
    "currency": "EUR",
    "device": "PC",
    "testMode": true
  }]'
```

Three things to get right:

- **The body is a JSON array**, even for one event. A single object is accepted too, but an array lets you batch.
- **`Origin` must contain your registered domain.** Without it the request is rejected with `NO_DOMAIN_APIKEY_MATCH`.
- **Send `lang` every time.** When it is missing, `EN` is assumed, and if `EN` is not a language of your account the request is rejected with `UNDEFINED_LANGUAGE`.

## Step 3: Read the response

The API answers HTTP 200 for every request. Whether it worked is in `statusCode`:

```json
{ "statusCode": "SUCCESS", "timestamp": 1757491200000, "responses": [[]], "campaigns": [[]] }
```

Anything other than `SUCCESS` names the reason. For example `{"statusCode": "NO_USERID"}` means an event had no `userId`. Every code is explained in [Responses and errors](/events/responses-and-errors/).

Always check `statusCode`. A 200 status alone does not mean the event was stored.

## Step 4: Add the events of each page

A typical shop needs the events below. Start from the top; each row makes more of Segmentify work.

| When | Event | Guide |
| --- | --- | --- |
| Any page loads | `PAGE_VIEW` with the page's `category` | [Page View](/events/page-view/) |
| A product page loads | `PRODUCT_VIEW` (in addition to `PAGE_VIEW`) | [Product View](/events/product-view/) |
| Basket changes | `BASKET_OPERATIONS` with `step` `add`, `remove` or `clear` | [Basket Operations](/events/basket-operations/) |
| Basket page loads | `CHECKOUT` with `step: "view-basket"` | [Checkout](/events/checkout/) |
| Order is completed | `CHECKOUT` with `step: "purchase"` | [Checkout](/events/checkout/) |
| User signs in or registers | CDP user events | [CDP User Events](/events/cdp-user-events/) |
| A recommendation widget is shown or clicked | `INTERACTION` | [Widget Interaction](/events/widget-interaction/) |
| User searches | `SEARCH` | [Search](/events/search/) |

Send `PAGE_VIEW` and `PRODUCT_VIEW` together in one array on a product page: one request, two events.

The exact fields and types of each event are in [Event fields and types](/events/event-fields/).

## Step 5: Go live

- Remove `testMode` (or send `false`). Test events are kept apart from live traffic.
- Check that `PRODUCT_VIEW` sends real prices and stock, in the currency named by `currency`.
- Check that `purchase` is sent exactly once per order, with a stable `orderNo`.
- Send the visitor's real `userAgent` when you call from a backend. Requests that look like bots are rejected with `BOT`.
- Handle a non-`SUCCESS` status in your code: log it, do not retry in a loop.

## Common first-time mistakes

| Symptom | Cause |
| --- | --- |
| `NO_DOMAIN_APIKEY_MATCH` | The `Origin` header is missing or is not your registered domain. Calls from a backend do not add it by themselves. |
| `NO_EVENT` | The body is not valid JSON, or a field holds a value that is not allowed, for example a `step` that does not exist. |
| `UNDEFINED_LANGUAGE` | `lang` is missing or is not configured for the account. |
| `INVALID_EVENT` | A value is out of range, or a required field of that event is missing. See the rules in [Event fields and types](/events/event-fields/). |
| `SUCCESS` but nothing changes | A field name is misspelled. Unknown fields are ignored without an error, so compare your names with the reference, letter by letter. |
| Events of one visitor look like many visitors | `userId` is not stored and a new one is created on every page. |

More checks are on the [Debugging](/debugging/) page.
