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

WordPress Analytics Without a Plugin

A script tag in your theme is simpler than a plugin. Here's how to add privacy-friendly analytics to WordPress without installing a plugin.

WordPress Analytics Without a Plugin

WordPress has a plugin for everything. But for analytics, a script tag in your theme is often simpler, faster to install, and less prone to conflicts than a plugin.

Why skip the plugin

WordPress plugins add code to your site on every page load — not just the pages that need them. A well-maintained plugin is fine, but many WordPress analytics plugins:

A direct script tag in your theme:

Method 1: Theme editor (simplest)

  1. In your WordPress admin, go to Appearance → Theme Editor (or Appearance → Theme File Editor in newer WordPress versions).
  2. Open your theme's header.php file.
  3. Find the </head> closing tag.
  4. Add the tracking snippet immediately before </head>.
<?php /* Antlytics — get your tracking ID from https://www.antlytics.com */ ?>
<script
  defer
  src="https://www.antlytics.com/tracker.js"
  data-tracking-id="YOUR_TRACKING_ID"
  data-api-host="https://www.antlytics.com"
></script>

Replace YOUR_TRACKING_ID with the UUID from your Antlytics dashboard. Same snippet as the WordPress docs and Quick start.

Note: Theme updates can overwrite header.php. Use a child theme, or Method 2 / a header-scripts plugin, so the snippet survives updates.

Method 2: functions.php

A cleaner approach that does not modify your theme's HTML template directly:

// Add to your theme's functions.php
function antlytics_tracking_script() {
    $tracking_id = 'YOUR_TRACKING_ID'; // Replace with your UUID
    ?>
    <script
      defer
      src="https://www.antlytics.com/tracker.js"
      data-tracking-id="<?php echo esc_attr($tracking_id); ?>"
      data-api-host="https://www.antlytics.com"
    ></script>
    <?php
}
add_action('wp_head', 'antlytics_tracking_script');

This uses WordPress's wp_head action to inject the script into the <head> on every page.

Verifying

  1. Visit your WordPress site in a browser without ad-blocker extensions.
  2. Open browser dev tools → Network tab.
  3. Confirm tracker.js loads and a POST request to /api/ingest/pageview appears.
  4. Check your Antlytics dashboard for a new visitor.

Caching considerations

If you use a caching plugin (WP Rocket, W3 Total Cache, or similar), the script will be cached as part of your theme's HTML. This is fine — the script tag is static and can be safely cached.

Do not add the tracking script to areas that are excluded from caching (like dynamic AJAX responses) — it should be in your page's <head>.

FAQ

Will this work with page builders? Yes. Page builders like Elementor and Divi still use WordPress's standard theme structure. The wp_head method works with all page builders.

What about Gutenberg (block editor) themes? Block themes use theme.json and block templates instead of PHP templates. Use the functions.php method (Method 2), or a header-scripts plugin, as they work regardless of theme type.

Should I use a child theme? Yes, if you are modifying header.php directly. A child theme prevents your changes from being overwritten on theme updates. The functions.php method should also go in a child theme's functions.php.

Does this work with WordPress multisite? Yes, but each site in a network needs its own tracking ID and snippet. Add the snippet separately to each site's theme or use a network-level plugin to manage it.


Related: WordPress docs · Quick start guide · Antlytics implementation guides