Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Differences between "Click Classes" and "Click Element" in Google Tag Manager

I don't really understand the differences between "Click classes" and "Click Element" in Google Tag Manager. I don't understand the expected use of these event and I don't understand their respective behavior regarding "contains" and "CSS selector".

Let's say I have class="buttons primary small".

What's working :

Click Element -> Matches CSS selector -> .buttons.small 
Click Classes -> contains -> small 

What's not working

Click Element -> contains -> .buttons.small 
Click Classes -> Matches CSS selector -> small 

if Click Classes is "an array of the classes on an object", What's really happen "under the hood" of GTM when doing this kind of manipulation ?

It's not that I have a real issues, just trying to understand properly.

like image 603
Simon Breton Avatar asked Apr 18 '17 16:04

Simon Breton


People also ask

What are click classes in Google Tag Manager?

There are two types of click triggers in Google Tag Manager: All elements and Just links. As their titles imply, All elements trigger tracks clicks of any element (link, image, button, etc.), while Just links trigger tracks link clicks only.

What is the difference between the just links and all elements click triggers?

All Elements: Track clicks on any element on a page, e.g. links, images, buttons, etc. Just Links: Track clicks only on HTML links that use the <a> element, e.g. <a href="www.google.com">Google.com</a> .

What is the difference between tags and triggers?

Tag: A tag is code that send data to a system such as Google Analytics. Trigger: A trigger listens for certain events, such as clicks, form submissions, or page loads. When an event is detected that matches the trigger definition, any tags that reference that trigger will fire.


1 Answers

Click Classes returns the value of the class attribute of the HTML element that was the target of the action. It is always a string, and in your example would return "buttons primary small" though not necessarily in that order.

Click Element returns the HTML element that was the target of the action.

"contains" is a match type in GTM that you use against strings. That's why it works with Click Classes (which returns a string) and not Click Element.

"Matches CSS Selector" is a check whether any given element matches a given CSS selector. "Matches CSS Selector" must thus be done against an HTML element. That's why it works with Click Element and not Click Classes.

In my opinion, Click Classes is redundant, since you're always better off doing a CSS selector check against Click Element rather than a string match against Click Classes. It's more robust that way, and you also don't need to worry about the class names being in a certain order in the class attribute value.

In other words, better:

Click Element matches CSS selector .buttons.primary.small

Worse:

Click Classes contains buttons primary small

like image 173
Simo Ahava Avatar answered Sep 20 '22 14:09

Simo Ahava