Skip to content

Frameworks

Docusaurus analytics with CrispStats

One object in the scripts array of docusaurus.config.js adds CrispStats to a Docusaurus site, followed by a deploy. Docusaurus puts it in the head of every page, and moving between docs pages is counted because the script watches the History API, so there is no plugin or npm package to install.

Updated

Set up CrispStats on Docusaurus

  1. 01

    Step 1: Add an entry to scripts

    Docusaurus turns each object in `scripts` into a <script> tag in <head>, with every key as an attribute. Copy your public key (it starts with cs_pk_) from Settings, Tracking code in the CrispStats dashboard and set your domain. If your config uses module.exports, add the same scripts key there.

    Replace the highlighted values with your own.

    docusaurus.config.js
    export default {// ...your existing configscripts: [{src: "https://in.crispstats.com/d.js",defer: true,"data-site": "cs_pk_your_site_key","data-domains": "example.com",},],};
  2. 02

    Step 2: Keep defer: true

    Docusaurus notes that scripts added this way block rendering unless they are deferred. With defer: true the page renders first and the script runs after.

  3. 03

    Step 3: Turn on more tracking (optional)

    Each option is one more key, and a flag takes an empty string. 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, because Docusaurus routes with real paths.

    docusaurus.config.js
    scripts: [{src: "https://in.crispstats.com/d.js",defer: true,"data-site": "cs_pk_your_site_key","data-domains": "example.com","data-outbound": "","data-vitals": "",},],
  4. 04

    Step 4: Build and deploy

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

  5. 05

    Step 5: Count clicks in MDX (optional)

    Give a link or button a data-cs-event attribute, with no JavaScript. From a React component, call window.crispstats?.("copy code", { page: "intro" }).

    docs/intro.mdx
    <a href="https://example.com/signup" data-cs-event="docs signup click">Create an account</a>

Check that it works

On your live docs, the developer tools’ Network tab shows d.js loading from in.crispstats.com and a POST to /e on the first load and again on each page change; the collector answers 202. In CrispStats, Settings, Tracking code shows Receiving events. and the visit appears on the Realtime screen within seconds. To confirm the tag itself, search a built page in build/ for in.crispstats.com/d.js.

What the install check shows once the first events land, on the demo site, Quillbook, on generated traffic.
  • What you get

    • The Pages report shows which docs are read most, from the first load and every page change after it.
    • Sources and channels, including readers who arrive from AI assistants such as ChatGPT and Perplexity, as their own channel. See AI traffic.
    • Entry pages, so you see which docs pages people land on from search and from assistants.
    • Broken links into your docs as 404 events, once data-404 is on and the not-found page is marked with a meta tag, a CSS selector or its 404 status (404 pages).
    • A core script of about 2.2 KB gzipped, with optional web vitals and outbound link clicks.
  • Notes and limits

    • The script counts a pageview on every pushState, replaceState and back or forward navigation. The same URL twice in a row is one pageview.
    • Clicking a heading anchor on the same page is not a new page: the fragment is dropped unless the tag has data-hash, which a Docusaurus site does not need.
    • headTags also inserts tags into <head> and works if your config already uses it; scripts is the simpler choice for one script tag.
    • Docs readers are often developers with ad blockers. Serve the script from your own domain with a forwarding rule on Vercel, Netlify, Cloudflare or nginx: see the proxy guide.
    • AI crawlers such as GPTBot read your docs without running JavaScript, so the script never sees them. Reporting them needs edge code on your host.

The docs page covers the optional steps this guide leaves out.

Setup questions. Straight answers.

What people ask before they connect it.

  • No. One entry in the scripts array of docusaurus.config.js is the whole install, with no package to keep updated.

  • Yes. Docusaurus changes the URL through the History API when a reader opens another page, and the script counts each new URL as one pageview.

  • Yes. Visits referred by ChatGPT, Perplexity, Claude, Gemini, Copilot and others are their own channel, with the pages those readers land on.

  • CrispStats sets no cookies and stores nothing on the reader's device by default, and it never stores IP addresses. Docusaurus keeps the reader's colour mode in localStorage, and a search or chat widget you add may store more, so check the whole site. This is not legal advice.

  • Docs traffic is mostly pageviews, one event each. Every account starts with a 14-day free trial with every feature, AI assistant referrals included, and no card; then Starter is $5 a month for 250,000 events.

Not answered here? Write to hello@crispstats.com

Go further

Related

  • Web analytics for developers

    A small cookieless script with web vitals and error tracking, an npm SDK, a REST API and an MCP server, so your analytics fits the way you work.

  • Track visitors from ChatGPT and Perplexity

    How to see visits sent by AI assistants: the referrers and UTM tags to look for, why much of it shows as direct, and how to log AI crawlers.

  • Bounce rate vs engagement

    Bounce rate means different things in different tools.

  • Web analytics for SaaS products

    See which channels bring paying customers, where trials stall in the funnel, and how your app performs for real users, from one cookieless script.

  • Hugo analytics

    Add CrispStats to a Hugo site by pasting one script tag into the head partial every page uses, overriding the theme's copy.

Your traffic, crisp and clear

One script, no cookies, and every feature from the first day. Set up takes about as long as pasting a snippet.