Plain HTML / vanilla JS
Works with any site that lets you add a <script> tag — static HTML, GitHub Pages, Squarespace custom code, or any CMS with a custom head field.
Prerequisites
- An Antlytics account and at least one site created in your dashboard
- The tracking ID (UUID) from Settings → Tracking Snippet
1. Copy your tracking ID
Sign in to your Antlytics dashboard and open Settings → Tracking Snippet. The snippet shown there is pre-filled with your tracking ID for the selected site.
2. Add the snippet to your <head>
Paste the block below into the <head> of every page you want to track. Replace YOUR_SITE_ID with the UUID from your dashboard.
<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>
Prefer copying the exact snippet from Settings → Tracking Snippet in your dashboard — it always matches the live generator output.
3. Verify data is flowing
Open your live site in a browser, then check the real-time count in your Antlytics dashboard. Data appears within seconds. Full traffic charts refresh on page reload.
What the snippet does
- Sends one pageview on initial load.
- Re-fires on
popstateso client-side navigation (e.g. SPA routing) is captured. - Reads UTM parameters from the current URL automatically.
- No cookies are set. The session ID lives only in
sessionStorageand clears when the tab closes.
Troubleshooting
If data does not appear after a few minutes:
- Check the browser Network tab for a
POSTto/api/ingest/pageview— the response should be200. - Confirm the tracking ID in the snippet matches the one in Settings → Tracking Snippet.
- If you use an ad blocker in your own browser, test in an incognito window, or set up the first-party proxy.
- Check that nothing in your
<head>blocks inline scripts (CSP headers or a script-blocking plugin).
See Troubleshooting for more common issues.