This article introduces how to use dataLayer.push method to do custom event tracking.
Meet dataLayer.push method
The dataLayer.push method uses dataLayer.push to send events, which are then triggered by GTM and sent to GA4.
The usage of dataLayer.push is as follows:
dataLayer.push({
'event': 'customize',
'color': 'red',
'conversionValue': 50
});
- Advantage:Tracking is accurate.
- Disadvantage:Need development support, send dataLayer.push
- Limit:Use this when other methods fail.
- Event Rules:
Event = Event name + Event parameter
Length of event name is up to 40 characters.
Event parameters per event is up to 25, since there are 5 default event parameters, actually 20 can be set.
Event parameters are divided into Event Scope Custom Dimension and Event Scope Custom Metrics.
Event Scope Custom Dimension is up to 40 characters.
Event Scope Custom Metrics is up to 100 characters.
Event tracking example: dataLayer.push method
Suppose I want to use the dataLayer.push method to track events at this location:
The usage of dataLayer.push is as follows:
dataLayer.push({
'event': 'datalayer_push_method',
'color': 'red',
'clickValue': 1 });
you can customize these, as long as you follow the Event Rules.
add dataLayer.push code
This step needs to be developed to add.
Variables
In GTM , click「Variables」——「New」——「Choose a variables type to begin setup…」——「Data Layer Variable」,Name it “dlv-color”, and make the following settings:
Set dlv-clickValue in the same way:
Note: dlv stands for Data Layer Variable.
Triggers
In GTM , click「Triggers」——「New」——「Choose a trigger type to begin setup…」——「Custom Event」,Name it “DataLayer Push”, and make the following settings:
Tags
In GTM , click「Tags」——「New」——「Choose a tags type to begin setup…」——「Google Analytics: GA4 Event」,Name it “Event Tracking-DataLayer Push (dataLayer.push method)”, and make the following settings:
Preview
Next is the Preview test, you can use any of the following methods:
The event fires as expected and can be published.
Custom definitions
The next step is to register event parameters. This event has event scope custom dimensions and event scope custom metrics:
- color is event scope custom dimensions
- click-value is event scope custom metrics
if you want to use it in GA4, you need to register it in the Custom definitions of GA4.
In GA4,click「Admin」——「Custom definitions」——「Create custom dimension」, then do the following configuration:
In GA4,click「Admin」——「Custom definitions」——「Custom metrics」——「Create custom metrics」, then do the following configuration:
The event tracking of the dataLayer.push method is complete.