Install on Mintlify
Mintlify doesn’t take a <script> tag directly. Instead, it loads every .js file found in your docs folder on all pages. You add one small file that loads the analytics script.
Copy the code
In the portal, open Settings → Install and choose Mintlify. Copy the code shown. It looks like this, with your own site key:
(function () {
var s = document.createElement('script');
s.defer = true;
s.src = 'https://analytics.writechoice.io/s/YOUR_SITE_KEY.js';
document.head.appendChild(s);
})();Create analytics.js
In your docs repository, create a file named analytics.js in the docs folder, next to docs.json, and paste the code into it.
Publish
Commit and push. Mintlify publishes the change with your next deployment. Then check that it works.
Notes
- The file name doesn’t matter, as long as it ends in
.jsand sits inside the docs folder. - Don’t paste a
<script src="...">tag into an MDX page: Mintlify’s documentation advises against it. Use the.jsfile instead. - Mintlify is a single-page application: moving between pages doesn’t reload the browser. The script records a pageview on each navigation, so you don’t need to listen for Mintlify’s navigation events yourself.
- The file applies to the whole site. It can’t be limited to some pages.
- To add a tag, add
s.setAttribute('data-tag', 'v2');after thes.srcline.
Heatmap preview
Sites hosted by Mintlify only allow being shown inside Mintlify’s own dashboard, so the Heatmaps tab draws the clicks on a blank background. This can’t be changed in docs.json: Mintlify changes the allowed origins on request. Email Mintlify support with your project subdomain, your documentation domain, the origins to allow (see Heatmap preview) and what it’s for. See Mintlify’s help page Embed your docs site in an iframe. If your docs are served through your own reverse proxy that sets the policy, change frame-ancestors there instead.
Site search
The Mintlify search box is recorded automatically: the final search, the number of results shown, and the result the reader opens. Questions sent to the Mintlify assistant are not recorded by the snippet: they are what the AI Reports look at.