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
- Go to tagmanager.google.com
- Select your account and container
- Make sure you’re in the correct workspace
Step 2: Create a New Tag
- Click Tags in the left sidebar
- Click New to create a new tag
- Name your tag “Ghost Metrics” (or something descriptive)
Step 3: Configure the Tag
- Click Tag Configuration
- Select Custom HTML from the tag type list
- Leave Support document.write unchecked — the Ghost Metrics snippet doesn’t use it
- 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
- Click Triggering below the tag configuration
- Select All Pages
- 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.)
Consent Management
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:
- Click Preview in the top right — Tag Assistant opens in a new tab
- Enter your website URL and click Connect
- Navigate through your site in the connected window
- 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:
- Click Submit in the top right
- Add a version name (e.g., “Added Ghost Metrics tracking”)
- Click Publish
Verify in Ghost Metrics
After publishing:
- Visit your website
- Open Ghost Metrics and go to Visitors → Real-time
- 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:
- Your site pushes an event:
dataLayer.push({'event': 'form_submit', 'formName': 'Contact Form'}); - In GTM, create a Custom Event trigger with event name
form_submit - Create a Data Layer Variable for
formName - 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