Monday, December 5, 2022
No menu items!
HomeData Analytics and VisualizationHow to Track Outbound Links with Google Tag Manager and Google Analytics

How to Track Outbound Links with Google Tag Manager and Google Analytics

Updated: January 3rd, 2022. It’s time for a guide that’s for those who are just starting with Google Tag Manager.

There is a high chance that your website contains some external links (a.k.a. outbound links), people might click them and they will be redirected to another domain. By default, Google Analytics cannot tell you whether that happened because no events are being tracked in Universal Analytics. You need to precisely instruct it to do so.

Luckily, there is a pretty simple way how you can start seeing that data automatically in Google Analytics thanks to GTM.

In today’s blog post, we’ll take a look at how to track outbound links with Google Tag Manager.

 

Looking for Google Analytics 4 instructions?

This blog post teaches how to track events with Universal Analytics. If you want to get familiar with event tracking in Google Analytics 4, you can also refer to this blog post.

Also, keep in mind that Google Analytics 4 can track outbound link clicks automatically. That is a part of Enhanced Measurement. Learn more here.

 

Table of contents

Want to learn more about click tracking in GTM?
Why should you track outbound links at all?
Getting method: Outbound link tracking with Google Tag Manager
Step 1. Create an auto-event variable
Step 2. Create a trigger
Step 3. Create a tag
Step 4. Test

Important!
Checking Outbound Link Click events in standard Google Analytics reports
Create a goal in Google Analytics
Track Outbound links with GTM: Final words

 

Want to learn more about click tracking in GTM?

I have prepared a bunch of resources where you can learn more about Google Tag Manager click tracking in general. Pick the one you prefer the most:

Guide: Google Tag Manager click tracking
Free course: Google Tag Manager fundamentals
Premium course: Google Tag Manager for Beginners. Also, you can learn even cooler tracking techniques in my Intermediate GTM course.


Why should you track outbound links with Google Tag Manager at all?

Before we learn how to actually track outbound links with Google Tag Manager, first let’s take a step back and think whether we need it at all. Why and how can it be useful?

In general, it can give you a better understanding of user behavior. After all, not every outbound link might be bad. At first, you might think that the outbound link click means that the visitor was lost. But what about links to your social media profiles?

What if your business owns multiple websites that are using different domains? You might be interested in which links are most clicked, right?

Without Google Tag Manager, link clicks in Google Analytics (or any other interactions ) had to be tracked manually. This means that if you are interested in clicks of 5 links, a developer had to add certain codes to those links to start tracking those clicks as events.

What if you want to track 5 more links? Yup, you need to contact a developer once again (unless, of course, a developer coded some more automated solution). But with Google Tag Manager, you can automate this process yourself. And in fact, this is exactly why I am implementing outbound link tracking on various projects.

I don’t check the total number of outbound link clicks (because that tells me nothing). But if I have a certain question, e.g. “do visitors on that page click any outbound links?” or “what do visitors do on that particular page?”, the story is totally different.

And thanks to Google Tag Manager, we can configure it in a way that you set it once and leave it (unless, of course, the domain of your website changes). There is no need to tell a developer to add an additional tracking code to certain links.

Another possible use case for outbound link clicks – affiliate/partner marketing. Without doing additional configuration you can have a better understanding of what kind of traffic volume are you sending to them.

 

Getting started: Track Outbound Links with Google Tag Manager

You might have seen other (older) Google Tag Manager guides offering you to use the Click URL variable in this setup. They are still very much valid, however, the latest update to Google Tag Manager (October 30th, 2019) made the outbound link tracking much easier and quicker to set up.

 

Step 1. Create a variable that tells GTM whether the link is outbound

Back in the old days (e.g. last week), people were using a built-in GTM {{Click URL}} variable to distinguish whether the clicked link belongs to the website or to an external resource.  But right now this can be done with an Auto-Event Variable that will return true or false based on whether the link is outbound or not.

To do that, go to Variables > User-defined Variables > New and choose Auto-Event Variable.

Then enter the following configuration:

Variable type: Element URL
Component Type: Is Outbound

