Skip to main content
To add CrispStats to a React or Vite app, paste the script tag into index.html. Route changes are picked up from the History API, which React Router and TanStack Router both use, so there is nothing to wire into your router. There is no npm package to install. You need your site’s public key, which starts with cs_pk_. Settings, Tracking code, React / Vite shows the tag with your key and domain filled in.
1

Add the tag to index.html

In a Vite project, index.html sits at the project root. Add the tag inside <head>:
index.html
Replace the key and the domain with yours. Keep the CrispStats tag a classic script with defer: type="module" does not work for it, because the script reads its options from its own tag.
2

Add types and the queue stub (TypeScript)

Save crispstats.d.ts in src/, and import the queue stub as the first line of src/main.tsx. Both files are on the TypeScript page. Then call the global from any component:
src/UpgradeButton.tsx
The optional call (?.) keeps the button working when an ad blocker stops the script. You can also track clicks with data-cs-event attributes and no JavaScript: see declarative events.
3

Deploy and check

Visits to the Vite dev server on localhost are not counted. Deploy, then open your production site in a normal browser window. Your visit appears in Realtime within a few seconds, and Settings, Tracking code shows Receiving events. To see events locally, use debug mode.

Routers

The same URL twice in a row counts as one pageview, so a repeated replaceState or a navigation to the current page does not inflate your numbers. See single-page apps.

Check that it works

  • Open your deployed app with the browser’s developer tools on the Network tab. You should see d.js load from in.crispstats.com and a POST to https://in.crispstats.com/e on the first load. The collector answers 202.
  • Click through a few routes. Each new URL sends another POST. If only the first load sends one, your router uses hash URLs (add data-hash) or saves history.pushState in a way the script cannot see (add data-manual, see the table above).
  • In CrispStats, Settings, Tracking code shows Receiving events., and each route appears in Realtime within seconds.
  • Open https://in.crispstats.com/check?k=cs_pk_xxxxxxxx with your key. "site": "known" means the key is right.

FAQ

No. The tag in index.html is the whole install, and the global window.crispstats is what you call from components.
No. The script is loaded once by the tag, outside React, so strict mode’s double rendering does not touch it. The same URL twice in a row is also one pageview.
Call await window.crispstats?.id() in the click handler that starts checkout and pass the id to your payment provider. See visitor id at checkout.

Next steps

Custom events

Track signups, clicks and other actions with properties.

TypeScript

Types for the global and the queue stub.

Proxy

Serve the script from your own domain.
Last modified on November 23, 2026