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
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:Do not set a flag to
docusaurus.config.js
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.jsloading fromin.crispstats.comand aPOSTtohttps://in.crispstats.com/eon the first load and on each page change. The collector answers202. - 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 forin.crispstats.com/d.jsto 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 everypushState, 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 withdata-cs-event, with no JavaScript:
docs/intro.mdx
window.crispstats?.("copy code", { page: "intro" }). See custom events and declarative events.
FAQ
Do I need a Docusaurus plugin?
Do I need a Docusaurus plugin?
No. The
scripts entry is the whole install.Can I count readers who use ad blockers?
Can I count readers who use ad blockers?
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.