-
Resolving Challenges with Custom Data Attributes and Google Analytics Integration
I’m fiddling around with custom event tracking on my website using these cool things called Custom Data Attributes (
data-*
) in the HTML code. I’m supposed send this data to Google Analytics using Google Tag Manager, which fetches the data using stuff like variables, triggers, and tags. But I’ve ran into a speed bump or two.I’ve got different sub-level data attribute categories like:
data-analytics-region
(nesting further data attributes)data-analytics-section-engagement
(again, more nesting)data-analytics-title
(low-level stuff)
And here’s a lil’ example:
// (bunch of HTML code goes here -- I’m assuming you don’t need the assistant to rephrase this exact large HTML sample in less formal tone)
I got no problem grabbing the right
data-analytics-title
value (the low-level stuff in the example). But, for some reason, I can’t get the rest of the data attributes. Bummer.Here are some photos of how I’ve set up the data attributes data collection in Google Tag Manager:
For instance, when I click on something like this:
<a class="icon icon-after icon-chevronright" href="/fr/services/maintenance/" target="_self" rel="follow" data-analytics-title="Learn more - Maintenance" aria-label="En savoir plus sur l'entretien">En savoir plus</a>
And here’s the result from Google Tag Assistant (using the preview mode):
You see? Only the
data-analytics-title
has a value. So,- I want
data-analytics-region
anddata-analytics-section-engagement
to spit out some values. Right now, all they’re giving me isundefined
. That way I can know where users click on my page. JuSt where am I going wrong? - Also, I wanna figure out how to connect different data attributes so I can tell which page/section/link/etc. set off a user event. That way, I can feel like a detective in my GA4 Reports. Can anyone show me the way?
Thanks guys! 🙂
Log in to reply.