Diego Rodriguez
Diego Rodriguez

Reputation: 65

Google Tag Manager Trigger by CSS class

I want to trigger a tag when a link with a certain css class is clicked. I create a trigger based on Clicks > Just Links, but when I go to select the variable, I just get "Page Hostname, Page Path, Page URL, Referrer, New Variable"... no "Click Class" as one would expect.

All the online help shows an outdated version of GTM that don't match the options I see. Even the GTM help docs are outdated.

How does one trigger by css class? (I tried using a custom variable, but didn't work either, and honestly the options didn't make much sense either).

Update: It works if I create a new custom variable "DOM Element has CSS selector" and then go to Trigger, select my custom variable, select "Equals" and enter the text of the link.

But this doesn't make much sense to me, all I want is trigger based on css class, not by the text contents of the tag.

Upvotes: 1

Views: 1274

Answers (1)

Diego Rodriguez
Diego Rodriguez

Reputation: 65

Turns out GTM's "Click Element" built in variable (and many others) is off by default, that's why it was missing from the trigger dropdown. One has to go to Built In Variables > Configure > and tick the "Click Element" variable.

Why would they turn this off by default and offer no clues in the UI, I have no idea.

Upvotes: 2

Related Questions