Tracking outbound links with Google Tag Manager

Especially in affiliate marketing, where the outbound link is essentially your product, tracking your outbound links is important and gives you useful information. Basically for an affiliate, getting a user out of the website is the goal of the affiliate site so by tracking links you get to see how many people you send from your website.

If you aren’t in the affiliate business, it might be still worth tracking the outbound links as well as links in general. With this information, you get to see, what are your websites hotspots when it comes to links and what information was something the visitors were interested to learn more about.

Google Tag Manager

Google Tag Manager is a free tool from Google – What is tag manager. While you can obviously setup even tracking in Google Analytics, with Tag Manager you don’t have to add anything in your code. For larger websites, this allows the analytics team work in their own terms without the need of the development team. If you aren’t yet using Google Tag Manager, see the previous post on how to install Google Analytics via Google Tag Manager.

Setting up necessary variables

If you haven’t already added more variables to the default settings, chances are that you won’t have the necessary variables yet available to set up the tracking for the outbound links. If this is the case, add variables by going to¬†variables -> configure and checking all the checkbox. While we aren’t needing all of them yet, you might as well just check all as it won’t really do any harm either to have all of them available.

Configure variables in Google Tag Manager
Enabling more variables in Google Tag Manager

At least make sure you have all the clicks enabled.

Click variables in Google Tag Manager
Check that you have all the click variables enabled

Create a new tag

Click to create a new tag and select the following settings.

Create a new tag in Google Tag Manager
Creating a new tag in Google Tag Manager

Create a trigger

Now we need to create a trigger for the tag. Something that fires the tag we have created. Since we want our trigger to be fired on external links only, we have set a rule that fires the trigger only when the click target is blank.

Create triggering in Google Tag Manager
Creating a trigger that fires the tag


Since WPTipster has cloaked affiliate links on the site, it uses the target blank to separate the outbound links from internal links. A cloaked link is basically an internal link that is redirected. Cloaking links is done for SEO purposes. Because of this, variables like pathname cannot be used as it would not track the most important thing WPTipster is interested in tracking, affiliate links. Check what plugin to use for link cloaking.

Preview and test that the tracking is working

Head back to overview page and click the preview button. This will allow you to preview the tags on your site. Sometimes new tracking may interfere with other scripts and cause parts of the code to brake. Because of this, it is always good to preview the new changes before submitting them live.

After you have entered the preview mode, go to your site where you want to set up the link tracking. If you click an outbound link, you should be able to see in the preview bar whether the tag was the triggered. If it was fired, test that the new tracking did not break anything on your page and that inner links aren’t triggering the tag. If everything works as it should, you are ready to submit the new version.

Submit changes

Assuming everything went well in the preview mode, you are now ready to deploy the new tag. Click on submit and write a brief description of what has changed in the new version. If you are familiar with version control such as git, this phase should be quite self-explanatory. After deploy, double check that everything is working. Now you are ready to track your outbound links. This data will be displayed in your Analytics account under Events.
Banner icon: Designed by Freepik