API reference
Events and revenue attribution
Send page events from your storefront, and orders from your server.
On this page
Ottla’s widget reports its own events for you. Any other custom front end should report what shoppers do with what Ottla shows them to /track (product views, clicks, adds to basket and the chat opening), and send orders to /attribution/ingest from your server. This lets the console show the orders placed after shoppers used each Ottla feature, and the order lines added to the basket from it.
Amounts are shown separately for each currency and never added across currencies. They show which features shoppers used before an order; they do not imply that a feature was responsible for it. To measure the direct effect of a personalised recommendation row or the basket line, run an experiment (see Growth and above). There is no way to hold the chat back from some shoppers.
On a Magento or Adobe Commerce store, our module does all of this for you, including orders, each line’s value and the feature it was added from. So this page only applies to a headless or other custom storefront.
Report a storefront event
Reports what a shopper does with what Ottla shows. Scope feedback:write, so your Storefront widget key works. Rate limit group track: 600 a minute per key. Like feedback, events keep flowing while a payment is overdue.
- Key
Authorization: Bearerwith thefeedback:writescope- Origin
- One of the key’s allowed origins
- Call from
- The browser or your server
- Rate limit
trackgroup, 600 a minute- Retries
- Safe with
Idempotency-Key
Headers and parameters
| Field | Description |
|---|---|
Origin
|
Your storefront’s address, which must be one of the key’s allowed origins. Browsers send it themselves; a server must send it too. |
Idempotency-Key
|
Makes a retry safe: the same key, path and body within 24 hours returns the first response again. A key is shared by every API key and store in the workspace, so it must be unique to each request (a random id, not a row number from one store’s database): reusing the key with a different body is refused with 409. Servers only. |
X-Ottla-Client-Ip
|
The shopper’s public IP address, when your server calls on a shopper’s behalf, so each shopper has their own allowance. Read only for a key marked “Used by a store connector or another server” in the console, which also needs allowed IP addresses; ignored for any other key. |
X-Ottla-Request-Id
|
Your own id for this request, returned in the response header. Ottla creates one when you send none. Servers only. |
Responses
-
202 Accepted
Accepted: the event will be recorded shortly.
statusisignoredwhen it came from a member of the store’s team shopping as a customer. -
401 Unauthorised
No API key was sent (
unauthenticated), or the key is unknown, revoked or expired (invalid_api_key). -
403 Forbidden
The key cannot be used for this request:
forbidden_scope,ip_not_allowedortenant_suspendedas for any key, or theOrigincheck failed:origin_not_configured,origin_required,origin_invalidororigin_not_allowed. -
409 Conflict
The
Idempotency-Keywas used before with a different body (idempotency_key_reused), or a request with it is still running (idempotency_in_flight). -
422 Invalid
The request is not valid (
validation_failed), oreventis not one of the accepted events (unsupported_event). -
429 Rate limited
A rate limit was reached: this key’s limit for the operation’s group (
rate_limited), the workspace’s limit across all its keys (tenant_rate_limited), the limit for one network address (ip_rate_limited) or for one shopper (shopper_rate_limited). Waitretry_afterseconds.
You should send these events from your custom front end:
| Event | Send it when | Worth adding |
|---|---|---|
product.viewed | A product page is viewed. | sku, external_id, page_type |
product.clicked | A shopper clicks a product Ottla showed: in an answer, a row or search. | answer_id, position, surface, session_id, vid, link |
product.add_to_cart | A shopper adds a product Ottla showed to their basket. | sku, answer_id, surface, session_id, vid, link |
suggestion.clicked | A shopper taps a starter question or a follow-up. | session_id, surface |
widget.opened | Your chat opens. | session_id, surface |
order_placed | An order is placed in a session where the shopper used Ottla. | order_id, total, currency, line_skus, session_id |
purchase is read as order_placed. The other names Ottla accepts are sent by its own widget, and anything else gets 422 unsupported_event. The first widget.opened also ticks Place the advisor on your store in the console’s getting started checklist.
| Field | Description |
|---|---|
event
|
The event name, from the table above. |
answer_id
|
The answer the event relates to, from POST /ask. |
session_id
|
The conversation’s session_id, up to 128 characters. |
sku
|
The product’s SKU. |
external_id
|
Your platform’s product id, up to 64 characters. |
external_ids
|
Several product ids, up to 50. |
position
|
The product’s position in what was shown, counting from 0, up to 100. |
surface
|
Where on your storefront it happened, up to 100 characters, such as chat or pdp_row. |
vid
|
The shopper’s visitor id: the value of their ottla_vid cookie, up to 128 characters. Send it only with link: true, and only when the shopper’s current privacy mode allows it: after a yes, or on a store outside the UK and the EU until the shopper says no. |
link
|
Set to true to let Ottla link this click, add to basket or tap on an Ottla block, row or search to a later order. Without it, vid is ignored. |
privacy
|
The shopper’s current privacy mode, as {mode}: c (consent), k (counts), o (off) or n (notice). Only in consent and notice does Ottla keep a visitor id or account link. In counts it keeps the event alone, with no identifier; in off it keeps nothing. |
page_type
|
The kind of page, up to 32 characters. |
order_id
|
For order_placed: your order number, up to 128 characters. |
total
|
For order_placed: the order total. |
currency
|
The currency, such as GBP. |
line_skus
|
For order_placed: the SKUs ordered, up to 200. |
website_id
|
Ottla’s id for the website. Ignored for a key bound to one website. |
scope_ref
|
Your code for the market or language, such as uk. |
curl https://ottla.ai/api/v1/track \
-H "Authorization: Bearer YOUR_BROWSER_KEY" \
-H "Origin: https://shop.example" \
-H "Content-Type: application/json" \
-d '{"event": "product.viewed", "sku": "TENT-2P", "external_id": "1187", "page_type": "pdp"}'
<?php
use GuzzleHttp\Client;
$client = new Client(['base_uri' => 'https://ottla.ai/api/v1/']);
$client->post('track', [
'headers' => [
'Authorization' => 'Bearer YOUR_BROWSER_KEY',
'Origin' => 'https://shop.example',
],
'json' => [
'event' => 'order_placed',
'session_id' => 'sess_8f2c1',
'order_id' => '100004521',
'total' => 174.00,
'currency' => 'GBP',
'line_skus' => ['TENT-2P', 'MAT-SELF'],
],
]);
An accepted event answers 202 with status: "queued". If it came from a member of the store’s team shopping as a customer, status is ignored and it isn’t counted. Send vid, set to the shopper’s visitor id (the ottla_vid cookie), and link: true with a click, an add or a tap to link it to a later order, only when the shopper’s privacy mode allows it: after a yes, or, on a store outside the UK and the EU, until the shopper says no. Never send them after a no, and delete the cookie then. Send privacy with the shopper’s current privacy mode on every event. Ottla ignores vid without link. You don’t need them on chat events: Ottla links the chat to an order through its session. The console then shows the orders placed within 7 days after a shopper used each feature.
Report an order from your server
Lets your back end send Ottla an order, or an add to basket, so Ottla can report which of its features shoppers used before the order. Use a key only your server holds: a Storefront widget key (it has ask:read) marked Used by a store connector or another server and limited to your servers’ IP addresses. The key in your web pages is refused with 403 server_key_required, because anyone can read it. There’s no Origin check, because the call comes from your server. Rate limit group attribution: 600 a minute per key.
- Key
Authorization: Bearerwith theask:readscope- Call from
- Your server only
- Rate limit
attributiongroup, 600 a minute- Retries
- Safe with
Idempotency-Key
Headers and parameters
| Field | Description |
|---|---|
Idempotency-Key
|
Makes a retry safe: the same key, path and body within 24 hours returns the first response again. A key is shared by every API key and store in the workspace, so it must be unique to each request (a random id, not a row number from one store’s database): reusing the key with a different body is refused with 409. Servers only. |
X-Ottla-Request-Id
|
Your own id for this request, returned in the response header. Ottla creates one when you send none. Servers only. |
Responses
-
202 Accepted
Accepted: the event will be recorded shortly.
-
204 No content
Revenue measurement is not on the plan, so nothing is recorded.
-
401 Unauthorised
No API key was sent (
unauthenticated), or the key is unknown, revoked or expired (invalid_api_key). -
402 Payment required
Billing needs attention.
plan_limit_exceeded: the plan’s allowance and any credits are used up (the body addsmetric,usedandlimit).account_past_due: a payment is overdue, or a trial ended without a plan.account_suspended: the account is suspended. Stop sending until the workspace owner resolves it atupgrade_url. -
403 Forbidden
The key cannot be used for this request: it lacks the scope (
forbidden_scope), it is limited to other IP addresses (ip_not_allowed), the workspace is not active (tenant_suspended), or it is a key a web page may hold (server_key_required): orders are accepted only with a key limited to your servers’ IP addresses. -
409 Conflict
The
Idempotency-Keywas used before with a different body (idempotency_key_reused), or a request with it is still running (idempotency_in_flight). -
422 Invalid
The request is not valid (
validation_failed, witherrorskeyed by field), or theIdempotency-Keyheader is malformed (invalid_idempotency_key). -
429 Rate limited
A rate limit was reached: this key’s limit for the operation’s group (
rate_limited), the workspace’s limit across all its keys (tenant_rate_limited), the limit for one network address (ip_rate_limited) or for one shopper (shopper_rate_limited). Waitretry_afterseconds.
| Field | Description |
|---|---|
event_type
|
order_placed or add_to_cart. |
order_id
|
Your order number, up to 128 characters. Required for order_placed: each order is counted once. |
value
|
The order or line value, such as 174.00. |
currency
|
The ISO 4217 code, three letters. Default GBP. |
line_items
|
Up to 1,000 lines, each with sku (required), qty and row_total, and optionally value (what the shopper paid for the line, with tax and after line discounts) and features: the Ottla features the line was added to the basket from, each as {surface, at, basis}, with at in ISO 8601 format (UTC) and basis the shopper’s privacy mode when the feature was recorded against that line (c for consent or n for notice). Send features, an empty list for none, only when you record them and the shopper’s privacy mode allowed marks for the whole basket; otherwise leave it out, and Ottla shows “added from” as not measured. |
session_id
|
The chat’s session_id, when the shopper used the assistant. |
visitor_id
|
The shopper’s visitor id (the value of their ottla_vid cookie), only when the shopper’s privacy mode allows it. Never send it after a no. |
privacy
|
The shopper’s privacy at the time of the order, as {mode, rules, refused, account_link, account_basis, chat_consent, signal}. mode is c (consent), k (counts), o (off) or n (notice); refused is true if the shopper said no; account_link says whether a signed-in customer’s chats can be linked to the order through their customer account. If the mode is anything other than c or n, Ottla ignores visitor_id and the chat session ids; it ignores customer_ref unless account_link is true, and every line’s features if refused is true. |
occurred_at
|
When it happened, in ISO 8601. Defaults to now. |
website_id
|
Ottla’s id for the website. Ignored for a key bound to one website. |
Example: sending an order from your order confirmation job
// Run this from the job or webhook that handles a new order (Node 18 or later).
// Generate the key once per order report, and pass the same key when your job retries.
import { randomUUID } from 'node:crypto';
export async function reportOrder(order, idempotencyKey = randomUUID()) {
const res = await fetch('https://ottla.ai/api/v1/attribution/ingest', {
method: 'POST',
headers: {
'Authorization': 'Bearer YOUR_SERVER_STOREFRONT_KEY',
'Content-Type': 'application/json',
'Idempotency-Key': idempotencyKey,
},
body: JSON.stringify({
event_type: 'order_placed',
order_id: order.number,
value: order.grandTotal,
currency: order.currency,
// value: what the shopper paid for the line, with tax and after line discounts.
// features: the Ottla features the line was added from, if your basket records them.
line_items: order.lines.map((l) => ({ sku: l.sku, qty: l.qty, row_total: l.rowTotal, value: l.paid, features: l.ottlaFeatures })),
session_id: order.ottlaSessionId ?? undefined,
// Only when the shopper's privacy mode allows it (c consent or n notice), never after a no.
visitor_id: ['c', 'n'].includes(order.privacyMode) ? order.ottlaVid : undefined,
privacy: { mode: order.privacyMode, refused: order.privacyRefused },
occurred_at: order.placedAt,
}),
});
if (res.status === 204) return; // revenue measurement is not on this workspace's plan
if (!res.ok) throw new Error(`Ottla answered ${res.status}`);
}
<?php
use GuzzleHttp\Client;
$client = new Client(['base_uri' => 'https://ottla.ai/api/v1/']);
$idempotencyKey = $idempotencyKey ?? bin2hex(random_bytes(16)); // keep it for retries of this call
$client->post('attribution/ingest', [
'headers' => [
'Authorization' => 'Bearer YOUR_SERVER_STOREFRONT_KEY',
'Idempotency-Key' => $idempotencyKey,
],
'json' => [
'event_type' => 'order_placed',
'order_id' => $order['number'],
'value' => $order['grand_total'],
'currency' => 'GBP',
'line_items' => array_map(fn ($l) => [
'sku' => $l['sku'],
'qty' => $l['qty'],
'row_total' => $l['row_total'],
'value' => $l['paid'],
], $order['lines']),
'session_id' => $order['ottla_session_id'] ?? null,
'occurred_at' => $order['placed_at'],
],
]);
curl https://ottla.ai/api/v1/attribution/ingest \
-H "Authorization: Bearer YOUR_SERVER_STOREFRONT_KEY" \
-H "Idempotency-Key: 7c2e9f40-1d3b-4a8e-b6f1-0a9d2c4e8b13" \
-H "Content-Type: application/json" \
-d '{"event_type": "order_placed", "order_id": "100004521", "value": 174.00, "currency": "GBP", "line_items": [{"sku": "TENT-2P", "qty": 1, "row_total": 129.00, "value": 129.00, "features": [{"surface": "search", "at": "2026-10-21T10:31:00Z"}]}, {"sku": "MAT-SELF", "qty": 1, "row_total": 45.00, "value": 45.00, "features": []}], "session_id": "sess_8f2c1", "occurred_at": "2026-10-21T10:42:00Z"}'
An accepted order answers 202 with status: "queued", an ack_id and a request_id. You get 204 with an empty body when revenue measurement isn’t on the workspace’s plan. Send the same order twice and it’s still counted once, so retrying is always safe.
Which figures each feeds
| You send | It feeds |
|---|---|
| /track clicks, adds, suggestion taps and chat opens | Engagement with each feature in Insights → Analytics, including chats started, recommendation clicks and adds to basket, and how shoppers used each feature. With vid and link, also which features shoppers used prior to an order. |
| /track order_placed | Holdout experiments. |
| /attribution/ingest | Orders following use of each Ottla feature, plus AI chat details, in Insights → Analytics. |
| /search/events | The search funnel and zero-result searches in Insights → Sales and search. |
Errors
| Status | Code | What to do |
|---|---|---|
| 401 | unauthenticated, invalid_api_key | Send a valid key. |
| 402 | account_past_due, account_suspended | Only on /attribution/ingest. Keep the orders and resend them once billing is resolved. |
| 403 | forbidden_scope, server_key_required, the origin_* codes | /track needs feedback:write and an allowed Origin; /attribution/ingest needs ask:read on a key limited to your servers’ IP addresses. |
| 409 | idempotency_key_reused, idempotency_in_flight | See Idempotency. |
| 422 | validation_failed, unsupported_event | Fix the fields in errors, or use an event name from the table above. |
| 429 | rate_limited and the other limit codes | Wait retry_after seconds. One call per event or order sits comfortably inside these limits. |
FAQ
Questions developers ask
Which key sends orders from my server?
A Storefront widget key that only your server holds. Create one under Storefront → API keys, turn on Used by a store connector or another server and list your servers’ IP addresses. It has ask:read, which /attribution/ingest needs, and this endpoint doesn’t check Origin. The key in your web pages is refused, because anyone can read it.
Will an order be counted twice if I resend it?
No. Orders are only counted once no matter how many times you send them. So you can safely resend if you receive a timeout.
Why did I get a 204?
Revenue measurement isn’t on your workspace’s plan, so nothing has been recorded.
Does this prove the assistant caused the sale?
No, and we don’t claim it does. These figures show which features shoppers used before an order. We can’t run a holdout for the chat, but experiments (Growth and above) let you measure the effect of a personalised recommendation row on its own.
Related
Feedback
Ratings on answers, sent with the same key.
JavaScript events and consent
Learn how our widget sends events and how we handle consent.
Analytics
See what data these events populate in your console.
Measuring AI assistant results
A guide to reading order figures honestly.
Headless storefronts
Where events fit in a custom front end.