This is the bare minimum you will need to use in order to distinguish the outbound link from an internal link. This variable will return true if a visitor is on https://www.yourdomain.com and clicks a link that redirects to:

https://www.someotherwebsite.com
or a different subdomain that belongs to your domain https://blog.yourdomain.com

If you want to treat more websites as internal, you can use the Affiliated Domains field. Separate each domain with a comma.

Important: every item in the Affiliated Domains field is matched with the operator “contains”. So if, for example, you want to treat ALL your subdomains as internal (because by default, they are external to this auto-event variable), just enter yourdomain.com (replace it with your actual domain). Don’t use www, https, etc. Just the top level of your domain.

 

Step 2. Enable a link click trigger in GTM

By default, Google Tag Manager does not track clicks. You can check that by enabling the Preview and Debug mode and refreshing the web page that you’re working on.

Note: the preview mode has been updated in 2020 and it looks a bit different. However, the debugging principle still looks the same. Instead of 3 events, you will now see 5 (Consent Initialization, Initialization, Container Loaded, DOM Ready, Window Loaded).

If you’re working on a fresh new GTM container, click any link on the page (not in the GTM debug panel) and see what happens on the left side of the panel. Nothing. You will still have those 3 events (unless, of course, you have implemented some other tracking functionality in your GTM container sometime before).

In order to start seeing Link Click events in the preview and debug mode, we need to have at least one Link Click trigger enabled on a page.

In Google Tag Manager, go to Triggers > Trigger Configuration > New > Just Links. Then choose Some Link Click and enter the following condition:

aev – is outbound link (that’s the name of the variable I created in the previous chapter) equals true

Speaking of two checkboxes, here is a quick overview:

Wait for tags is useful if the link opens in the same browser tab. If you have any tags linked to the link click trigger and Wait for tags is enabled (say for 2000 milliseconds), GTM will put the redirection temporarily on hold (for up to 2000 milliseconds) to give tags a chance to properly fire. Once the tags have properly fired or 2000 milliseconds have passed, the user will continue navigation to another page. You can change the duration of that pause, not limited to 2000 milliseconds.

Check Validation checks if the click was actually valid. This setting is mentioned in two guides by Simo Ahava. usually, I leave this checkbox unchecked.


 

Step 3. Create a tag

Now, let’s send outbound link clicks as events to Google Analytics. To do that, go to Tags (in your GTM interface) > Tag Configuration > Universal Analytics.

And enter the following settings:

In fact, you can enter anything that is meaningful to you in the Event Category, Event Action, and Event Label fields. The screenshot above is just for the demonstration purpose. P.S. thanks to Marek Lecián for the naming convention tip.

For this to work, you need to enable click-related built-in variables in GTM. Go to Variables > Customize > Click checkboxes next to every click variable (or at least Click URL).

{{Click Hostname}} is not a built-in variable in GTM. Read this article to learn how to create one.

If you don’t have any Google Analytics Settings Variable in the container yet, create one by clicking the drop-down list and choosing New Variable.

At least for now, enter the GA Tracking ID of your property (it looks like this UA-XXXXXXX-XX) and hit Save.

If you want to use other GA features, like custom dimensions, cross-domain tracking, you’ll need to do additional configuration in the GA Settings Variable.

With GA Settings Variable you’ll be able to reuse the same GA settings in multiple Google Analytics tags. Each GA tag requires a Tracking ID and, optionally, other settings to configure. Once you have 20, 50, or even more Google Analytics Tags, the management on the individual level becomes unbearable.

That’s where the GA Settings Variables saves the day: after you make a single change in the variable, all the tags that are using the variable will automatically inherit the change.


 

Step 4. Test

Enable (or refresh) the Preview and Debug mode, go to your website and refresh the page. Here are scenarios you should test:

Click an internal link (e.g. the one that opens a “Contact us” page). The outbound link GA tag must not fire.
Click an external (outbound) link. The GA Tag must fire. If the tag did not fire, click it in the P&D mode.

and scroll down to the Firing triggers section and check if all the conditions were not met (marked with a red X).
Then check GA real-time event reports and see if you are getting the data.
In Google Analytics, go to Realtime > Events, and you should see the click data you’ve just tracked with GTM.

