# Integrate Google Tag Manager with Google Analytics

**URL:** https://meta.discourse.org/t/integrate-google-tag-manager-with-google-analytics/47335
**Category:** Integrations
**Tags:** how-to, analytics, platforms
**Created:** [July 14, 2016, 9:34pm UTC](https://meta.discourse.org/t/integrate-google-tag-manager-with-google-analytics/47335 "2016-07-14T21:34:57Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Discourse](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/discourse/32/148734_2.png) [@Discourse](https://meta.discourse.org/u/Discourse)
#### Post date: [July 14, 2016, 9:34pm UTC](https://meta.discourse.org/t/integrate-google-tag-manager-with-google-analytics/47335/1 "2016-07-14T21:34:57Z")

</div>

> 🔖 This guide will help you set up Google Tag Manager and use it with Google Analytics on your Discourse site. Additionally, it covers configuring variables, triggers, and tags in Google Tag Manager to track page views.
> 
> ℹ This guide covers setting up Google Tag Manager. If you only want to enable Google Analytics for your site, set the G-Tag in the `ga universal tracking code` site setting. Our settings may still refer to all analytics as `universal`, but this is a legacy field naming artifact. The following instructions use, and work for, Google Tags.
> 
> 🙋 Required user level: Administrator

Integrating Google Tag Manager (GTM) with Google Analytics (GA) allows you to manage and track events on your Discourse site effectively. This guide covers the full setup process, from creating a GA account to configuring GTM with the necessary tags and triggers.

## Summary

1. Create a Google Analytics account and property.
2. Set up Google Tag Manager.
3. Configure GTM variables, triggers, and tags.
4. Integrate GTM with your Discourse site.

## Create a Google Analytics account

1. Visit [Google Analytics](https://analytics.google.com) and sign in with your Google account.

2. If you don’t have an account yet, follow the guided steps to create one.

3. Create a property by clicking on “Admin” and then “Create Property”.  

4. Fill in the required details on the “Property creation” screen.  

5. Enter your business details on the next screen.  

6. Select your business objectives appropriately.

> ℹ **Info:** Selecting the four sections will most closely match the reports Analytics has typically provided:

 ![Business objectives screen](https://global.discourse-cdn.com/meta/original/4X/2/d/3/2d3debc5ba1fff41712bd63efd0b0e73fb525b35.png)

7. Choose “Web” as the platform for data collection.

 ![Data collection screen](https://global.discourse-cdn.com/meta/original/4X/7/9/e/79e54500312bb73dd58095f2e151c5cb16abcca5.png)

1. Set up a data stream by entering your site’s URL and a stream name.  
 ![Data stream setup](https://global.discourse-cdn.com/meta/original/4X/d/e/9/de94ace1ff23e29ed76650ed3f6f91c950cf4448.png)

> ℹ After successfully creating your web stream, make a note of your Measurement ID. You’ll need this for GTM setup.

## Set up Google Tag Manager

1. Visit [Google Tag Manager](https://tagmanager.google.com) and create an account.
2. Set up a container by following the guided steps, and choose “Web” as the platform.  
 ![Create container](https://global.discourse-cdn.com/meta/original/4X/c/d/4/cd4d81681bdb60640cdc174d7d54e9dd33f1496b.png)

## Configure GTM

### Variables

1. Go to the “Variables” tab in GTM and click “New” in the User-Defined Variables section.
2. Create two Data Layer Variables:

- **Title** : `DL-page-title`  
**Type** : `Data Layer Variable`  
**Data Layer Variable Name** : `page.title`  
**Data Layer Version** : 2

- **Title** : `DL-page-url`  
**Type** : `Data Layer Variable`  
**Data Layer Variable Name** : `page.url`  
**Data Layer Version** : 2

As an example, choose the variable type:

 ![Choose variable type](https://global.discourse-cdn.com/meta/original/4X/2/5/c/25c28e5afe4a07f9437e124d1dce32fe5c698ce7.png)

Then configure the variables, as in this example:

 ![ga4_2024-06_gtm-dl-page-title](https://global.discourse-cdn.com/meta/original/4X/6/9/7/697c58e647c25ad315baf197a249d0c8a8bcb995.png)

### Triggers

1. Go to the “Triggers” tab and click “New”.

2. Choose “Custom Event” as the type.

3. Name the trigger `virtualPageView` and Save it.

### Tags

1. Go to the “Tags” tab and create a new tag.

2. Choose `Google Analytics: Google Tag` as the tag type.  

3. Configure the tag with the following details:

- **Measurement ID** : Enter your Measurement ID from GA.
- **Required Fields to Set** :
  - `title`: `{{DL-page-title}}`
  - `page`: `{{DL-page-url}}`
  - `send_page_view`: `true`
  - `page_path`: `{{Page Path}}`

When finished it should look like this (note that you can add a `userID` parameter in addition to the parameters above, but you will need to add an additional variable like `DL-page-url`.):

 ![GTM tags setup](https://global.discourse-cdn.com/meta/original/4X/8/7/5/875bf3b9738314869fe688c6d5f224084949c960.png)

1. Choose the `virtualPageView` trigger for this tag.  
 ![Tag trigger](https://global.discourse-cdn.com/meta/original/4X/f/1/e/f1e852c6bff33d07fa0abef99e2f7ba89c4f065c.png)
2. Name your tag and Save it.

### Publish your GTM workspace

Publish your container in GTM by clicking the blue “Submit” button in the upper-right corner of the page.

> ⚠ **Important:** If you encounter 404 errors from `googletagmanager.com`, ensure your GTM container changes have been published.

## Integrate GTM with Discourse

1. Go to your Discourse Admin settings and search for `gtm container id`.
2. Enter your GTM Container ID (format: `GTM-XXXXXX`) in the corresponding field.  
 ![Discourse GTM setup](https://global.discourse-cdn.com/meta/original/4X/8/3/b/83b2927b2df7d692024bfe4eafd081969cde6c57.png)

> ⚠ **Note:** Remove any existing Analytics tracking code from the `ga universal tracking code` setting in Discourse when using GTM, to avoid duplicate tracking.

Reload your site and check the Real-Time content view in GA to confirm that data is flowing through GTM.

## Additional Uses

With GTM, you can add more tags to track additional events such as:

- [Google DFP](https://github.com/discourse/discourse-adplugin)
- AdWords
- LinkedIn

## Related Links

- [Using nonces in Google Tag Manager scripts](https://meta.discourse.org/t/use-nonces-in-google-tag-manager-scripts/188296)
- [Push custom events to Google Tag Manager and Analytics](https://meta.discourse.org/t/push-custom-events-to-google-tag-manager-and-analytics/181552)
- [How to add Google Auto Ads to Discourse via Google Tag Manager](https://meta.discourse.org/t/how-to-add-google-auto-ads-to-discourse-via-google-tag-manager/126308)

> Last edited by @MarkDoerr 2026-05-12T01:58:41Z
> 
> > **Check document**
> >
> > Perform check on document:

---

<div class="post-metadata">

### Author: ![MarkDoerr](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/markdoerr/32/549630_2.png) [@MarkDoerr](https://meta.discourse.org/u/MarkDoerr)
#### Post date: [April 24, 2024, 1:14am UTC](https://meta.discourse.org/t/integrate-google-tag-manager-with-google-analytics/47335/89 "2024-04-24T01:14:36Z")

</div>

As noted, the GA4 Configuration tag has been removed and you’ll now choose the Google Tag. The setup steps remain the same, but I have updated the documentation.

For anyone who had previously setup the GA4 tag, it should’ve been updated automatically and require no changes on your end.

---

<div class="post-metadata">

### Author: ![Stefan\_Holmes](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/stefan_holmes/32/436043_2.png) [@Stefan\_Holmes](https://meta.discourse.org/u/Stefan_Holmes)
#### Post date: [August 1, 2024, 9:42am UTC](https://meta.discourse.org/t/integrate-google-tag-manager-with-google-analytics/47335/94 "2024-08-01T09:42:17Z")

</div>

Worth mentioning this is not an optimal setup in terms of current GA4/ GTM best practices and the step #2 in the Triggers section seems to be incorrect.

Instead of a Page View trigger, this should be a Custom Event trigger with the name `virtualPageView`.

`cookieDomain = auto` seems to be a holdover from Universal Analytics and isn’t needed. GA4 automatically deals with subdomain navigation.

Another best practise is to have the Google Tag fire on Initialization, have `send_page_view` set to `false` and instead have a separate GA4 Event tag for `page_view`

When we implemented we also added an override for `page_location` with the full URL of the site + virtual page path. This will populate standard GA4 reports correctly.

---

<div class="post-metadata">

### Author: ![MarkDoerr](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/markdoerr/32/549630_2.png) [@MarkDoerr](https://meta.discourse.org/u/MarkDoerr)
#### Post date: [August 1, 2024, 10:03am UTC](https://meta.discourse.org/t/integrate-google-tag-manager-with-google-analytics/47335/95 "2024-08-01T10:03:08Z")

</div>

Hi Stefan,

Thanks for these notes.

I’ve updated step #2 of the Triggers section as I already had screenshots to match, and we’ll get the rest of this updated as soon as possible.

---

<div class="post-metadata">

### Author: ![luigi7up](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/luigi7up/32/477213_2.png) [@luigi7up](https://meta.discourse.org/u/luigi7up)
#### Post date: [January 26, 2025, 5:47pm UTC](https://meta.discourse.org/t/integrate-google-tag-manager-with-google-analytics/47335/99 "2025-01-26T17:47:40Z")

</div>

**Description** :

I’m facing an issue with Google Tag Manager (GTM) on my Discourse forum. Let me explain my setup and the problem in detail:

1. **GTM Setup** :

• I have set up a Google Tag Manager container (ID: GTM-…MZV).

• For testing purposes, I’ve added a **Google Analytics 4 tag** in GTM, configured to fire on all pages during initialization.

• I haven’t added any complex triggers, user layer, or data layer. It’s just a basic configuration to verify GTM is working.

1. **GTM Integration with Discourse** :

• In my Discourse forum, I’ve configured GTM by entering the container ID (GTM-W…MZV) in the **Admin settings**.

• When I inspect my website, I can see that:

• The GTM script ([https://www.googletagmanager.com/gtm.js?id=GTM-W...MZV](https://www.googletagmanager.com/gtm.js?id=GTM-W...MZV)) is being loaded in the section.

• There are no errors in the browser console or the **Network** tab related to GTM or gtm.js.

1. **The Problem** :

• After publishing my GTM container, I went to **Preview Mode** in Google Tag Manager and entered my website URL ([https://forum.hobiguru.com](https://forum.hobiguru.com)).

• However, the GTM Preview Debugger says that **no GTM tag was found** on my site.

• Despite gtm.js loading and no visible errors, the debugger is not recognizing the GTM setup.

**Screenshots** :

• Screenshot 1: GTM container setup in Google Tag Manager (showing the GA4 tag and triggers).

• Screenshot 2: Discourse Admin settings showing the GTM container ID (GTM-W…MZV) configured.

• Screenshot 3: Browser Developer Tools showing that the gtm.js library is successfully loaded on my website.

• Screenshot 4: GTM Preview Mode showing the error message: **No GTM tag found on your website**.

 ![This image displays a screen from the Tag Manager interface, showing tags related to a default workspace with options to view and edit tags. (Subtitulado por IA)](https://global.discourse-cdn.com/meta/original/4X/4/b/9/4b9a587c4a958af623e24473c4db761f50efd49e.jpeg)  
 ![The image shows a settings page with a Google Tag Manager (GTM) container ID displaying an example ID alongside a reset button. (Subtitulado por IA)](https://global.discourse-cdn.com/meta/original/4X/8/2/3/8237b8116f55bf59d42d84b36a9968508b85b32e.jpeg)  
 ![This image shows a Chrome browser's DevTools network panel with a network request to a Google Tag Manager resource interface. (Subtitulado por IA)](https://global.discourse-cdn.com/meta/original/4X/4/c/e/4ce5f2299c7328bb01f2f932c0bdb19ecf62e706.jpeg)

 ![The image shows a screen displaying a notification for a Google tag on hobiguru.com, specifically mentioning "GMV" and giving instructions to verify that the tag is installed and not blocked. (Subtitulado por IA)](https://global.discourse-cdn.com/meta/original/4X/8/e/7/8e7a12589e43c7d5fc1d5dd7e975107abcfc9d0d.jpeg)

**What I’ve Tried So Far** :

• Confirmed that gtm.js is loading in the **Network** tab.

• Checked the browser console for any Content Security Policy (CSP) or other JavaScript errors.

• Cleared the cache on my site and browser to ensure there’s no caching issue.

• Re-published the GTM container to ensure it’s updated.

**Request** :

Can anyone help me understand why GTM Preview Mode isn’t detecting my GTM setup, even though the gtm.js script is loading correctly? Is there something I’m missing in the setup or integration process?
