Events and config
Send events#
POST /api/sdk/events with a JSON body of at most 64 KB and at most 100 events:
{
"key": "your-public-key",
"events": [
{
"event": "$pageview",
"distinctId": "optional-visitor-id",
"sessionId": "optional-session-id",
"props": { "path": "/pricing" },
"ts": 1791360000000,
"url": "https://example.com/pricing?utm_source=newsletter",
"referrer": "https://www.google.com/",
"utm_source": "newsletter",
"utm_medium": "email",
"utm_campaign": "october",
"screen": { "w": 1512, "h": 982 }
}
]
}Only event is required.
| Field | Meaning |
|---|---|
event | The name. $pageview is a page view; signup, checkout and purchase feed those counts in Web analytics; $identify creates a person in Product analytics › People |
distinctId | The visitor. Without it the server uses a daily visitor hash (see below) |
sessionId | The session, ended by 30 minutes without an event |
props | Any JSON object |
ts | Milliseconds since the epoch. Up to 30 days old is kept; older or future times become "now" |
url | The page URL; the path and hostname are taken from it |
referrer | The referring URL; only its hostname is kept, and your own host counts as no referrer |
utm_source, utm_medium, utm_campaign, utm_term, utm_content | Campaign parameters |
screen | { w, h } in CSS pixels |
The answer is 202 { "ok": true, "received": 3, "dropped": 0 }. dropped counts events that were invalid (no name) or not stored.
| Status | When |
|---|---|
400 | The body is not valid JSON or events is not an array |
404 | Unknown key |
413 | Body over 64 KB or more than 100 events |
429 | More than 600 requests a minute for one key |
What the server adds and keeps#
- Visitor: without
distinctIdthe visitor is a hash of key, date, IP address and user agent, salted with a server secret. It changes every day. The IP address is used for this hash only and never stored. - Country from your host's header (
x-vercel-ip-countryorcf-ipcountry). Browser, OS and device from the user agent. - Bots: requests from bot user agents (crawlers, headless browsers,
curl, uptime monitors) are not stored. They only show in Settings › Products › Verify installation, so acurltest proves the key works without counting a visit. - Retention: raw events are kept 90 days; the daily roll-ups behind the charts stay.
- PostHog: if the product reads its analytics from PostHog, the answer is
202withreceived: 0. The SDK keeps working for experiments, feedback and surveys.
curl -X POST "$HOST/api/sdk/events" -H "content-type: application/json" \
-d '{"key":"'$KEY'","events":[{"event":"$pageview","url":"https://example.com/"}]}'The SDK sends these batches for you every two seconds and when the page is hidden. Call the endpoint yourself only for events that happen on your server, for example a purchase in a payment webhook.
Events from your server#
Add "server": true to the body. The bot filter is skipped (server HTTP clients look like bots), no country, browser or device is added, and every event needs a distinctId: the same id you pass to identify(). Events without one are dropped.
{ "key": "your-public-key", "server": true, "events": [{ "event": "purchase", "distinctId": "user_42", "props": { "plan": "pro" } }] }Read recent events#
GET /api/sdk/events?key&limit returns { events, counts24h }: the latest events seen (up to limit, default 50, at most 500, from memory) and the number of events in the last 24 hours. Verify installation uses it.
Config#
GET /api/sdk/config?key returns { project, experiments }.