Search code examples
google-analyticsgoogle-tag-manageruniversal-analytics

GTM - get href value inside custom html tag


I have below anchor tags in my site and I am tracking data in Google Analytics using GTM.

I have created a custom html Tag in GTM which sends user data to GA. This tag will fire when trigger with Click_ID matches 'Nav_Link1' or 'Nav_Link2'. Inside my GTM tag, I need to get corresponding href value which matches with id. If I click first link I need to capture, first links href value and same as for all the anchor tags.

How to achieve this in GTM?

<a id="Nav_Link1" href="/External/UserData">UserData</a>
<a id="Nav_Link2" href="/External/OwnerData">OwnerData</a>

Solution

  • The easiest way for this is to enabel Click URL within built-in variable, which does exactly the same thing, what you need. You can then refer to it as {{Click URL}}.

    Although at your current use case it might not be a problem, but your trigger should be preferably Click - Just Links type, so that the actual clicked element would not be any other elements within the a tag, which might not provide value for the Click URL variable.