Skip to main content
A payment can only be attributed to a visit when the checkout carries that visitor’s CrispStats id. Call 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

It returns a Promise of a 32-character lowercase hex string: the id the collector files this browser’s events under right now. Nothing is added to your reports. Get the id in the visitor’s browser, not on your server. The collector derives it from the browser’s request, so a call from your server returns an id that belongs to your server.

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 and crispstats.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:
The script must have loaded first: the queue stub described in custom events cannot return a value, so it does not cover 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 .localhost name, 127.0.0.1, [::1] or file:// and data-allow-localhost is 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.
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:
Each provider’s page shows the same code, with what else that provider reads.

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, call crispstats.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.
User ids are cut at 200 characters.

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.
Last modified on November 24, 2026