CMS & blogs · 3 min setup

How to add analytics to Mintlify docs

To add VisitTrack to Mintlify, add a .js file (for example visitrack.js) to your docs repository that inserts the tracker script. Mintlify includes every .js file in your content directory on every page, so one file covers the whole docs site.

Updated

Mintlify's built-in analytics integrations are configured in docs.json, but VisitTrack isn't one of them — so you use Mintlify's custom scripts feature. Mintlify recommends injecting third-party scripts from JavaScript rather than writing raw <script src> tags in MDX, which is what the file below does.

Use the same data-site as your marketing site when the docs live on a subdomain like docs.example.com: subdomains of one root domain share the visitor id, so a reader who goes from docs to signup is one visitor with one source.

Mintlify at a glance

Where the code goes
A .js file in your docs content directory
Scope
Runs on every page; can't be scoped to some pages
Page changes
Tracked through the History API
Subdomain docs
Same site id → shared visitors with your main site
Goes live
On your next Mintlify deployment

How to install VisitTrack on Mintlify

  1. Step 1: Copy your site id

    Use the site id of your main product site (recommended for docs.yourdomain.com), or create a separate site for the docs. Replace SITE_ID below.

  2. Step 2: Create visitrack.js in your docs repo

    Place it in the content directory (next to docs.json). It creates the same tag as the standard snippet, and skips if the tag already exists so it can never load twice.

    visitrack.js
    (function () {
      if (document.querySelector('script[src="https://visitrack.app/tracker.js"]')) return;
      var s = document.createElement("script");
      s.defer = true;
      s.src = "https://visitrack.app/tracker.js";
      s.setAttribute("data-site", "SITE_ID");
      document.head.appendChild(s);
    })();
  3. Step 3: Allow the docs hostname

    If you've saved Allowed hostnames in VisitTrack's Settings → General, add docs.yourdomain.com (or *.yourdomain.com). Until you save a list, every hostname counts.

  4. Step 4: Commit and deploy

    Push the file. Mintlify deploys on push to your docs branch; the script runs once the deployment is live. Local previews on localhost are ignored by the tracker.

How to check VisitTrack is working on Mintlify

  1. Open your live docs and click through two or three pages in the sidebar.
  2. VisitTrack's live view shows you; the Pages tab lists each docs path. With a shared site id, filter by host in the Hostname tab to see docs only.
  3. DevTools → Network: one POST to visitrack.app/api/collect per page change.

Mintlify docs switch pages in the browser without a full reload. The tracker follows History API navigations, so each docs page a reader opens is one pageview. Jumping to a heading anchor (#authentication) doesn't change the path and isn't counted again.

Mintlify custom scripts run after the page becomes interactive, so a reader who closes the tab within the first moment may not be counted — a small, consistent undercount rather than a skew.

How to track custom events and goals in Mintlify

Links from your docs to your app ("Get an API key", "Sign up") on another subdomain are outbound clicks, tracked automatically. To name a specific call to action, MDX accepts plain JSX attributes, so data-vt-goal works on links you write:

quickstart.mdx
<a href="https://app.example.com/signup" data-vt-goal="docs_signup_click">
  Create a free account
</a>

With a shared site id, the signup event your app already sends lands on the same visitor — so you can build a funnel from a docs page to signup and see which guides convert. See custom events.

Script options you might need on Mintlify

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).

Mintlify troubleshooting

The file doesn't seem to run

It must be a .js file inside the content directory Mintlify builds from, and the change must be deployed. Check the live page's DevTools console for errors.

Docs and main site show as separate visitors

They use different site ids, or live on different root domains. Use the same data-site on a subdomain of your main domain; for a separate domain, see cross-domain tracking in Script configuration.

Hits from the docs are blocked

Your Allowed hostnames list doesn't include the docs host. Allow it from the Blocked hostnames list in Settings → General.

Docs behind a reverse proxy at /docs

That works too: the docs are just paths on your main domain. If your proxy sets a Content-Security-Policy, add https://visitrack.app to script-src and connect-src.

Mintlify analytics FAQ

Does Mintlify support custom analytics scripts?

Yes. Mintlify includes any .js file in your content directory on every page, and recommends injecting third-party scripts from that file. That's how VisitTrack is installed.

Can I add VisitTrack to Mintlify's analytics integrations in docs.json?

No, VisitTrack isn't a built-in Mintlify integration. The custom JavaScript file above loads it on every page instead.

Should docs use the same VisitTrack site as my product?

Usually yes, if the docs are on a subdomain of the same domain. Visitors are shared through the root-domain id, so you can see which docs pages lead to signups. The Hostname tab still lets you look at docs traffic alone.

Are Mintlify page changes tracked?

Yes. The tracker listens to the History API, so each docs page a reader opens without a full reload is still a pageview.

Can I see which AI crawlers read my docs?

Not from the browser script — most AI crawlers don't run JavaScript. VisitTrack's AI crawler tracking needs a small server-side hook, which isn't possible on Mintlify's hosting unless you serve the docs through your own proxy.

Keep going

Add VisitTrack to your Mintlify 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 Mintlify? See all 29 integration guides.