GA4 Custom Events: dataLayer.push Method

Google Analytics BCS 3 years ago (2023-02-01) 5057 Views 0 Comments

This article introduces the use of dataLayer.push method for event tracking, this is how e-commerce tracking is used, read more: Google Analytics 4: Google Tag Manager Ecommerce Setup Guide

The principle of dataLayer.push is very simple. Once a specific event is triggered, it passes dataLayer.push pushes the event to the data layer, then uses the custom event as the trigger condition in the Trigger in GTM, and then uses a Tags to configure the event. Read more: Data Layer in Google Tag Manager Guide

Suppose now we want to do dataLayer.push tracking on this location:

GA4 Custom Events: dataLayer.push Method

 

Step 1 : DE add dataLayer.push

The source code for tracking location is:

<a>dataLayer.push demo test</a>

DE needs to add dataLayer.push as:

dataLayer.push = ({
    'event': 'test',
    'pageType': 'product'
});

The effect after adding it to the required position is:

<a onclick="dataLayer.push({'event': 'test','pageType': 'product'});">dataLayer.push demo test</a>

GA4 Custom Events: dataLayer.push Method

As long as the location is clicked, dataLayer.push is executed.

Step 2 : Set Up the Variable

In GTM, click「 Variables」——「New」——「Choose a variable type to begin setup…」——「Data Layer Variable」, name it “dlv-Page Type”, and then set as follows:

GA4 Custom Events: dataLayer.push Method

Step 3 : Set Up the Trigger

In GTM , click「Triggers」——「New」——「Choose a trigger type to begin setup…」——「Custom Event」,Name it “dataLayer.push demo”, and make the following settings:GA4 Custom Events: dataLayer.push Method

Whatever the value of the event in dataLayer.push is, fill in the event name.

 

Step 4 : Set Up the Tags

In GTM , click「Tags」——「New」——「Choose a tags type to begin setup…」——「Google Analytics: GA4 Event」,Name it “GA4-Event-dataLayer.push”, and make the following settings:

GA4 Custom Events: dataLayer.push Method

 

Step 5 : Preview and Publish

Next is the Preview test:

GA4 Custom Events: dataLayer.push Method

Tags is triggered, click it to open and check whether the value of the event parameter page_type is accurate:

GA4 Custom Events: dataLayer.push Method

The event parameters are accurate, and can be published.

Read More:

Step 6 : Custom definitions

The next step is to register event parameters page_type, 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:

GA4 Custom Events: dataLayer.push Method

Step 7 : Verify Data in Reports

Generally, after 24 hours, we can see the data in GA4, such as:GA4 Custom Events: dataLayer.push Method

 

Read More: 


If you don't understand, You can leave a comment below.
Like (3)
Post my comment
Cancel comment
Expression Bold Strikethrough Center Italic

Hi, you need to fill in your nickname and email!

  • Nickname (required)
  • Email (required)
  • Website