Skip to Content
InstallationGoogle Tag Manager

Google Tag Manager Installation

Install Ghost Metrics using Google Tag Manager (GTM).

Prerequisites

Before you begin, make sure you have:

  • A Google Tag Manager account with access to publish changes
  • Your Ghost Metrics tracking code from the dashboard
  • GTM container already installed on your website

Step 1: Open Your GTM Container

  1. Go to tagmanager.google.com 
  2. Select your account and container
  3. Make sure you’re in the correct workspace

Step 2: Create a New Tag

  1. Click Tags in the left sidebar
  2. Click New to create a new tag
  3. Name your tag “Ghost Metrics” (or something descriptive)

Step 3: Configure the Tag

  1. Click Tag Configuration
  2. Select Custom HTML from the tag type list
  3. Leave Support document.write unchecked — the Ghost Metrics snippet doesn’t use it
  4. Paste your 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 -->

Replace example.ghostmetrics.cloud and container_XXXXXXXX.js with the values from your Ghost Metrics dashboard.

Step 4: Set Your Trigger

  1. Click Triggering below the tag configuration
  2. Select All Pages
  3. Click Save

All Pages is the right trigger for analytics. (The “Initialization” triggers exist for consent and setup logic that must run before every other tag — they aren’t needed here.)

Custom HTML tags don’t get GTM’s built-in consent checks. If your site uses a consent platform with GTM Consent Mode, open the tag’s Advanced Settings → Consent Settings and require the appropriate consent (typically analytics_storage) so the Ghost Metrics tag respects your visitors’ choices.

Step 5: Preview and Test

Before publishing:

  1. Click Preview in the top right — Tag Assistant opens in a new tab
  2. Enter your website URL and click Connect
  3. Navigate through your site in the connected window
  4. Verify the Ghost Metrics tag appears under Tags Fired for each page in Tag Assistant

Step 6: Publish

Once you’ve confirmed the tag is firing:

  1. Click Submit in the top right
  2. Add a version name (e.g., “Added Ghost Metrics tracking”)
  3. Click Publish

Verify in Ghost Metrics

After publishing:

  1. Visit your website
  2. Open Ghost Metrics and go to VisitorsReal-time
  3. You should see your visit appear within seconds

Single Page Applications

If your site is an SPA, do not re-fire the Ghost Metrics container tag on GTM’s History Change trigger — that would inject the container repeatedly. Instead, create a separate Custom HTML tag on a History Change trigger that tracks the virtual pageview:

<script> _paq.push(['setCustomUrl', window.location.href]); _paq.push(['setDocumentTitle', document.title]); _paq.push(['trackPageView']); </script>

Event Tracking with GTM

To track custom events through GTM, pair a data-layer push with a trigger and tag:

  1. Your site pushes an event: dataLayer.push({'event': 'form_submit', 'formName': 'Contact Form'});
  2. In GTM, create a Custom Event trigger with event name form_submit
  3. Create a Data Layer Variable for formName
  4. Create a Custom HTML tag fired by that trigger:
<script> _paq.push(['trackEvent', 'Form', 'Submit', {{DLV - formName}}]); </script>

The push alone does nothing without the trigger and tag. Alternatively, configure event tracking in the Ghost Metrics container itself and skip GTM for events entirely — contact support if you’d like help choosing.

Troubleshooting

Tag Not Firing

  • Check that your trigger is set to “All Pages”
  • Verify the container is published (not just in preview mode)
  • Clear your browser cache and try again

Data Not Appearing in Ghost Metrics

  • Confirm the tracking code has the correct domain and container ID
  • Check for JavaScript errors in your browser’s developer console
  • Verify your GTM container is installed on the website

Next Steps

Last updated on