revenue event from your server with a secret API key and the visitor id you saved at checkout. The payment is recorded and attributed exactly like a webhook payment, with provider api.
Amounts are integers in minor units (4900 is 49.00) with an ISO 4217 currency code. The same instructions are in Settings, Integrations, under Payment API, View instructions.
Report a payment from your server
You need:- A secret API key (
cs_sk_…) with theeventsscope. Create one in Settings, API keys. See API keys. Never ship it to a browser. - The site’s public key (
cs_pk_…). - The visitor id from
crispstats.id(), saved with the order when the visitor checked out.
authorization header must start with Bearer cs_sk_. Without it the request is handled as a browser event: it gets an empty 202 without any checks and is then dropped, because it does not come from a browser.
A 202 response with an empty body means the payment was accepted. It appears under Payments on the Revenue screen within a few seconds. The example uses the global fetch, so it runs on Node.js 18 and later, Cloudflare Workers, Vercel Edge, Deno and Bun.
Request body
The amount as an integer in minor units.
4900 is 49.00. A number with decimals fails with 400. A negative amount is recorded as a refund (only with a secret key, as here), and 0 records no payment.The three-letter ISO 4217 currency code, such as
USD. It must be exactly three characters, or the request fails with 400. When it is missing, or its three characters are not all letters, the site’s currency is used.The visitor id from
crispstats.id(), 32 lowercase hex characters. It ties the payment to that visitor’s visits. A value of another shape is ignored, and one over 64 characters fails with 400. Without a visitor id or a user id (i) the payment is recorded but not tied to a visit.Your own user id, as passed to
crispstats.identify(), up to 200 characters. Attribution then uses that user’s sessions. trackServer sends its userId option here.An event name, up to 120 characters. Shown as the payment’s product when
p.product is not set. trackServer sends its name option here.Flat properties with keys up to 60 characters: strings (up to 500 characters), numbers, booleans or
null. Set product to name the product in the payments table. trackServer sends its props option here.ts field in the body is not used for the time.
Responses
How the payment is recorded
The payment is stored with providerapi and kind one_time, or refund for a negative amount. The API does not record subscription_new or subscription_renewal: use a provider integration for those. See payment types.
When the request carries vid and that visitor is still on your site, the payment is attached to their open session and appears in the realtime feed. Either way, first-touch attribution then runs as described in how revenue attribution works.
Report a payment from the browser
The script can also report a payment from the page the buyer lands on after paying:api like a server-side payment.
It needs no API key, but it has trade-offs. Prefer the server for anything you rely on:
- It can be blocked. Ad blockers that block the script block the payment too.
- Anyone can send it. The public key is in your page, so a visitor can call
crispstats.revenue()with any amount. - Every call counts. Reloading or revisiting the thank-you page records the payment again.
- It cannot record a refund. Refunds are accepted only from a secret key (the server-side event above) or a verified payment webhook. A negative amount sent from the browser with the public key is dropped like any other invalid browser input.
- It is skipped when the browser is not tracked, for example on an excluded path or with
localStorage.crispstats_ignoreset. - Errors are silent. The collector answers
202to browser events even when the payload is invalid.
crispstats.revenue() before the script has loaded, add the queue stub for identify and revenue from custom events.
Next steps
Pass the visitor id
Get the id at checkout and store it with the order.
Server-side events
The same endpoint for custom events and identify.
API keys
Create a key with the events scope.