crispstats.id() in the browser right before checkout, then put the id in the checkout’s metadata (or custom data) as crispstats_visitor_id. The webhook brings the id back to CrispStats with the payment.
Without the id the payment is still recorded and counted in revenue, MRR and every total, but it is not tied to a visit: it is left out of the source, campaign and channel breakdowns rather than filed under Direct.
Get the visitor id
Behind a proxy
If you serve the script through your own domain (see proxy the script),crispstats.id() asks your proxy at <your prefix>/id, which forwards to https://in.crispstats.com/p/id. The collector reads the visitor’s address from the X-Forwarded-For header your proxy sets, so the id is the same one your proxied pageviews are filed under. Nothing changes in your code.
If the proxy answers anything but the id (an old proxy rule that does not forward /id, an HTML error page), crispstats.id() asks https://in.crispstats.com/id directly instead. That direct id matches your events only when your proxy forwards the visitor’s address, so check that once with the setup check described in proxy the script.
You can also call the collector yourself from the browser. Both addresses keep working:
In a single-page app
In a single-page app (Next.js, React, Vue, SvelteKit), the script loads once andcrispstats.id() works on every route, including routes that render the checkout button after a client-side navigation. You do not need the script tag on the checkout page itself. Call it in the click handler that starts the checkout, not while the page renders:
crispstats.id(). A click handler runs long after the script has loaded.
When there is no id
crispstats.id() resolves to undefined instead of an id when the script is not tracking this browser, or when the request fails (for example, offline). The script does not track when:
- the page is on
localhost, a.localhostname,127.0.0.1,[::1]orfile://anddata-allow-localhostis not set, - the hostname is not in
data-domains, - the browser sends Do Not Track and the tag has
data-dnt, - the browser is automated, or the site owner excluded it with
localStorage.crispstats_ignore.
window.crispstats exists in all of these cases, so the call is safe. It does not exist when the script did not load at all, for example because an ad blocker stopped it, so call it with optional chaining as above and send the visitor to checkout without the id. The payment is then recorded without a visit.
Attach it to the checkout
CrispStats reads these fields from each payment it reads from the provider. Values that are not shaped like a visitor id (32 lowercase hex characters) are ignored.- Stripe
- Lemon Squeezy
- Polar
- Paddle
- Dodo Payments
- Creem
- Razorpay
- RevenueCat
Send the id from the browser to the server route that creates the Checkout Session (the button above), then put it in the metadata:For a one-time payment, leave out
subscription_data. Your own client_reference_id, if you set one, stays as it is.For a Payment Link, which has no metadata you can set per visitor, add the id to the link’s URL as client_reference_id:Attribute across days with your user id
The visitor id rotates daily unless the site has persistent visitors on, so on its own it links a payment to visits from the same day. If your customers sign in, callcrispstats.identify() with your user id and also pass it at checkout as crispstats_user_id in the same metadata. CrispStats then takes the first touch from the earliest session of that user, whichever day it was.
Next steps
Connect Stripe
Paste a restricted key; CrispStats creates the webhook.
Payment API
Report payments from any other provider or your own billing.
How attribution works
First-touch rules and the Revenue screen.