This section describes how to do batch event tracking, that is, a tag triggers multiple events. If each event tracking has to be located one by one, the workload is relatively large and tedious. Now we introduce a method that can track events in batches.
Suppose there are several locations on the blog that need to be tracked for events. The specific locations are as follows:
There are four places to do event tracking.
Setup Process
1、Add ga-data attribute
Move the mouse to the position you want to track, then right-click and select Inspect to see the source code:
Let the colleague of development add the ga-data attribute on it, such as ga-data = “1”. Each location that needs to be tracked needs to be added and assigned a value. The effect after adding is as follows:
2、Setting Variables
Need to set three variables
element
Create a User-Defined Variables Auto-Event Variable and name it element,Variable Type set as Variable , The specific configuration is as follows:
Custom JavaScript
Create a Custom JavaScript, then copy the following code into it and name it Get-ga-data:
<span style="font-size: 12pt;">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; }</span>
The specific configuration is as follows:
Lookup Table
Create a lookup table and name it Lookup Table-ga-data:
Input Variable Select Get-ga-data; Input is the ga-data value set previously , It is the value in ga-data = “1”, and output can be customized for specific locations:
2、Setting Triggers
Create a Click-All Elements trigger, select Some Clicks, named as Bulk:
The range of the trigger condition is the value range in ga-data, which is why the value is used in ga-data. More convenient positioning.
3、Setting Tags
Make the following settings:
4、Preview
On the real time report back to Google Analytics:
The data was also received.
We done!