Adding data-attributes as variables

Hi,

I have a page that has around 30 links on it. Each link has a set of data attributes added to them e.g. <a class="product-link" href="http://example.com" data-product-name="Product One" data-product-size="large">Product One</a>

I am able to create a tag that uses a custom trigger to listen for clicks on elements with a class of “product-link” which is working perfectly.

For the tag event value I am also able to assign the ClickClasses as per the standard variable.

However, what I would like to do is also collect the values of each of the data attributes when the element is clicked. Something very similar to ClickClasses except for the data attributes.

Does anybody know if this is possible and how I might set up those variables? It seems when creating variables, it is not possible to create them based off the targeted element, only the entire page or other similar types of data?

Thanks

Hi Alan, have you found a solution yet? Would love to know.

This has been addressed on this forum here: How to get data attribute in Custom JavaScript variable? - #5 by ulli_s

And a nice article can be found also here: https://www.mikkopiippo.com/matomo-analytics-event-tracking-using-data-attributes/

In addition to above it seems tomper00 made a very nice JS script:

Data attribute tracking is a technich that allows you to just set meta data in your code and from that automatically send event tracking to Matomo without having to add triggers, tags and variables in the TagManager

1 Like