Custom events API
Send your own events to ab.one, from the storefront or your server, and count them per test version.
Custom events count actions ab.one doesn't track on its own, such as a newsletter sign-up or a finished quiz, per test version. First define the event on the test, as described in Custom events. This page is the reference for sending it.
Endpoint
POST https://app.ab.one/api/v1/events
Content-Type: application/json
The address and the store's public key are on the test's Settings tab, under Custom events (Ingest URL and Public key). How it works shows a ready-made request for the test.
Send one event per request. There's no batch form for custom events.
Body
{
"key": "pk_live_3b9f…",
"test": "3f1c2a9e-5b7d-4e21-9a0c-8d6f4b2e1a37",
"event": "newsletter_signup",
"variant": "b",
"visitorId": "6c0a1f4e-2d3b-4a59-8e71-0f9c2b5d7a13",
"properties": { "source": "footer" }
}
| Field | Required | Type and limit | What to send |
|---|---|---|---|
key | yes | string, up to 200 characters | The store's public key. |
test | yes | string, a UUID | The test's ID. |
event | yes | string, 1 to 100 characters | The Event name exactly as defined on the test. Upper and lower case matter. |
variant | no | string, up to 16 characters | The version the visitor saw, see Variant values. |
visitorId | no | string, up to 128 characters | The ab.one visitor ID, see Visitor ID and test ID. |
properties | no | object | Extra details. Only the keys listed under Allowed body parameters are kept. |
The body may be sent as application/json or as text/plain with the same JSON in it. Don't add fields called events or heartbeat: ab.one uses those for its own tracking requests, and the request is then handled as one of those.
What ab.one stores
- The event name, the test, the version and the visitor ID you sent.
- From
properties, only the allowed body parameters. Everything else is dropped before saving, so no personal data ends up in ab.one by accident. If you allow a parameter likeemail, its value is stored, so allow only what you need. - The device type, taken from the request's
User-Agentheader, and the country, taken from the visitor's IP address. ab.one keeps only a hash of the IP address.
Because of the last point, send events from the visitor's browser when you can. Sent from your server, device and country describe your server, not the visitor.
Variant values
variant tells ab.one which version to count the event for.
| You send | Counted for |
|---|---|
control, original, a or 0 | The control |
b, variant or 1 | The first variant |
c or 2, d or 3 … | The second, third … variant |
| Nothing, or anything else | The control |
Upper or lower case doesn't matter. Send it as a string: "1", not 1. A number is rejected with 400.
Visitor ID and test ID
On the storefront, the ab.one theme script keeps the visitor in the browser's local storage under ab.one_visitor, as JSON. It holds the visitor ID (id) and one entry per test the visitor is in (assignments), each with the testId and the variantIndex (0 is the control, 1 the first variant, and so on).
window.abone doesn't offer a function that returns these. Read local storage directly, and be careful: it's the script's own storage, not a versioned API. Code it so that a missing or different value just means "don't send".
function aboneAssignment(testId) {
try {
const visitor = JSON.parse(localStorage.getItem("ab.one_visitor") || "null");
const a = visitor?.assignments?.find((x) => x.testId === testId);
if (!visitor?.id || !a || typeof a.variantIndex !== "number") return null;
return { visitorId: visitor.id, variant: String(a.variantIndex) };
} catch {
return null;
}
}
To see your own visitor ID and version while testing, open the test with the debug pane.
The test ID is in the address of the test's page in ab.one (/tests/3f1c…), in the example under How it works, and in the REST API.
Examples
From the storefront
For example in a theme section or a custom Liquid block, after the sign-up form was sent:
const TEST_ID = "3f1c2a9e-5b7d-4e21-9a0c-8d6f4b2e1a37";
const PUBLIC_KEY = "pk_live_3b9f…";
function sendAboneEvent(event, properties) {
// ab.one only tracks visitors who allow analytics (Shopify Customer Privacy API).
if (window.Shopify?.customerPrivacy?.analyticsProcessingAllowed?.() !== true) return;
const assignment = aboneAssignment(TEST_ID);
if (!assignment) return; // not in this test
fetch("https://app.ab.one/api/v1/events", {
method: "POST",
// text/plain avoids a CORS preflight, so keepalive works.
headers: { "Content-Type": "text/plain" },
body: JSON.stringify({
key: PUBLIC_KEY,
test: TEST_ID,
event,
variant: assignment.variant,
visitorId: assignment.visitorId,
properties,
}),
keepalive: true, // still delivered if the page navigates away
}).catch(() => {});
}
sendAboneEvent("newsletter_signup", { source: "footer" });
The endpoint accepts requests from any website (CORS), so this works from your store's domain.
From your server
When the action happens on your side, for example after your backend confirmed a sign-up, pass along the visitor ID and version from the browser:
curl -X POST https://app.ab.one/api/v1/events \
-H "Content-Type: application/json" \
-d '{
"key": "pk_live_3b9f…",
"test": "3f1c2a9e-5b7d-4e21-9a0c-8d6f4b2e1a37",
"event": "newsletter_signup",
"variant": "1",
"visitorId": "6c0a1f4e-2d3b-4a59-8e71-0f9c2b5d7a13",
"properties": { "source": "footer" }
}'
Responses
When ab.one accepted the event:
HTTP/1.1 202 Accepted
{ "data": { "ok": true } }
Errors look like this:
{ "error": { "code": "ERROR", "message": "Test is not active" } }
| Status | code | message | Why |
|---|---|---|---|
400 | BAD_REQUEST | "Invalid JSON" | The body isn't valid JSON. |
400 | BAD_REQUEST | "Invalid event payload" | A required field is missing, a field has the wrong type, or a value is too long. |
400 | ERROR | "Test is not active" | The test isn't live. Events are only accepted while the test is live. |
400 | ERROR | "Invalid variant" | variant points to a version number above 255. |
401 | ERROR | "Invalid public key" | key doesn't belong to any store. |
404 | ERROR | "Test not found for this store" | The test doesn't exist or belongs to another store. |
404 | ERROR | Unknown event "…" | No custom event with this name is defined on the test. |
413 | PAYLOAD_TOO_LARGE | "Request body too large" | The body is larger than 256 KB. |
429 | RATE_LIMITED | "Too many requests. Please try again later." | Too many requests from this IP address. Wait for the seconds in Retry-After. |
500 | ERROR | "Event ingestion failed" | Something went wrong on ab.one's side. |
Limits
| Limit | Value |
|---|---|
| Body size | 256 KB |
| Requests per IP address | 600 per minute, counted together with ab.one's own tracking requests from the same address |
| Events per request | 1 |
The public key
The public key starts with pk_live_ and is the same for every test of the store. ab.one's own tracking uses it too.
It's made to be visible in the storefront's code. With it, anyone can send events to the store's live tests, but nobody can read test data, change tests or use the REST API. Because it's public, treat custom event counts as a signal, not as exact figures. The key can't be changed in the app.