Static site generators · 2 min setup
How to add analytics to Docusaurus
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
scriptsarray indocusaurus.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 starton localhost is ignored
How to install VisitTrack on Docusaurus
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.Step 2: Add the script to docusaurus.config.ts
Add it next to your existing config keys.
docusaurus.config.tsimport 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;Step 3: Build and deploy
Run
npm run buildand deploy thebuildfolder (or let your host build it). Then open the live docs.
How to check VisitTrack is working on Docusaurus
- View source on a deployed page: the head contains a script tag loading
visitrack.app/tracker.jswith yourdata-siteattribute. - Click through a few sidebar pages; each shows up in the Pages tab and the live view.
- DevTools → Network: one
POSTtovisitrack.app/api/collectper page change, without full reloads.
Does VisitTrack track Docusaurus page navigation?
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.
<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.
| Attribute | What it does |
|---|---|
data-cookieless | Store 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-local | Track on localhost and *.local — for testing an install only. |
data-debug | Log 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
- Mintlify analyticsAdd VisitTrack to Mintlify docs with a custom .js file in your docs repo — page changes tracked, and docs.example.com shares visitors with your main site.
- Gatsby analyticsAdd VisitTrack to Gatsby with setHeadComponents in gatsby-ssr — rendered into every page's head, with Gatsby Link navigations tracked automatically.
- React analyticsAdd VisitTrack to a React single-page app (Vite, Create React App) through index.html — React Router navigations are tracked automatically.
- Netlify analyticsAdd VisitTrack on Netlify with Snippet injection (no code) or in your framework, keep deploy previews out, and set CSP in _headers.
- Install the tracking scriptThe reference tag, CSP notes and how to check it's working.
- Custom events and signupsvisitrack(), data-vt-goal, scroll events and server-side signups.
- Use casesHow SaaS teams, indie hackers, stores and agencies use VisitTrack.
- VisitTrack vs Google AnalyticsCookie-free analytics with revenue attribution, compared honestly.
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.