How to add content group to Google Analytics
Last Updated: 2023-12-04
Step 1: Add code to web pages
window.dataLayer = window.dataLayer || [];
window.dataLayer.push({
topic: 'kubernetes',
});
// code snippet to install googletagmanager
Step 2: Create Variables
Variables
tab:
New
->Data Layer Variable
-> Use the same key (e.g.topic
) inData Layer Variable Name
field.New
->Google Tag: Event Settings
-> Usecontent_group
inEvent Parameter
field -> use the reference of theData Layer Variable
in theValue
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
-> SelectDOM Ready
type.
Step 4: Create Tags
New
->Google Analytics
->Google Tag
Tag ID
set toMeasurement ID
(e.g.G-XXXXXXX
)Shared event settings
: setEvent Settings Variable
to theGoogle 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
: setEvent Settings Variable
to the one created in Step 2.
- set
Step 5: Preview and Submit
Check in preview, make sure the data is set in dataLayer and the tags are fired.