Track outbound links in Google Tag Manager

Tracking outbound links is a nice to have feature in every Google Analytics implementation, and making it work with Google Tag Manager is very easy.

In short, what we want to do is track links that are being clicked on any given page and then send an event to Google Analytics if the link goes to any page outside current domain, making it external.

This post will introduce you to the Link Click Listener in Google Tag Manager and how to configure it to listen to exactly what we want.

The Link Click Listener

The first thing we need to get into our GTM container is an active Link Click Listener. This listener will make sure to listen on all link clicks on the pages we want it active on.

First, start by creating a new Tag as follows:

GTM Link Click Listener

You’ll find the Tag Type Link Click Listener under Event Types in the dropdown.

Make sure to have it fire on All Pages. The listener will then be available to you upon every link click on every page and you can then build Tags and Rules to fire when different set of criteria is met.

The next step we need is to create a specific Event to be sent into Google Analytics when our criteria is met.

Create an event to send data to GA when an outbound link is clicked

Event for outbound links in GTM

Create a new Tag with the Type Universal Analytics (or Classic, if that’s what you are using) and make sure to change the standard Track Type from Pageview to Event.

This will give you a set of parameters you can configure in order to tell GTM what kind of data to pass onto Google Analytics.

As we want to pass on information about clicks on outbound links, we setup the event tracking as follows:

  • Category: outbound-link
  • Action: {{element url}}
  • Label: {{url path}}

This will make sure that we pass on both the URL the link is pointing to as well as where on your site the visitor was upon clicking.

Firing Rule for outbound-link

In order to have this Tag fire when a visitor click on a link not pointing to your own site we set it up as follows.

gtm-outbound-link-firing-rule

The Event we’re using is based on the Link Click Listener we setup before, that will trigger with gtm.linkClick.

Next, we want to make sure that the link itself point to a place outside of your domain, so in my case I’m using {{element url}} does not contain dcarlbom.com – and you should of course make sure to swap my domain name out and use your own. Pretty obvious, I know.

This setup will require that you don’t use relative URLs och paths when developing your site. Always make sure to use absolute paths.

Update: The fun part of being part of the GTM community is that feedback comes with a swift respond where it’s needed. In this case Simo kindly pointed out that it really doesn’t matter if there’s a relative path in the href attribute of the HTML link tag. Google Tag Manager actually uses the DOM element property, which always include the complete URL.

The end result?

Events_-_Google_Analytics

 

Make sure to test this in Google Tag Manager Debug Mode prior to Publishing. The above screen shot is similar to what you should see when testing this out.

This all depends on how you want to see your data of course. Another way of pushing the event to Google Analytics via Google Tag Manager could be to use the current page as the Event Action and the target URL as the Event Label in order to more easily see what of your pages engage people in clicking on external links instead.

It’s all about how you want to present your data, and what works for you.

Tell your friends...Share on Facebook0Tweet about this on TwitterShare on Google+0Share on LinkedIn7