Onclick Event on Links

Hi!

I’m not sure if anything has changed here in the meantime, but I would like to add an onclick event to a link to implement Google Tag Manager conversion tracking.

Track clicks on your website as conversions

The link to be included should be as follows:

<a onclick="return gtag_report_conversion('http://example.com/your-link');"
href="http://example.com/your-link">Download now!</a>

Is it possible to implement this with the custom element?

Regards,
Markus

Hi Markus,

I could be wrong but the code you are showing looks more like UA code. GA4 has changed things, where an event is more generic and has more parts. GTM is totally different again.

I usually use GTM. With GTM you’d do something like put an ID or class or custom attribute on the link, and then setup the click handler in GTM.

Your approach or something similar could work if you want to go straight to GA4, and yes you could use a custom element to support your onclick attribute.
But I do think the code has changed a bit for GA4 events.