Static site generators · 2 min setup

How to add analytics to Docusaurus

To add VisitTrack to Docusaurus, add an object to the scripts array in docusaurus.config.ts with src, defer: true and 'data-site': 'SITE_ID'. Docusaurus writes it into the head of every page, and its client-side page changes are counted automatically.

Updated

Docusaurus's scripts option accepts plain objects whose keys become attributes on the generated <script> tag — the only required key is src, and any other attribute is allowed. That's exactly what the tracker needs: an external script with a data-site attribute.

Docusaurus at a glance

Where it goes
scripts array in docusaurus.config.ts / .js
Attributes
Any key becomes an attribute ('data-site', defer)
Navigation
Client-side route changes tracked
Versioned docs
Each version's paths counted separately
Local dev
docusaurus start on localhost is ignored

How to install VisitTrack on Docusaurus

  1. Step 1: Copy your site id

    Use your product site's id if the docs are on a subdomain of the same domain (shared visitors), or create a separate site. Replace SITE_ID.

  2. Step 2: Add the script to docusaurus.config.ts

    Add it next to your existing config keys.

    docusaurus.config.ts
    import type { Config } from "@docusaurus/types";
    
    const config: Config = {
      title: "My Docs",
      url: "https://docs.example.com",
      baseUrl: "/",
      scripts: [
        {
          src: "https://visitrack.app/tracker.js",
          defer: true,
          "data-site": "SITE_ID",
        },
      ],
      // …presets, themeConfig
    };
    
    export default config;
  3. Step 3: Build and deploy

    Run npm run build and deploy the build folder (or let your host build it). Then open the live docs.

How to check VisitTrack is working on Docusaurus

  1. View source on a deployed page: the head contains a script tag loading visitrack.app/tracker.js with your data-site attribute.
  2. Click through a few sidebar pages; each shows up in the Pages tab and the live view.
  3. DevTools → Network: one POST to visitrack.app/api/collect per page change, without full reloads.

Docusaurus is a React single-page app after the first load: sidebar and navbar links change the URL with the History API, which the tracker follows. Each page change is one pageview; heading anchors (#installation) don't change the path and aren't counted again.

Versioned docs use different paths (/docs/next/intro vs /docs/intro), so you can see how much traffic still lands on old versions. The search page keeps its path when the query changes.

How to track custom events and goals in Docusaurus

Docs pages are MDX, which accepts plain JSX attributes — so a data-vt-goal on a link or button works anywhere in your content. Links from the docs to your app on another subdomain are tracked as outbound clicks automatically.

docs/quickstart.mdx
<a className="button button--primary" href="https://app.example.com/signup" data-vt-goal="docs_signup_click">
  Get an API key
</a>

Make the event a goal in Settings → Goals, and if the docs share a site id with your app, build a funnel from a docs page to signup to see which guides convert.

Script options you might need on Docusaurus

All optional — add them to the same tag. Full reference: script configuration.

AttributeWhat it does
data-cookielessStore nothing in the browser; the server derives a daily-rotating id. See cookieless mode.
data-exclude="/app/*"Never track these paths (comma-separated, * wildcard). Checked on every navigation.
data-allow-localTrack on localhost and *.local — for testing an install only.
data-debugLog every event the script sends, and why it skipped one, to the console.
data-auto="false"Turn off automatic events (downloads, contact clicks, form submits, rage clicks, JS errors, 404s).

Docusaurus troubleshooting

data-site is missing from the generated tag

The key must be quoted ("data-site") and its value a string. Rebuild after changing the config.

Nothing during npm start

Localhost is ignored by design; test the deployed site, or temporarily add "data-allow-local": true.

Docs and app counted as different visitors

They use different site ids or different root domains. Use one data-site on subdomains of one domain; see cross-domain tracking in Script configuration for separate domains.

CSP violations

If your host sends a Content-Security-Policy, add https://visitrack.app to script-src and connect-src.

Docusaurus analytics FAQ

How do I add a script to Docusaurus?

Use the scripts array in docusaurus.config.js or .ts. Each entry can be a string (just the URL) or an object whose keys become attributes, such as src, defer and data-site.

Does VisitTrack track Docusaurus page navigation?

Yes. Docusaurus navigates client-side with the History API, and the tracker counts each page change as a pageview.

Is there a Docusaurus plugin for VisitTrack?

No; the built-in scripts option is all you need, so there's nothing to install or keep compatible across Docusaurus versions.

Can I see which documentation pages lead to signups?

Yes, if the docs and your product share a VisitTrack site on the same root domain. Visitors are shared, so a funnel from a docs page to your signup event shows conversion by page.

Does it work with Docusaurus on GitHub Pages, Netlify or Vercel?

Yes. The tag is part of the generated static HTML, so any host works.

Keep going

Add VisitTrack to your Docusaurus site

Cookie-free analytics with revenue attribution, live visitors, funnels and session replays. One script tag, every feature on every plan. 14 days free, no card required.

Not on Docusaurus? See all 29 integration guides.