WordPress Installation
Install Ghost Metrics on your WordPress website.
Option 1: Official Plugin (Recommended)
The Ghost Metrics plugin connects your site to your Ghost Metrics instance, installs tracking automatically on every page, measures AI assistants (ChatGPT, Claude, Perplexity, and others) server-side, and surfaces your analytics right inside WordPress admin — no code required.
Requirements
| Minimum | |
|---|---|
| WordPress | 6.4 |
| PHP | 8.1 |
If your site can’t meet these requirements, use the manual method below.
Install the plugin
-
Download the plugin (this link always serves the latest version):
-
In your WordPress admin, go to Plugins → Add New Plugin → Upload Plugin, choose the zip you downloaded, click Install Now, then Activate.
-
Open Ghost Metrics in the admin menu and enter:
- Instance address —
yourname.ghostmetrics.cloud - API token — from your Ghost Metrics welcome email
The plugin verifies the token, detects your site, and selects your tracking container automatically.
- Instance address —
That’s it — tracking is live on every page of your site.
What you get
- Automatic tracking — the tracking snippet is injected on every front-end page; you never touch code or templates.
- AI-assistant visibility — AI assistants don’t run JavaScript, so snippet-based tracking never sees them. The plugin detects them server-side and records their visits with privacy-safe URLs.
- Reports in WordPress — visits, top pages, traffic sources, and referrers in the Ghost Metrics admin screen, plus an at-a-glance widget on your WordPress dashboard.
- Security built in — your API token is encrypted at rest and is never exposed to browsers.
Updates
The plugin updates like any other WordPress plugin — update notices appear under Dashboard → Updates and on the Plugins screen, and updating is one click. Your site checks for new versions automatically twice a day (or immediately when you click Check again on the Updates screen). No configuration needed.
Cookie consent
If you use a consent plugin (Complianz, CookieYes, etc.), enable require
consent in the Ghost Metrics settings. Tracking then waits for your
consent plugin’s approval before running, so your analytics behave the way
your privacy policy promises. Developers can integrate any consent tool via
the ghost_metrics_has_consent filter.
Caching plugins
Page caching (WP Rocket, W3 Total Cache, LiteSpeed Cache, etc.) works fine
with the plugin. Just purge your caches once after activating —
including any CDN cache — so previously cached pages pick up the tracking
snippet. If you use aggressive JavaScript optimization (e.g., WP Rocket’s
“Delay JavaScript execution”), add your ghostmetrics.cloud domain to the
exclusion list. Note that AI-assistant tracking is unaffected by caching or
JS optimization either way — it happens server-side.
Option 2: Manual Tracking Code
If your site can’t run the official plugin (older WordPress or PHP), you can install the tracking snippet manually. Note that manual installation provides browser tracking only — server-side AI-assistant tracking, in-admin reports, and automatic updates require the plugin.
Using WPCode (easiest manual method)
- In your WordPress admin, go to Plugins → Add New Plugin
- Search for “WPCode”
- Install and activate WPCode (listed as “WPCode – Insert Headers and Footers + Custom Code Snippets”)
- Go to Code Snippets → Header & Footer
- Paste your Ghost Metrics tracking code in the Header box — this places it in the
<head>of every page, which is exactly where it belongs:
<!-- 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 the scope to Only run on site front-end
- Save and activate the snippet
Using your theme’s functions.php
Important: Use a child theme to prevent losing changes when your theme updates. Note that modern block themes (Twenty Twenty-Four and later) put the file editor under Tools → Theme File Editor, and many hosts disable the file editor entirely for security — if you don’t see it, use WPCode instead.
- Go to Appearance → Theme File Editor (or Tools → Theme File Editor on block themes)
- 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
We don’t recommend editing header.php directly: changes are lost when
the theme updates, a typo can break your site, and block themes don’t have
a header.php at all.
Manual installation notes
- Caching: purge all caches (plugin + CDN) after adding the snippet, and exclude the Ghost Metrics domain from JavaScript delay/combine features in optimization plugins.
- Consent plugins may block unrecognized scripts until consent is given — categorize the Ghost Metrics snippet appropriately so tracking behaves the way your privacy policy intends.
WordPress Multisite
- Official plugin: install the plugin network-wide or per site, then activate and connect each site individually — every site gets its own connection to your Ghost Metrics instance so its analytics stay separate.
- Manual snippet: network-activate a snippets plugin such as WPCode and add each site’s own tracking code individually (or network-wide via a shared mu-plugin if all sites report to one container).
Contact support if you need help configuring tracking for a Multisite network.