GA4 Event Tracking Series ⑨ —— Custom Events(ga-data Method) | BCS GA4 Event Tracking Series ⑨ —— Custom Events(ga-data Method) | BCSBCS

GA4 Event Tracking Series ⑨ —— Custom Events(ga-data Method)

Google Analytics BCS 2 years ago (2023-02-02) 2118 Views 0 Comments

Update time: January 12, 2025

This article introduces how to use ga-data attributes method to do custom event tracking.

If you need to track events at multiple locations, you can add ga-data attributes to different locations and assign different values ​​to different locations. You only need to configure one Tags to track events in batches.

Now we need to track events at these three locations, and see how to set them using the ga-data attribute:

GA4 Event Tracking Series ⑨ —— Custom Events(ga-data Method)

Step 1 : Add ga-data Attribute

Add ga-data attributes to the page, and add different values ​​to different locations.

The source code before adding is as follows:GA4 Event Tracking Series ⑨ —— Custom Events(ga-data Method)

The effect after adding is as follows:

GA4 Event Tracking Series ⑨ —— Custom Events(ga-data Method)

Note: If you do not have development permission, please ask DE to help you complete this step.

 

Step 2 : Get ga-data Attributes in GTM

First, In GTM , click「Variables」——「New」——「Choose a variables type to begin setup…」——「Auto-Event Variable」,Name it “element”, and make the following settings:

GA4 Event Tracking Series ⑨ —— Custom Events(ga-data Method)

Then, click「Variables」——「New」——「Choose a variables type to begin setup…」——「Custom JavaScript」,Name it “Get ga-data”, and make the following settings:

GA4 Event Tracking Series ⑨ —— Custom Events(ga-data Method)

Source Code :

function() {
	var elem = {{element}},
	    attr = "ga-data", // change this to the attribute that you want to get
        result = (elem.getAttribute && elem.getAttribute(attr)) || null;

	if( !result ) {
		var attrs = elem.attributes,
			l = attrs.length;
		for(var i = 0; i < l; i++) {
			if(attrs[i].nodeName === attr)
				result = attrs[i].nodeValue;
                }
	}

	return result;
}

 

Step 3 : Set Up a Lookup Table

In GTM , click「Variables」——「New」——「Choose a variables type to begin setup…」——「Lookup Table」,Name it “Lookup Table ga-data”, and make the following settings:

GA4 Event Tracking Series ⑨ —— Custom Events(ga-data Method)

Convert the specific values ​​in the attributes of the ga-data obtained earlier into corresponding specific behaviors. Generally, the numerical range is constructed in sequence to facilitate determining the triggering conditions when setting the Trigger later.

 

Step 4 : Set Up the Trigger

In GTM , click「Triggers」——「New」——「Choose a trigger type to begin setup…」——「Click – All Elements」,Name it “ga-data Trigger”, and make the following settings:

GA4 Event Tracking Series ⑨ —— Custom Events(ga-data Method)

Triggered only when ga-data is greater than or equal to 100.

Step 5 : Set Up the Tags

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

GA4 Event Tracking Series ⑨ —— Custom Events(ga-data Method)

Step 6 : Preview and Publish

Next is the Preview test: GA4 Event Tracking Series ⑨ —— Custom Events(ga-data Method)

 

The event is triggered normally. Click Open to confirm whether the event parameter position is correct:GA4 Event Tracking Series ⑨ —— Custom Events(ga-data Method)

 

The event fires as expected and can be published.

Read More:

Step 7 : Custom Definitions

The next step is to register event parameters position, 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 Event Tracking Series ⑨ —— Custom Events(ga-data Method)

Step 8 : Verify Data in Reports

Generally, after 24 hours, we can see the data in GA4, such as:

GA4 Event Tracking Series ⑨ —— Custom Events(ga-data 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