Skip to content

Install GoodMetrics on WordPress

Add the GoodMetrics tracking script to any WordPress site — works with every theme, including block (full site editing) and page-builder themes.

You can add GoodMetrics to any WordPress site by placing your tracking script in the site’s <head>. The recommended method below works with every theme and page-builder.

First, you’ll need your unique tracking script. If you don’t have it yet, here’s how to retrieve it. It looks like this:

<script id="gmScript" data-gm="XXXXXXXX" src="https://cdn.goodmetrics.io/goodmetrics.min.js"></script>

💡 Your data-gm ID is unique to your site, so copy your own script from your site settings rather than the example above.

Section titled “Recommended: add the script with a header plugin”

A header/footer plugin injects your script into the <head> of every page. It works on any theme, survives theme switches and updates, and requires no code editing — which makes it the safest option for most sites.

We’ll use the free WPCode plugin (the most widely used option), but any “header and footer scripts” plugin follows the same steps.

  1. In your WordPress dashboard, go to Plugins → Add New.
  2. Search for WPCode (formerly Insert Headers and Footers). Choose Install Now, then Activate.
  3. Go to Code Snippets → Header & Footer.
  4. Paste your GoodMetrics script into the Header box.
  5. Choose Save Changes.

That’s it — your script now loads on every page. Skip to Verify your installation.

Alternative: use your theme’s built-in header field

Section titled “Alternative: use your theme’s built-in header field”

Some popular page-builder themes include a built-in field for <head> code, so you can add GoodMetrics without a plugin:

  • Divi — Go to Divi → Theme Options → Integration, enable Add code to the < head > of your blog, paste your script into that box, and Save Changes.
  • Avada — Go to Avada → Options → Advanced → Code Fields, paste your script into Space Before </head>, and Save Changes.

If your theme has its own header scripts, custom code, or header & footer setting, you can paste the script there instead. When in doubt, use the plugin method above — it’s the most reliable.

Advanced: add it in your theme files (developers)

Section titled “Advanced: add it in your theme files (developers)”

If you’re comfortable editing theme code, you can add the script with the wp_head action. Do this in a child theme (or a code snippet plugin) so your change isn’t lost when the theme updates:

add_action('wp_head', function () {
echo '<script id="gmScript" data-gm="XXXXXXXX" src="https://cdn.goodmetrics.io/goodmetrics.min.js"></script>';
});

Replace XXXXXXXX with your unique data-gm ID.

Block themes (full site editing): themes like Twenty Twenty-Four have no header.php to edit, so use the plugin method instead.

  1. Visit your website.
  2. In GoodMetrics, open the Realtime report.
  3. Confirm that your visit appears in the report.

If you don’t see your visit:

  • Confirm the script was saved and that you published any plugin or theme changes.
  • Check that you replaced the data-gm ID with your own.
  • If you use a caching plugin (e.g. WP Rocket, W3 Total Cache, LiteSpeed Cache), clear your site cache and try again.
  • Still stuck? Contact us and we’ll be happy to help.