Add Antlytics to MkDocs
Prerequisites
- An Antlytics account (sign up free)
- Your tracking ID from Settings → Tracking Snippet in your Antlytics dashboard
Install the snippet
MkDocs Material and most other MkDocs themes support custom template overrides.
Step 1 — Enable the overrides directory
In mkdocs.yml, add a custom_dir under theme:
# mkdocs.yml
theme:
name: material # or your active theme
custom_dir: overrides
Step 2 — Create the override template
Create overrides/main.html and extend the base template to inject the snippet:
<!-- overrides/main.html -->
{% extends "base.html" %}
{% block scripts %}
{{ super() }}
<script>
(function(){
var t="YOUR-SITE-ID",
u="https://www.antlytics.com/api/ingest/pageview",
k="ant_sid";
function sid(){
try{var s=sessionStorage.getItem(k);if(s)return s;
s=crypto.randomUUID();sessionStorage.setItem(k,s);return s;}
catch(e){return crypto.randomUUID();}
}
function utm(){
try{var p=new URLSearchParams(location.search),o={};
["utm_source","utm_medium","utm_campaign","utm_term","utm_content"]
.forEach(function(k){var v=p.get(k);if(v)o[k]=v;});
return o;}
catch(e){return {};}
}
function send(){
fetch(u,{method:"POST",headers:{"Content-Type":"application/json"},
keepalive:true,
body:JSON.stringify(Object.assign(
{tracking_id:t,pathname:location.pathname,
referrer:document.referrer||undefined,session_id:sid()},
utm()))});
}
send();
window.addEventListener("popstate",send);
})();
</script>
{% endblock %}
Note: Replace
YOUR-SITE-IDwith the tracking ID from your Antlytics dashboard.
{{ super() }} preserves all existing scripts from the base theme. The Antlytics snippet is appended after them.
For themes other than Material, check the theme's documentation for the correct block name and whether custom_dir is supported.
Verify installation
- Visit your site in a browser.
- Open your Antlytics dashboard → Overview.
- Your visit should appear within a few seconds.
If data does not appear after a few minutes, check the troubleshooting guide.
Optional: First-party proxy
To avoid ad blockers, set up a first-party proxy on your own domain.
Need help?
Email support@antlytics.com with your site ID and page URL.
Something missing? Get in touch and we will update these docs.