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
Section titled “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
Section titled “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
Section titled “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:
curl "https://{dataCenter}.segmentify.com/get/key?count=2"["-428194869725151232", "-428194869725151231"]Use the first as userId and the second as sessionId.
- Store
userIdfor as long as you can (a long-lived cookie, app storage). It is how Segmentify recognises a returning visitor. - Create a new
sessionIdfor each visit: call/get/key?count=1when 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.
Step 2: Send your first event
Section titled “Step 2: Send your first event”Send a home page view in test mode:
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.
Originmust contain your registered domain. Without it the request is rejected withNO_DOMAIN_APIKEY_MATCH.- Send
langevery time. When it is missing,ENis assumed, and ifENis not a language of your account the request is rejected withUNDEFINED_LANGUAGE.
Step 3: Read the response
Section titled “Step 3: Read the response”The API answers HTTP 200 for every request. Whether it worked is in statusCode:
{ "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.
Always check statusCode. A 200 status alone does not mean the event was stored.
Step 4: Add the events of each page
Section titled “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 |
| A product page loads | PRODUCT_VIEW (in addition to PAGE_VIEW) |
Product View |
| Basket changes | BASKET_OPERATIONS with step add, remove or clear |
Basket Operations |
| Basket page loads | CHECKOUT with step: "view-basket" |
Checkout |
| Order is completed | CHECKOUT with step: "purchase" |
Checkout |
| User signs in or registers | CDP user events | CDP User Events |
| A recommendation widget is shown or clicked | INTERACTION |
Widget Interaction |
| User searches | SEARCH |
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.
Step 5: Go live
Section titled “Step 5: Go live”- Remove
testMode(or sendfalse). Test events are kept apart from live traffic. - Check that
PRODUCT_VIEWsends real prices and stock, in the currency named bycurrency. - Check that
purchaseis sent exactly once per order, with a stableorderNo. - Send the visitor’s real
userAgentwhen you call from a backend. Requests that look like bots are rejected withBOT. - Handle a non-
SUCCESSstatus in your code: log it, do not retry in a loop.
Common first-time mistakes
Section titled “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. |
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 page.