Integrating Google Tag Manager with Google Analytics

:bookmark: 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.

:information_source: This guide covers setting up Google Tag Manager. If you only want to enable Google Analytics for your site, simply 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 simply a legacy field naming artifact. The following instructions use, and work for, Google Tags.

:person_raising_hand: Required user level: Administrator

Set up Google Tag Manager for use with Google Analytics

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 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.

:information_source: Info: Selecting the four sections will most closely match the reports Analytics has typically provided:


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

  1. Set up a data stream by entering your site’s URL and a stream name.

:information_source: 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 and create an account.
  2. Set up a container by following the guided steps, and choose “Web” as the platform.

Configure GTM

Variables

  1. Go to the “Variables” tab in GTM and click “New” in the User-Defined Variables section.
  2. Create the following 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:

Then configure the variables, as in this example:

Triggers

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

  2. Choose “Page View” as the type.

    Choose trigger type

  3. Name the trigger virtualPageView and Save it.

    The end result should look like this:

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:

    • cookieDomain: auto
    • title: {{DL - page title}}
    • page: {{DL - page url}}
    • send_page_view: true

    When finished it should look like this (note that the userID field is optional and not covered by this guide):

  1. Choose the virtualPageView trigger for this tag.
  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.

:warning: 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.

:warning: Note: Remove any existing Analytics tracking code from the ga universal tracking code and ga tracking code settings in Discourse.

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:

Related Links


Meta Information


*Last Updated by @MarkDoerr on 2024-05-03T07:00:00Z

Last edited by @MarkDoerr 2024-06-25T16:31:13Z

Check documentPerform check on document:
45 Likes

Hi
since the last update, GTM removed the “GA4 Configuration” tag, and introduced one named “Google tag”. It doesn’t seem to be exactly the same.

Could you update this tuto / explain how to setup GA using discourse using this new method ?

thanks

4 Likes

Even I am facing similar issue with setup

reviving this since I’m trying to set this up. but couldn’t figure out how

since the last update, GTM removed the “GA4 Configuration” tag, and introduced one named “Google tag”. I setup using this new tag but I’m not sure how to check if everything works

1 Like

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.