Home > Software engineering >  How to track link clicks for external sites using Google Tag Manager and G4A?
How to track link clicks for external sites using Google Tag Manager and G4A?

Time:09-10

Let's say I have a landing page URL that is not on my own site, www.notmysite.example/somepage and I want to advertise this link. I would like to create a URL that is tracked through my G4A Tag Manager, whereby the link click, referrer, etc., are all tracked in a G4A campaign.

I found enter image description here

  • Create a redirect CUSTOM JavaScript variable that reads the url-redirect_parameter variable

    function() { try { return {{url-redirect_parameter}}?setTimeout(function(){window.location='{{url-redirect_parameter}}'},500):false; } catch(e) { return e; } }

This custom JS variable references a redirect tag with the following configurations

  • redirect Trigger trigger that to your GA tag on your website enter image description here

enter image description here

What this captures now is whenever there is a "redirect=" in the query string, the trigger will fire, record and redirect.

Another solution is just to add UTM parameters to a page you control on your site and have code on that page to auto-redirect to a QS parameter as well. This essentially does just that by injecting JS that does the redirect if the QS is present.

I hope his helps someone else looking for a similar solution and open to other solutions, like a G4A solution.

Here is the Universal Analytics result:

enter image description here

  • Related