0

I'm trying to capture this button-position value in a GTM variable on a link click, to differentiate different instances of a button being clicked:

button-position value in the HTML

The developer I'm working with doesn't want to use an element ID in the dataLayer as there would be multiple instances and apparently that's bad practice.

I'm not sure where I'm going wrong, I guess I'm not referencing something or the HTML needs changing, but this is what I have in a variable:

gtm.element.dataset.buttonPosition in GTM variable

I've read this can still be a dataLayer variable in GTM, but happy to be corrected, or if there's some custom JavaScript I can use instead.

Thanks for any help...

Tom

2 Answers 2

0

Figured this out, the HTML needed 'data' adding to it so the variable knew what to reference.

It needed to read: data-button-position=“Navbar”

0

There is a easier way to do this.

GTM Screenshot of AEV

Use the Auto-Event Variable

If user click the element and the variable Click Element is the you want to capture.

You can use Auto-Event Variable to get the attribute easily without modify the html.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.