Search code examples
google-tag-manager

GTM Click Element trigger isn't firing


I want to fire a GTM trigger based on the settings below: https://i.sstatic.net/vBGLD.png

But when I test it, it says that not all conditions are met, see: https://i.sstatic.net/2XvM3.png

And this is what I see in GTM preview mode: https://i.sstatic.net/4QX7v.png

I can't trigger on click class, since there are more buttons with them same name and I want to track this particular button.

What am I missing here? Hope someone is willing to help me. Thanks!


Solution

  • The div is a wrapper around the actual clickable item you're tracking, which is an <a> tag. It is very likely that every time the click occurs, it is the <a> element that becomes the Click Element (it is usually hard for a div wrapper to claim the click over a clickable child - such as a link or a button), which has the class green-btn and not col-sm-6 col-md-6.

    Since you say that the green-btn class is applied to other buttons you *don't want to track, I could suggest two alternatives:

    1. If you have access to the development team that maintains the website in question, and if you could get them to add a unique id attribute to this <a>, I highly recommend doing that. You could then use the id attribute via a CSS selector or the Click ID GTM attribute to target the button.
    2. If #1 is not possible, you could update your current CSS selector to be more specific, like so: div.col-sm-6.col-md-6 > a.green-btn. For this to work reliably, you have to make sure that the only element that matches this selector in the whole website is this button that you want to track.

    Please try and let me know how it goes.

    [Edit: Added a "don't" that was missing in my original answer. I usually leave my mistakes alone, but this one would change the meaning of a core point entirely for anyone who stumbles upon this answer in future.]