Skip to Content
InstallationWordPress

WordPress Installation

Install Ghost Metrics on your WordPress website.

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
WordPress6.4
PHP8.1

If your site can’t meet these requirements, use the manual method below.

Install the plugin

  1. Download the plugin (this link always serves the latest version):

    ghost-metrics-latest.zip 

  2. In your WordPress admin, go to Plugins → Add New Plugin → Upload Plugin, choose the zip you downloaded, click Install Now, then Activate.

  3. Open Ghost Metrics in the admin menu and enter:

    • Instance addressyourname.ghostmetrics.cloud
    • API token — from your Ghost Metrics welcome email

    The plugin verifies the token, detects your site, and selects your tracking container automatically.

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.

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)

  1. In your WordPress admin, go to PluginsAdd New Plugin
  2. Search for “WPCode”
  3. Install and activate WPCode (listed as “WPCode – Insert Headers and Footers + Custom Code Snippets”)
  4. Go to Code SnippetsHeader & Footer
  5. 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 -->
  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 the scope to Only run on site front-end
  2. 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.

  1. Go to AppearanceTheme File Editor (or Tools → Theme File Editor on block themes)
  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

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.

Next Steps

Last updated on