Skip to main content
To add CrispStats to a Docusaurus site, add one object to the scripts array in docusaurus.config.js. Docusaurus inserts it as a <script> tag in the <head> of every page, and page changes made in the browser are counted because the script watches the History API. You need your site’s public key, which starts with cs_pk_. Find it in your site’s settings under Tracking code. The key is safe to publish. There is no Docusaurus plugin or npm package to install.

Add the script

1

Add an entry to scripts

docusaurus.config.js
Replace the key and the domain with yours. If your config uses module.exports, add the same scripts key there. Keep defer: true: Docusaurus notes that scripts added here block rendering otherwise.
2

Turn on more tracking (optional)

Each option is one more key. A flag takes an empty string, which switches it on:
docusaurus.config.js
Do not set a flag to true. The tag would carry data-outbound="true", and for data-downloads the script reads the value as a list of file extensions. Leave out data-hash: Docusaurus routes with real paths. Script attributes lists every attribute.
3

Build and deploy

Run npm run build and deploy. npm run start serves on localhost, which the script ignores. Open your live docs in a normal browser window.

Check that it works

  • In your browser’s developer tools, the Network tab shows d.js loading from in.crispstats.com and a POST to https://in.crispstats.com/e on the first load and on each page change. The collector answers 202.
  • In CrispStats, Settings, Tracking code shows Receiving events., and the visit appears in Realtime within seconds.
  • View the source of a built page in build/ and search for in.crispstats.com/d.js to confirm the tag is in <head>.

How page changes are counted

After the first load, moving between docs pages changes the URL with the History API. The script counts a pageview on every pushState, replaceState and back or forward navigation. The same URL twice in a row is one pageview, and clicking a heading anchor on the same page does not count: the fragment is dropped unless the tag has data-hash, which a Docusaurus site does not need. See single-page apps. The Pages report then shows which docs are read most, and Sources shows where readers came from, including AI assistants. See AI traffic.

Send custom events

Track clicks in MDX with data-cs-event, with no JavaScript:
docs/intro.mdx
From a React component in your site, call window.crispstats?.("copy code", { page: "intro" }). See custom events and declarative events.

FAQ

No. The scripts entry is the whole install.
scripts is the simpler choice for one script tag. headTags also inserts tags into <head>, so it works if your config already uses it.
Serve the script from your own domain with a forwarding rule on your host. See proxy by host.

Next steps

AI traffic

See readers who arrive from ChatGPT, Perplexity and other assistants.

Proxy on Vercel

Serve the script from your own domain.

404 pages

Find broken links into your docs.
Docusaurus details (the scripts field, attribute maps, insertion into <head> and the render-blocking note) checked against https://docusaurus.io/docs/api/docusaurus-config on 2026-11-23.
Last modified on November 23, 2026