How to add content group to Google Analytics

Last Updated: 2023-12-04

Step 1: Add code to web pages

window.dataLayer = window.dataLayer || [];
  topic: 'kubernetes',

// code snippet to install googletagmanager

Step 2: Create Variables

Variables tab:

  • New -> Data Layer Variable -> Use the same key (e.g. topic) in Data Layer Variable Name field.
  • New -> Google Tag: Event Settings -> Use content_group in Event Parameter field -> use the reference of the Data Layer Variable in the Value field.

Step 3: Create Triggers

The Message or the dataLayer push may happen after initialization, so we need to create a trigger that happens at a later stage, e.g. DOM Ready, Window Loaded.

  • New -> Select DOM Ready type.

Step 4: Create Tags

  • New -> Google Analytics -> Google Tag
    • Tag ID set to Measurement ID (e.g. G-XXXXXXX)
    • Shared event settings: set Event Settings Variable to the Google Tag: Event Settings set in Step 2.
    • Trigger set to the trigger created in Step 3.
  • New -> Google Analytics -> Google Analytics: GA4 Event
    • set Measurement ID (e.g. G-XXXXXXX)
    • Event Parameters: set Event Settings Variable to the one created in Step 2.

Step 5: Preview and Submit

Check in preview, make sure the data is set in dataLayer and the tags are fired.