Add Privatus Analytics to Mintlify
Add cookieless analytics to a Mintlify docs site with a custom JavaScript file in your docs repo, since Mintlify has no custom script tag option.
Mintlify's built-in analytics list in docs.json is a fixed set of
providers. Custom JavaScript is the way to add anything else. Mintlify
includes any .js file in your content directory on every page.
- Create
privatus.jsin the root of your docs repo:
const s = document.createElement('script')
s.defer = true
s.src = 'https://privatusstats.com/js/pa.js'
s.setAttribute('data-site', 'pa_YOURSITEID')
s.setAttribute('data-modules', 'engage,auto,vitals,clicks,ask')
document.head.appendChild(s)
- Commit and push. Mintlify deploys it with the rest of your docs.
Mintlify's docs say custom scripts run after the page becomes interactive,
can't be limited to some pages and run once per visit. That suits the
tracker, which follows history.pushState navigations itself, so you don't
need the mintlify:navigate event. Set each
attribute before the element is added.
If your site sets a Content Security Policy, allow the tracker host. Mintlify has a separate page on that setting.
Preview deployments use other hostnames and are dropped unless you add them as an additional domain.