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.
Option 1: Code Snippets Plugin (Recommended)
The safest and easiest method is using a code snippets plugin like WPCode or Code Snippets.
Using WPCode
- In your WordPress admin, go to Plugins → Add New
- Search for “WPCode”
- Install and activate WPCode – Insert Headers and Footers
- Go to Code Snippets → Header & Footer
- 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 -->- Click Save Changes
Using Code Snippets Plugin
- Install and activate the Code Snippets plugin
- Go to Snippets → Add New
- Name it “Ghost Metrics Tracking”
- 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
});- Set it to run “Only on the front end”
- 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.
- Go to Appearance → Theme File Editor
- Select your child theme’s
functions.php - 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');- Click Update File
Option 3: Header.php (Not Recommended)
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:
- Clear your caching plugin’s cache
- Clear any CDN cache (Cloudflare, etc.)
- 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.