Skip to Content
InstallationWordPress

WordPress Installation

Install Ghost Metrics on your WordPress website.

Coming Soon: Official Plugin

We’re currently developing an official Ghost Metrics plugin for WordPress that will make installation and configuration even easier. Stay tuned for updates.

In the meantime, you can install Ghost Metrics using one of the methods below.


The safest and easiest method is using a code snippets plugin like WPCode or Code Snippets.

Using WPCode

  1. In your WordPress admin, go to PluginsAdd New
  2. Search for “WPCode”
  3. Install and activate WPCode – Insert Headers and Footers
  4. Go to Code SnippetsHeader & Footer
  5. Paste your Ghost Metrics tracking code in the Header section:
<!-- Ghost Metrics Tag Manager --> <script> var _mtm = window._mtm = window._mtm || []; _mtm.push({'mtm.startTime': (new Date().getTime()), 'event': 'mtm.Start'}); (function() { var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0]; g.async=true; g.src='https://example.ghostmetrics.cloud/js/container_XXXXXXXX.js'; s.parentNode.insertBefore(g,s); })(); </script> <!-- End Ghost Metrics Tag Manager -->
  1. Click Save Changes

Using Code Snippets Plugin

  1. Install and activate the Code Snippets plugin
  2. Go to SnippetsAdd New
  3. Name it “Ghost Metrics Tracking”
  4. Add this PHP code:
add_action('wp_head', function() { ?> <!-- Ghost Metrics Tag Manager --> <script> var _mtm = window._mtm = window._mtm || []; _mtm.push({'mtm.startTime': (new Date().getTime()), 'event': 'mtm.Start'}); (function() { var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0]; g.async=true; g.src='https://example.ghostmetrics.cloud/js/container_XXXXXXXX.js'; s.parentNode.insertBefore(g,s); })(); </script> <!-- End Ghost Metrics Tag Manager --> <?php });
  1. Set it to run “Only on the front end”
  2. Save and activate the snippet

Option 2: Theme Functions File

Add tracking code via your theme’s functions.php file.

Important: Use a child theme to prevent losing changes when your theme updates.

  1. Go to AppearanceTheme File Editor
  2. Select your child theme’s functions.php
  3. Add this code at the end:
/** * Ghost Metrics Tracking Code */ function ghost_metrics_tracking_code() { ?> <!-- Ghost Metrics Tag Manager --> <script> var _mtm = window._mtm = window._mtm || []; _mtm.push({'mtm.startTime': (new Date().getTime()), 'event': 'mtm.Start'}); (function() { var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0]; g.async=true; g.src='https://example.ghostmetrics.cloud/js/container_XXXXXXXX.js'; s.parentNode.insertBefore(g,s); })(); </script> <!-- End Ghost Metrics Tag Manager --> <?php } add_action('wp_head', 'ghost_metrics_tracking_code');
  1. Click Update File

You can edit your theme’s header.php directly, but this is not recommended because:

  • Changes are lost when the theme updates
  • It’s easy to break your site with a typo

If you must use this method, add the tracking code just before the closing </head> tag in your theme’s header.php file.


Caching Considerations

If you use a caching plugin (WP Rocket, W3 Total Cache, LiteSpeed Cache, etc.), the tracking code will still work normally since it loads asynchronously.

However, after adding the tracking code:

  1. Clear your caching plugin’s cache
  2. Clear any CDN cache (Cloudflare, etc.)
  3. Test in an incognito/private browser window

WordPress Multisite

For WordPress Multisite installations, you have two options:

  • Network-wide tracking: Add the code at the network level to track all sites
  • Per-site tracking: Add unique tracking codes to each site individually

Contact support if you need help configuring tracking for a Multisite network.

Next Steps

Last updated on