New: Free plan is live 7 August 2026 · View changelog →
Antlytics logoAntlytics

WordPress

There are two ways to add the Antlytics snippet to a WordPress site. Pick the one that matches how you manage your theme.

Prefer the hosted tracker.js snippet below (or the Antlytics WordPress plugin 1.1.0+). Both load the same CDN tracker so pageviews, engagement, and SPA navigations stay current.

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:

  1. In your WordPress admin, go to Appearance → Theme File Editor.
  2. Open header.php from the file list on the right.
  3. Locate the closing </head> tag.
  4. Paste the snippet immediately before </head>:
<script
  defer
  src="https://www.antlytics.com/tracker.js"
  data-tracking-id="YOUR_SITE_ID"
  data-api-host="https://www.antlytics.com"
></script>
  1. Replace YOUR_SITE_ID with your tracking ID from the Antlytics dashboard.
  2. Click Update File.

Note: If you update your theme, the edit to header.php may 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:

  1. Open the plugin's settings page.
  2. Paste the snippet (with YOUR_SITE_ID replaced) into the header or <head> field.
  3. 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.

Also confirm the site URL in Antlytics matches how visitors reach you (for example https://themortgageroom.com.au vs https://www.themortgageroom.com.au). Hostname shields and strict origin use that URL.

Troubleshooting

  • Open the browser Network tab and look for a POST to /api/ingest/pageview. A 200 response means the snippet fired correctly.
  • On hide or unload you should also see a request to /api/ingest/engagement (scroll depth + active time). If pageviews succeed but engagement shows a CORS error about Access-Control-Allow-Origin: *, hard-refresh so the browser loads the latest tracker.js, or update the Antlytics WordPress plugin to 1.1.0+.
  • 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.

Something missing? Get in touch and we will update these docs.