I have created a regex lookup table variable to output text based on the Click Element containing a specific string. However, the variable appears as null despite the string definitely being in the Click Element. Can anyone help?
Here is my regex lookup table variable Here is the debug window showing null (the Action field is where the regex table variable should populate)
Here is the full tag that contains the variable
Here is the trigger for the tag I have tried various different strings from the Click Element, without luck.
The trigger for the tag is based on the same string, and the trigger works, which only adds to my confusion.
I feel like the problem must be obvious, but I'm at a loss.
I struggled with this as well until I realized that "Click Element" is actually an object, not a string. It's based on gtm.element
in the datalayer
.
So, in order to do this you'll need to create a custom datalayer variable that more accurately targets a specific child key.
To see what I mean, open a link in a new tab and then type in datalayer
into your browser console, and press enter. You'll see something like:
3:
event: "gtm.click"
gtm.element: a#mylinkclass.my-class.something.else
accessKey: ""
ariaAtomic: null
ariaAutoComplete: null
ariaBusy: null
ariaChecked: null
ariaColCount: null
ariaColIndex: null
etc....
Screenshot of chrome inspector console showing datalayer children
So, then you'll have to create custom variable to target the key you'd like. For example, a datalayer variable that you create with gtm.element.className
would return my-class something else
for link <a href="/my-link-here/" class="my-class something else" id="mylinkclass">Link Text</a>
.
Using this method I was able to create a Regex lookup table just like you're trying to do.
Here's a post that goes into some more detail on some of the above:
https://www.analyticsmania.com/post/click-element-variable-in-google-tag-manager/