WordPress
There are two ways to add the Antlytics snippet to a WordPress site. Pick the one that matches how you manage your theme.
Prerequisites
- An Antlytics account and at least one site created in your dashboard
- The tracking ID (UUID) from Settings → Tracking Snippet
- Administrator access to your WordPress site
Option A — Theme editor (classic themes)
If you are using a classic (non-block) theme and have access to the theme editor:
- In your WordPress admin, go to Appearance → Theme File Editor.
- Open
header.phpfrom the file list on the right. - Locate the closing
</head>tag. - Paste the snippet immediately before
</head>:
<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>
- Replace
YOUR_SITE_IDwith your tracking ID from the Antlytics dashboard. - Click Update File.
Note: If you update your theme, the edit to
header.phpmay be overwritten. Use a child theme or switch to Option B to avoid losing it.
Option B — Header-scripts plugin (block themes or safer alternative)
If you are using a block theme (e.g. Twenty Twenty-Four) or want a change that survives theme updates, use a plugin that adds code to your site's <head>. Search the WordPress plugin directory for "header footer scripts" or "custom head code" — there are several free options.
Once installed:
- Open the plugin's settings page.
- Paste the snippet (with
YOUR_SITE_IDreplaced) into the header or<head>field. - Save. No need to touch any theme files.
Caching plugins
If your site uses a caching plugin (e.g. WP Super Cache, W3 Total Cache, WP Rocket), the script tag is static HTML and requires no special configuration — it will be cached along with the rest of the page and will still fire correctly in the browser. No special exclusion rules are needed.
Verify data is flowing
Visit your live WordPress site in a browser, then check the real-time count in your Antlytics dashboard. Data appears within seconds.
Troubleshooting
- Open the browser Network tab and look for a
POSTto/api/ingest/pageview. A200response means the snippet fired correctly. - Confirm the tracking ID matches Settings → Tracking Snippet in your Antlytics dashboard.
- Test in an incognito window if you have an ad blocker installed, or set up the first-party proxy.
See Troubleshooting for more common issues.