If, for some reason, you don’t see the data in Google Analytics real-time reports, read this guide.

 

Checking Outbound Link Click events in standard Google Analytics reports

After you made sure that outbound link click events appear in the GA Real-time reports, you should wait a bit until they appear in standard GA reports. Usually, it can take minutes or several hours but you should prepare yourself to wait for up to 24 hours.

Anyway, to see these events in GA reports, you need to go to Behavior > Events > Top events. Make sure that in the date picker you have included today’s data as well (by default that is not included so you need to specifically tell that to GA).

Once you’ve done this, in the search field enter the category of the event (that you used in the GA Event Tag) if you have too many event categories.

That should display the events you sent to GA. Once again, if you don’t see them, be patient and wait for up to 24 hours.

 

Create a goal in Google Analytics

Usually, I don’t track outbound link clicks as goals because I find other interactions more meaningful (like opt-in, download, etc.), but maybe it makes sense in your project to track clicks of certain outbound links as goals.

If yes, then let’s take a look at how can you do that.

Goals are interactions/behavior that you treat as something important. By definition, they are designed to measure how your website visitors are behaving and whether they do the activities that are important to your business (like signup, download, etc.).

So if you think that a certain outbound link is an important event and should be treated as a goal, do this. In Google Analytics, go to Admin and in the View column choose goals. Create a new goal (keep in mind that Universal Analytics allows you to create 20 goals per view).

Choose Custom > Enter the name of the goal. It can be anything you want. But just make sure that the name is clear and other people can easily understand what it means. Choose the Event as a goal type.

Now you will see 4 fields. Fill in AT LEAST ONE of them. It is NOT required to fill in all of them. Just make sure that you enter category, action or label exactly as you sent those events from GTM to GA. So if you used the event category outbound link click in GTM and such event is sent to GA, then should enter outbound link click in goal’s settings as well.

But once again, it is not required to enter all the fields. For example, the goal will work perfectly fine if you enter just the Event Action.

Here are several examples of goals:

You can enter just outbound link click in the event category (of Goal’s settings). This means that all events with such a category will be treated as completed goals. Although I don’t see any value in tracking ALL clicks as goals, it is possible.
You can enter outbound link click as event category and https://socialnetwork.com/our-business-name as the event label. In that case, only clicks of a specific link will be treated as a goal.

A common mistake among beginners: If you use {{some variables}} in GA event tag (in GTM), DO NOT enter the name of the variable in GA goal’s settings. You need to enter the final output of that variable. So if we take a look at the screenshot above, I did not enter {{Click URL}} in the label. I entered the output of the variable, which is https://socialnetwork.com/our-business-name.

Once everything is entered, you can verify the goal. But if you have just implemented the tracking of outbound link clicks, the verification will return 0%. That’s because the data has not been fully processed by GA (yet).

So you can ignore that and use the GA real-time conversion reports. Just like it was with event debugging, go to Real-time reports > Conversions and you can see whether your goals are being tracked.

Important: goals are not retroactive. You will start seeing them in GA reports only starting from the moment you created that them.

 

Track Outbound Links with Google Tag Manager: Final words

I remember when I started working with Google Tag Manager. I think that the second thing I implemented via GTM (after pageviews) was outbound link tracking (because it was so simple to configure).

In this guide, I’ve explained how to automate outbound link tracking with Google Tag Manager. Instead of manually telling GTM to track X or Y link, you just configured it to track all link clicks that redirect people to an external resource (e.g. 3rd party website, social network, etc.).

Here is the summary of actions you need to complete in order to track outbound links with Google Tag Manager:

Create an auto-event variable that returns true if the clicked link is outbound
Create a Just Links trigger that activates tags only if the clicked link is outbound
Create a tag (e.g. GA Event) that sends the event when the outbound link is clicked
Test

Is there anything else that you’re missing in this on how to track outbound links with Google Tag Manager? If yes, then post a comment below.


The post How to Track Outbound Links with Google Tag Manager and Google Analytics appeared first on Analytics Mania.

Read MoreAnalytics Mania

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments