Slight deviation this week, but we’re still on the path to
glory a setup of Adobe Analytics and Dynamic Tag Manager (DTM) that is as close to perfection as possible.
The deviation today has to do with a question I was asked about a month ago: how can I track an attribute of a clicked element using an Event Based Rule?
Event Based Rule
Remember: DTM is based on rules. You have rules that fire on page load and rules that can be executed when something happens on the page.
The latter are called Event Based Rules and they are powerful for custom link tracking and for dynamic sites that use a lot of AJAX and DOM manipulation.
Event Based Rules, like all rules, allow you to set Adobe Analytics “variables”. You can use Data Elements for that, for example. This is great with a Data Layer, but I think I have mentioned that before.
For the question above, the real puzzler was: how do you make a Data Element that refers to some attribute of the clicked element?
And it turns out: you don’t have to!
The official documentation on Global Variables in DTM spells out an example that is interesting under the heading “Dynamically Populate Variables”:The example assigns the “id” of the clicked element to eVar1.
For that, it uses a syntax that is very close to how you access Data Elements. In fact, the syntax is exactly the same:
I can assure you that “%this.id%” is not a Data Element that I built. This is built-in functionality.
So I had to play around with that a little bit.
Say I wanted to track the class of the element that surrounds whatever I clicked on. Turns out that is possible:
This is the rule:The HTML looks like this: (Yes, that is not nicely indented. Thank you, PHP. And yes, I am using ZURB Foundation)When I click the text, I see this: Pretty cool, isn’t it?I haven’t tried to find out where the limits are. Neither have I tried to go beyond them. I hope someone else will, and I hope that someone will share their experiences and results!
The quest for perfection will continue in 2015. For now, switch off your machines and brains. Have a good time off and a quiet time with your families!