Integration von Google Tag Manager mit 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, 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.

:person_raising_hand: 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 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 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:

Then configure the variables, as in this example:

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.

    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:
    • 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.):

  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

Last edited by @jessii 2024-08-03T01:04:37Z

Check documentPerform check on document:
46 „Gefällt mir“

Wie bereits erwähnt, wurde das GA4-Konfigurationstag entfernt und Sie wählen nun das Google-Tag aus. Die Einrichtungsschritte bleiben gleich, aber ich habe die Dokumentation aktualisiert.

Für alle, die zuvor das GA4-Tag eingerichtet hatten, sollte es automatisch aktualisiert worden sein und erfordert keine Änderungen Ihrerseits.

Erwähnenswert ist, dass dies im Hinblick auf die aktuellen GA4/GTM-Best Practices keine optimale Einrichtung ist und Schritt Nr. 2 im Abschnitt „Trigger“ falsch zu sein scheint.

Anstelle eines „Page View“-Triggers sollte dies ein „Custom Event“-Trigger mit dem Namen virtualPageView sein.

cookieDomain = auto scheint ein Überbleibsel von Universal Analytics zu sein und wird nicht benötigt. GA4 kümmert sich automatisch um die Subdomain-Navigation.

Eine weitere Best Practice ist, dass der Google Tag bei der Initialisierung ausgelöst wird, send_page_view auf false gesetzt wird und stattdessen ein separater GA4-Ereignis-Tag für page_view vorhanden ist.

Als wir implementiert haben, haben wir auch eine Überschreibung für page_location mit der vollständigen URL der Website + dem virtuellen Seitenpfad hinzugefügt. Dies wird die Standard-GA4-Berichte korrekt ausfüllen.

1 „Gefällt mir“

Hallo Stefan,

Vielen Dank für diese Notizen.

Ich habe Schritt 2 des Abschnitts „Trigger“ aktualisiert, da ich bereits passende Screenshots hatte, und wir werden den Rest so schnell wie möglich aktualisieren.

2 „Gefällt mir“

Beschreibung:

Ich habe ein Problem mit Google Tag Manager (GTM) auf meinem Discourse-Forum. Lassen Sie mich mein Setup und das Problem im Detail erläutern:

  1. GTM-Setup:

    • Ich habe einen Google Tag Manager-Container (ID: GTM-…MZV) eingerichtet.
    • Zu Testzwecken habe ich ein Google Analytics 4-Tag in GTM hinzugefügt, das bei der Initialisierung auf allen Seiten ausgelöst werden soll.
    • Ich habe keine komplexen Trigger, User Layer oder Data Layer hinzugefügt. Es handelt sich lediglich um eine grundlegende Konfiguration, um zu überprüfen, ob GTM funktioniert.
  2. GTM-Integration mit Discourse:

    • In meinem Discourse-Forum habe ich GTM konfiguriert, indem ich die Container-ID (GTM-W…MZV) in den Admin-Einstellungen eingegeben habe.
    • Wenn ich meine Website inspiziere, kann ich sehen, dass:
  3. Das Problem:

    • Nachdem ich meinen GTM-Container veröffentlicht hatte, ging ich in den Vorschau-Modus in Google Tag Manager und gab meine Website-URL (https://forum.hobiguru.com) ein.
    • Der GTM Preview Debugger meldet jedoch, dass kein GTM-Tag auf meiner Website gefunden wurde.
    • Obwohl gtm.js geladen wird und keine sichtbaren Fehler auftreten, erkennt der Debugger das GTM-Setup nicht.

Screenshots:

  • Screenshot 1: GTM-Container-Setup in Google Tag Manager (zeigt das GA4-Tag und Trigger).
  • Screenshot 2: Discourse Admin-Einstellungen, die die GTM-Container-ID (GTM-W…MZV) zeigen.
  • Screenshot 3: Browser-Entwicklertools, die zeigen, dass die gtm.js-Bibliothek erfolgreich auf meiner Website geladen wird.
  • Screenshot 4: GTM-Vorschau-Modus mit der Fehlermeldung: Kein GTM-Tag auf Ihrer Website gefunden.



Was ich bisher versucht habe:

  • Bestätigt, dass gtm.js im Netzwerk-Tab geladen wird.
  • Die Browserkonsole auf Content Security Policy (CSP) oder andere JavaScript-Fehler überprüft.
  • Den Cache meiner Website und meines Browsers gelöscht, um sicherzustellen, dass kein Caching-Problem vorliegt.
  • Den GTM-Container erneut veröffentlicht, um sicherzustellen, dass er aktualisiert ist.

Anfrage:

Kann mir jemand helfen zu verstehen, warum der GTM-Vorschau-Modus mein GTM-Setup nicht erkennt, obwohl das gtm.js-Skript korrekt geladen wird? Übersehe ich etwas im Setup oder im Integrationsprozess?