Activity API
Send what people do on your site, straight from the browser.
The Activity API records what people do on your site or in your app: a page view, a sign-up, a plan change. Each event belongs to a person. An event can start an automation or put a person in an audience.
The base URL is https://api.acorndispatch.com. Requests and answers are JSON. There is one endpoint: Send an event. It is safe to call from a web page.
Send a track key in the Authorization header on every request:
Authorization: Bearer $ACORNDISPATCH_TRACK_KEY- A workspace Admin creates track keys in AcornDispatch, on Activity, APIs & Keys. Every track key starts with
adt_. An Admin can copy a key again at any time. - A track key works on the Activity API only. An Email API key gets 401
unauthorizedhere, and a track key gets 401 on every Email API route. - A missing, wrong or revoked key gets 401
unauthorized.
A page can call the API with fetch. The browser first sends a preflight OPTIONS request. It gets 204 for any origin. Every answer to the POST allows any origin, so your page can read it, an error too. Send no cookies: the API reads none.
Each track key can have a list of up to 20 allowed origins. An empty list allows any origin.
- An origin is
https://hostorhttps://host:port, with no path. For local work,http://localhostandhttp://127.0.0.1work too, with or without a port. - With a list, the request must carry an
Originheader that is in it. A request with noOrigin, orOrigin: null, gets 403origin_not_allowed. So does another site. - A change to the list works from the next request.
A track key sits in your page source, so it is public. Anyone who reads it can send events with it. Allowed origins stop other websites from using the key in a visitor's browser. They cannot stop a script outside a browser, which can send any Origin header.
With your track key, anyone can:
- Add events to people who already exist in your workspace. An event for an identifier with no person is answered
{}like any other, and is not stored. A track key never creates a person and never changes the attributes your app sets. - Change what AcornDispatch works out from events. For example, a
subscribe successevent marks the person as one who has paid. - Put an existing person in an audience whose rule reads events, and start an automation that starts on an event for that person. A person enters each automation once at most.
- Send an event
idfor a person first, so that your later event with the sameidfor that person is not stored.
The rate limits cap how much one key can send. To stop a key, revoke it in AcornDispatch and create a new one.
- An event with an
idis stored once per person. A repeat with the sameidfor the same person is answered{}and not stored, whatever key sent the first one. - The same
idfor two people stores two events. - An event with no
idis always stored.
- Each track key may send 1,200 events per minute.
- Each client IP address may send 120 events per minute with one key. Visitors behind one address, such as an office or a mobile network, share it. Over it, their browsers get 429 and those events are lost.
- Requests with a wrong key count per client IP address: over 60 per minute they get 429 too.
- Over a limit, the API answers 429
rate_limitedwith aretry-afterheader in seconds, counted per clock minute.
Every error has this form:
{ "error": { "code": "origin_not_allowed", "message": "This track key does not allow requests from this origin" } }Branch on code, not on message. Each code, its HTTP status and what it means:
| Code | HTTP | Meaning |
|---|---|---|
invalid_request | 400 | The body or the identifier breaks a rule: not JSON, an unknown field, no name, a timestamp that is not in seconds, a NUL character. The message names the field. |
payload_too_large | 413 | The body is over 32 KB. |
unauthorized | 401 | The track key is missing, wrong or revoked, or the key is not a track key. |
origin_not_allowed | 403 | The key has allowed origins and the request's Origin is not one of them, or is missing. See Browser use and allowed origins. |
rate_limited | 429 | Over a limit. Wait the retry-after seconds, then retry. See Rate limits. |
internal_error | 500 | Something failed on our side. Retry with the same event id. |
invalid_request400The body or the identifier breaks a rule: not JSON, an unknown field, noname, atimestampthat is not in seconds, a NUL character. The message names the field.payload_too_large413The body is over 32 KB.unauthorized401The track key is missing, wrong or revoked, or the key is not a track key.origin_not_allowed403The key has allowed origins and the request'sOriginis not one of them, or is missing. See Browser use and allowed origins.rate_limited429Over a limit. Wait theretry-afterseconds, then retry. See Rate limits.internal_error500Something failed on our side. Retry with the same eventid.
POST/
Needsa track key
Records something a person did, such as a page view or a plan change. The event is stored for a person who already exists. See What a track key can do.
- The body is strict: any other field gets 400
invalid_request. - The body is at most 32 KB. Above it: 413
payload_too_large. - The body can be nested at most 32 levels deep. Deeper gets 400
invalid_request. - The answer is
{}for every identifier. An identifier with no person gets the same answer, and the event is not stored.
Path
| Field | Type | Required | Note |
|---|---|---|---|
identifier | string | Yes | The person's email address, or your app's own id for them. 1 to 255 characters. Percent-encode it (encodeURIComponent). It cannot start with cio_. |
identifierstring, requiredThe person's email address, or your app's own id for them. 1 to 255 characters. Percent-encode it (encodeURIComponent). It cannot start withcio_.
Body
| Field | Type | Required | Note |
|---|---|---|---|
name | string | Yes | The event, for example page_viewed. 1 to 255 characters, trimmed. |
data | object | No | Facts about the event. Stored with it. Not sent: {}. |
timestamp | integer | No | When it happened, in Unix seconds. A value that is not a time in seconds, or that is more than 5 minutes in the future, gets 400 invalid_request. Not sent: the time AcornDispatch got it. |
id | string or integer | No | Your id for the event, up to 100 characters. A repeated id for the same person is stored once. See Event ids. |
namestring, requiredThe event, for examplepage_viewed. 1 to 255 characters, trimmed.dataobject, optionalFacts about the event. Stored with it. Not sent:{}.timestampinteger, optionalWhen it happened, in Unix seconds. A value that is not a time in seconds, or that is more than 5 minutes in the future, gets 400invalid_request. Not sent: the time AcornDispatch got it.idstring or integer, optionalYour id for the event, up to 100 characters. A repeatedidfor the same person is stored once. See Event ids.
Errors
| Code | HTTP | When |
|---|---|---|
invalid_request | 400 | The body or the identifier breaks a rule: not JSON, an unknown field, no name, a timestamp that is not in seconds, a NUL character. The message names the field. |
payload_too_large | 413 | The body is over 32 KB. |
unauthorized | 401 | The track key is missing, wrong or revoked, or the key is not a track key. |
origin_not_allowed | 403 | The key has allowed origins and the request's Origin is not one of them, or is missing. See Browser use and allowed origins. |
rate_limited | 429 | Over a limit. Wait the retry-after seconds, then retry. See Rate limits. |
invalid_request400The body or the identifier breaks a rule: not JSON, an unknown field, noname, atimestampthat is not in seconds, a NUL character. The message names the field.payload_too_large413The body is over 32 KB.unauthorized401The track key is missing, wrong or revoked, or the key is not a track key.origin_not_allowed403The key has allowed origins and the request'sOriginis not one of them, or is missing. See Browser use and allowed origins.rate_limited429Over a limit. Wait theretry-afterseconds, then retry. See Rate limits.
Example
const identifier = ''
fetch(`https://api.acorndispatch.com/api/v1/customers/${encodeURIComponent(identifier)}/events`, {
method: 'POST',
headers: {
Authorization: `Bearer ${ACORNDISPATCH_TRACK_KEY}`,
'Content-Type': 'application/json',
},
body: JSON.stringify({
name: 'plan_upgraded',
data: {
plan: 'pro',
},
timestamp: 1790000000,
id: 'evt_8f2c1',
}),
}){}const identifier = ''
fetch(`https://api.acorndispatch.com/api/v1/customers/${encodeURIComponent(identifier)}/events`, {
method: 'POST',
headers: {
Authorization: `Bearer ${ACORNDISPATCH_TRACK_KEY}`,
'Content-Type': 'application/json',
},
body: JSON.stringify({
name: 'plan_upgraded',
data: {
plan: 'pro',
},
timestamp: 1790000000,
id: 'evt_8f2c1',
}),
}){}