Thom Watson
Thom Watson

Reputation: 1

Custom tag elements in Google Tag Manager

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

Answers (1)

nyuen
nyuen

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" ...>

enter image description here

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.

enter image description here

Upvotes: 2

Related Questions