Outbound link tracking with Google Tag Manager (GTM)

Outbound link tracking? Yes! You would like to know where your visitors are going from your website, right? You can use this data to see what external links have been clicked on by your visitors. This can be of great value for bloggers, for example, this way you can find out what affiliate links are working.

To set up the outbound link tracking we’re going to use Google Tag Manager. We’re not going to dive into how you can set up Google Tag Manager for your website, this article only dives into the outbound link tracking part.

If you don’t have Google Tag Manager set up yet, follow this video. If you haven’t, follow the steps down below.

Outbound link tracking

Let’s get started!

Step 1: Creating a variable in GTM

The first step is to log into Google Tag Manager and navigate to the appropriate container. Now let’s first start by creating a variable to check whether a link is internal or external (outbound).

To create a variable, in GTM go to Variables > User-defined Variables > New and choose Auto-Event Variable.

Add the following information:

Name: GA | Outbound link tracking
Variable type: Element URL
Component Type: Is Outbound 

So with this, you are saying that the element must be a URL and that the type of URL must be external (outbound). It will look like this:

outbound link tracking Screenshot 1 - Sander Volbeda

Of course, click save before continuing. This variable indicates when someone is on your domain and clicks on a link that redirects to an external website or a (different) subdomain. A subdomain could be blog.yourwebsite.com for example.

If you want to treat subdomains or other websites as internal traffic and not as external as is the default you can set this up with affiliated domains.

An important part of this is that affiliated domains work like a volt. Each item in the affiliated domain’s field will be matched with a so-called operator. The operator is “contains”, so if the URL contains the affiliated domain, then it is considered internal traffic.

If you want to count subdomains as internal traffic, but the main domain without www, HTTPS, etc. in the affiliated domains field. This only applies to the top level of the domain. All URLs containing the main domain will then be considered internal traffic. If you add multiple domains to affiliated domains, put a comma between them, e.g. domain1.com, domain2.com.

Outbound link tracking Screenshot 2 - Sander Volbeda

Step 2: Creating the trigger in GTM

With the variable, it is clear what needs to be done, with the trigger you can set when something needs to be done. In Google Tag Manager, go to Triggers > New > Trigger Configuration > Just left.

Name: GA | Outbound link trigger
This trigger fires on: Some Link Clicks

Dropdown 1 (select variable): GA | Outbound Link Tracking
Dropdown 2: Equals
Input field: true

Outbound link tracking Screenshot 3 - Sander Volbeda

Save the trigger, we can now proceed with creating the tag right away.

Step 3: Creating a tag

Now that we have the what (variable) and the when (trigger) we still need to set up the data to appear in Google Analytics so it can be visualized. So in this case, a tag allows you to forward data.

In Google Tag Manager, go to Tags > New.

Name: GA | Outbound link tracking
Tag Configuration: Google Analytics: Universal Analytics
Track Type: Event
Category: Outbound link tracking
Action: Select variable {{Page Path}}
Label: Select variable {{Click URL}}
Google Analytics: Select the tracking ID variable
Triggering: Select trigger GA | Outbound link trigger

Outbound link tracking Screenshot 4 - Sander Volbeda

Save! Of course, just test via debug/preview mode if everything is going well before publishing. To test if the data is coming into Google Analytics you can go to Google Analytics, Realtime > Events, and there you will already find the test clicks you made during debugging/reviewing.

After publishing the Google Tag Manager container, the data will be found in Google Analytics under Behavior (Behavior) > Events.

Very useful to find out where your traffic goes to and if this is your intention! Would you like to learn how to track the Scroll Depth of your users, I’ve written an article about it! Would you rather learn more about this subject and go more in-depth, read this article about tracking External links.

Ow yeah, there is also a video

Logo Freelance CRO specialist Sander Volbeda

Working remotely from Groningen, the Netherlands. Get in touch and let’s schedule a meeting, no strings attached.

Get in touch
© 2024 Sander Volbeda, All rights reserved
CoC: 53236734 VAT: NL002247968B39