Learn business growth with Google Analytics 4 Forums Google Analytics 4 Tracking External Site Link Clicks with Google Tag Manager and G4A: A Comprehensive Guide

  • Tracking External Site Link Clicks with Google Tag Manager and G4A: A Comprehensive Guide

    Posted by Ethan on 31 March 2023 at 5:48 am

    Imagine I have a landing page URL that isn’t mine, something like www.notmysite.example/somepage, but I want to use it in my ads. Now, what I’d love to do is to create a URL that’s trackable through my G4A Tag Manager. I want all clicks, the source of traffic, and so on, visible in a G4A campaign.

    I was checking out this tutorial and it showcases how to do something similar with the older Universal Analytics – but man, it seems rather complicated!

    I’m just looking for a simple middle-man link. Something that’ll tally up who’s clicking and from where, before redirecting them to the intended page.

    I mean, sure, I do have a WordPress site with G4A tracking enabled. I could potentially set up a redirect there that reads URL parameters. But honestly, I’d prefer to avoid dealing with another platform and having to organize redirects like that.

    So, the puzzle I’m trying to piece together is – how can I pull this off smoothly with G4A and Google Tag Manager?


    Alright, to elaborate – let’s look at a link from, say, a GoFundMe campaign. Now, GoFundMe has their own internal tracking and analytics stuff, which is cool. But I can’t see any way to add my own tracking to that link or view their analytics data. So, my idea is to design a new link that takes care of the tracking for my personal use, before whisking the user away to the required page.

    Alex replied 10 months, 4 weeks ago 3 Members · 2 Replies
  • 2 Replies
  • Wyatt

    25 June 2023 at 1:25 am

    Sure, let’s break it down into a discussion:

    Let’s say you want to create a sneak peak link from your website that secretly tracks clicks before whisking users to their intended destination. To do that, you’ll need Google Tag Manager (GTM).

    Here’s a simple step-by-step guide:

    1. First, you need to establish a new URL variable in GTM that checks for the presence of a “redirect” query in your URL. Let’s call this url-redirect-parameter.

    2. Next, you’ll need to craft a JavaScript variable that checks for url-redirect-parameter and redirects users to its URL after a short delay, giving GTM enough time to register the visit. Not tech-savvy? No worries, here’s the code for it:

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

    3. Now, link this new JavaScript variable to a new GTM tag and have it trigger your Google Analytics (GA) tag on your website.

    What you have now is a clever little system that springs into action the moment it detects “redirect=” in your website URL. It logs the visit and then redirects the user to their destination.

    There is another way to do this – by simply adding UTM parameters to a page on your site and have a code on the page auto-redirect to a parameter. It’s a similar principle: the catch here is the presence of a query string (QS) in the URL.

    At the end of the day, both methods tell you who is clicking on your links and where they’re going. Now you can see that traffic in your Universal Analytics results.

    This seamlessly integrates with GTM and GA and doesn’t involve adding additional code to another website. So yeah, it’s pretty cool how you can layer your own tracking onto someone else’s link, right?

  • Alex

    6 July 2023 at 12:41 am

    Sure, if you’ve got access to the back-end where you’re adding the link, you might want to consider using Google’s data layer to track an event instead of redirects. Essentially it means you listen for when the link is clicked and then track that click event. You can use this to record when the link was clicked, where the click came from, and other stuff that might be useful. This way, you’re effectively designing that new link to take care of your tracking before sending the user to the next page, as you mentioned wanting to do. Here’s to happy tracking!

Log in to reply.