Tracking HTML links with Zaraz

How can i track clicks on ahref links for GA4 with Zaraz? I tried adding Click listner and XPath with the /link to track and also the event tag for GA4 but it doesnt seem to work
8 Replies
BensTechLab
BensTechLab11mo ago
I'm using this feature and it's working for me. But XPath can be complicated... do you have the option to modify the HTML of the site and add a CSS class or Id to the target element(s)? Might be more reliable/simple. For example I add a cta-try-app class on my site for all call to action links that I wanted Zaraz to track for me, then added a unique element id for each CTA and forward both the click and the link id to google analytics.
BensTechLab
BensTechLab11mo ago
My click trigger looks like this:
No description
BensTechLab
BensTechLab11mo ago
Then my GA4 action looks like this:
No description
BensTechLab
BensTechLab11mo ago
The element_id lets me know which instance of the CTA links a user clicked.
c3d
c3dOP11mo ago
I see. I don't have a css class on my ahref links so i just need to track the url itself
BensTechLab
BensTechLab11mo ago
You can do it with other selectors - but its just going to be a matter of really verifying that the XPath thing works the way you think it does! (ie: not a bug in Zaraz, just the intricacy of DOM traversal).
Beto Garcia
Beto Garcia11mo ago
Use css selector a[href="your link"] or a[href^="start with"] using ˆ or end with a[href$="ends with"] or includes a[href*="has it"]
c3d
c3dOP11mo ago
Like this for all URLs containing /go/ ?
No description

Did you find this page helpful?