# Checkout

> Tracks the two key steps of the checkout funnel using the CHECKOUT event.

Tracks the two key steps of the checkout funnel using the `CHECKOUT` event. Both requests share the same event name and differ in the `step` field.

**Requests:**
- **View Basket** — fires when a user views their cart before proceeding to checkout (`step: "view-basket"`). Includes the full `productList` array with `productId`, `price`, and `quantity`, plus `totalPrice`.
- **Purchase** — fires when an order is successfully completed (`step: "purchase"`). Includes `productList`, `totalPrice`, and a merchant `orderNo` for deduplication.

These events are critical for conversion tracking and revenue attribution in the Segmentify dashboard.

## View Basket

**Example body**

```json
{
  "name": "CHECKOUT",
  "userId": "1234567890123456789",
  "sessionId": "9876543210987654321",
  "testMode": "true",
  "device": "PC",
  "params": {},
  "recommendIds": [],
  "pageUrl": "",
  "referrer": "",
  "lang": "EN",
  "productList": [
    {
      "productId": "PRODUCT_ID",
      "price": "1222",
      "quantity": 1
    }
  ],
  "currency": "EUR",
  "step": "view-basket",
  "email": "user@example.com",
  "totalPrice": "1222",
  "basketId": "basket_1234567890123456789"
}
```

:::tip[Try it]
Send this request from the [Events API reference](/reference/events/): pick **Checkout / View Basket** in the request body examples of *Send events*.
:::


## Purchase

### Purpose

Sends a **Purchase** event (`name: "CHECKOUT"`, `step: "purchase"`) to Segmentify Events API. Use this event to report a completed checkout (order) together with customer/session context and purchased items.

---

### Endpoint

**POST** `https://{dataCenterUrl}.segmentify.com/add/events/v1.json?apiKey={apikey}`

> This request uses query param authentication via `apiKey`. 

---

### Required variables

These variables are referenced in the request URL / headers / body. Make sure they are defined in your active environment (or at collection/global level):

- `dataCenterUrl` (string) – datacenter subdomain/prefix (e.g., `eu`, `us`, etc.)

- `apikey` (string) – Segmentify API key

- `domain` (string) – value for the `origin` header (your site domain)

- `userId` (string) – your user identifier

- `sessionId` (string) – session identifier

- `deviceType` (string) – device type (e.g., `desktop`, `mobile`, `tablet`)

- `lang` (string) – language code (e.g., `en`, `tr`)

- `productId` (string) – product identifier used inside `productList[]`

- `currency` (string) – currency code (e.g., `USD`, `EUR`, `TRY`)

- `region` (string) – region/country code (e.g., `TR`)

- `email` (string) – customer email

---

### Headers

- `origin: {domain}`

---

### Body (JSON)

Content type is **raw JSON**.

#### Top-level schema

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `name` | string | yes | Event name. For this request it is `CHECKOUT`. |
| `userId` | string | yes | User identifier. |
| `sessionId` | string | yes | Session identifier. |
| `testMode` | string/boolean | recommended | When enabled, the event may be treated as test traffic. **Note:** this request currently sends it as a string (`"false"`). |
| `device` | string | recommended | Device type (from `{deviceType}`). |
| `params` | object | optional | Additional custom parameters. |
| `recommendIds` | array | optional | Recommendation IDs associated with the conversion (if any). |
| `pageUrl` | string | optional | Page URL where purchase occurred. |
| `referrer` | string | optional | Referrer URL. |
| `lang` | string | recommended | Language code. |
| `productList` | array | yes | Purchased items list. See schema below. |
| `currency` | string | yes | Currency code for the order. |
| `region` | string | recommended | Region/country. |
| `step` | string | yes | Checkout step. For purchase it is `purchase`. |
| `orderNo` | string | yes | Merchant order number. |
| `email` | string | recommended | Customer email. |
| `totalPrice` | string/number | yes | Total order price. **Note:** this request currently sends it as a string. |

#### `productList[]` item schema

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `productId` | string | yes | Purchased product identifier. |
| `price` | string/number | yes | Unit price. **Note:** this request currently sends it as a string. |
| `quantity` | number | yes | Quantity purchased. |

---

### Example payload

```json
{
  "name": "CHECKOUT",
  "userId": "{userId}",
  "sessionId": "{sessionId}",
  "testMode": "false",
  "device": "{deviceType}",
  "params": {},
  "recommendIds": [],
  "pageUrl": "",
  "referrer": "",
  "lang": "{lang}",
  "productList": [
    {
      "productId": "{productId}",
      "price": "1222",
      "quantity": 1
    }
  ],
  "currency": "{currency}",
  "region": "{region}",
  "step": "purchase",
  "orderNo": "TS232323",
  "email": "{email}",
  "totalPrice": "1222"
}

 ```

---

### Success / error expectations

Because implementations may vary by account/setup, validate based on your Segmentify Events API behavior:

#### Success

- HTTP status commonly **200** or **2xx**

- Response body typically includes an acknowledgement that the event is accepted/processed

#### Error

- **4xx**: invalid/missing `apiKey`, invalid payload, missing required fields

- **5xx**: server-side error

Recommended validation:

- Ensure the response is JSON (if applicable)

- Confirm the event appears in your dashboard/logs according to your tracking setup

---

### Notes

- **Idempotency:** If you might retry requests, consider keeping `orderNo` stable per order to avoid duplicate purchases (behavior depends on backend deduplication rules).

- **`testMode`****:** This request sends `testMode` as a string. If your backend expects a boolean, you may want to align types in your implementation.

- **Money fields:** `price` and `totalPrice` are currently strings. If numeric values are required, ensure type consistency.

- **Currency/region:** Use standard ISO codes where possible (e.g., `TRY`, `USD`; `TR`, `US`).

- **Optional URLs:** Set `pageUrl` and `referrer` when available to improve analytics attribution.

**Example body**

```json
{
  "name": "CHECKOUT",
  "userId": "1234567890123456789",
  "sessionId": "9876543210987654321",
  "testMode": "false",
  "device": "PC",
  "params": {},
  "recommendIds": [],
  "lang": "EN",
  "productList": [
    {
      "productId": "PRODUCT_ID",
      "price": "1222",
      "quantity": 1
    }
  ],
  "currency": "EUR",
  "step": "purchase",
  "orderNo": "TS232323",
  "email": "user@example.com",
  "totalPrice": "1222"
}
```

:::tip[Try it]
Send this request from the [Events API reference](/reference/events/): pick **Checkout / Purchase** in the request body examples of *Send events*.
:::
