Reputation: 1
I'm wanting to add a custom tag element to all elements on my site but how can it be setup so Google Tag manager sees them?
data-tag="example"
e.g.
<a href="example.html" data-tag="menuItem">Example</a>
This would then be used to create a standard Universal Analytics tag that would record all elements containing data-tag="example"
Upvotes: 0
Views: 153
Reputation: 8907
If the element you want to grab is not directly related to an element you are interacting if, then you could create a DOM
variable and use the CSS Selector selection method. For example, if your HTML was something like:
<body .....>
<header data-my-attribute="spaghetti" ...>
Use the CSS selector to pinpoint exactly which element you are targeting, and just pluck out the attribute value.
If you are trying to fetch an attribute of a clicked element, then you could use an Auto-Event Variable which, when interacted with, will automagically grab the value of the specified attribute.
Upvotes: 2