POST to https://in.crispstats.com/e, authenticated by a secret API key (cs_sk_…). Pass the visitor id you saved from the browser, and the event joins that visitor’s history. There is nothing to install: any HTTP client works.
identify and revenue do not.
Set it up
1
Create a secret API key
In the dashboard, open the workspace page (Workspace in the account menu, or Team and API keys below a site’s settings tabs), and under API keys create a key with the Events scope. The Write and Admin scopes also allow sending events; a Read key, the default for the REST API, gets
403 key_not_valid_for_site. Choose whether the key works for every site in the workspace or only this site. Owners and admins can create keys.The key is shown once. Store it as a secret on your server, for example in a CRISPSTATS_API_KEY environment variable. Never send it to a browser.2
Save the visitor id in the browser
Server-side events attach to a visit only through a visitor id. When the user does something your server will follow up on, such as signing up or starting a checkout, read the id in the browser and send it to your backend:
crispstats.id() returns a Promise of the anonymous id the collector files this browser’s events under right now. It resolves to undefined when the script did not start on the page (for example on localhost or in an opted-out browser) or when the request fails. Store the id with the user or order record. Behind a proxy, crispstats.id() works the same way.3
Send the event from your server
Post the event where the action happens. In TypeScript, this function is all you need. It runs on Node 18 and later, Cloudflare Workers, Vercel Functions, Deno and Bun:Call it from your handler:Other languages send the same request: see send the request over HTTP.
crispstats-server.ts
4
Check the dashboard
Open Events. The event appears with the name and properties you sent.
Send the request over HTTP
The request is the same from any language:Request body
The body is JSON, at most 16 KB, in the same format the browser script sends.How the event is attributed
- With a valid
vid. If that visitor has an open session, the event joins it and takes the session’s source, and the session’s user id when you send none. Otherwise the event is stored under that visitor id on its own, with the source Direct. - With
iand novid. The event is filed under a visitor id derived from your user id, so repeated events for the same user land together, and it counts toward that user’s identified profile. - With neither. The event is counted, under an id of its own, but belongs to no visit.
Status codes
Next steps
Visitor id at checkout
Pass the visitor id to your payment provider so revenue is attributed.
API keys
Create, scope, revoke and delete secret keys.
Collector reference
Every endpoint the collector serves at in.crispstats.com.