Google Tag Manager | Web Analytics

Google Tag Manager Tutorial Part 1: Tracking Outbound Links in GTM Version 2

An updated version of this blog post was published in March 2020.

Last year we published a Google Tag Manager Guide to help you start using Google Tag Manager for event tracking.  Since then, Google has upgraded all Google Tag Manager accounts to Version 2.  This updated Google Tag Manager tutorial contains revised information about how to use the new GTM v2 to track important events on your website like link clicks, downloads, and form submissions.

This tutorial assumes you already have a Google Tag Manager account, have created a Container, and have installed it in your website (if not, start with the Tag Manager Help).  You should also already have a Google Analytics account for your website, and have already installed the tracking code with one of the methods recommended by Google Analytics.  Start by opening up Google Tag Manager and clicking on your Container to begin.

Part 1: Tracking Outbound Links

Part 1 of this tutorial will show you how to set up Google Tag Manager to track outbound links.  It is very useful to know how often users click on links that take them away from your site, and which of these links they click.  Unfortunately Google Analytics does not automatically track outbound links.

Set up outbound link tracking by following the steps below. First you will enable a built-in variable that gets the URL of elements that users click on.  Then, you need to create the trigger that defines what an outbound click is. Then finally, you will create a tag that records these clicks as events in Google Analytics.

1. Enable the Click URL Variable

In Google Tag Manager Version 2, you can enable and disable a variety of built-in variables (previously known as Macros), as well as create your own custom variables if needed. This lets you reduce the amount of JavaScript running on your page, in order to optimize page load speed.

Google Tag Manager Version 2 variables

To track outbound link clicks, you need to have the built-in “Click URL” variable enabled.  This will let you capture the URL of the links that users click. To enable it, just check the box next to “Click URL”.

Enable the Click URL variable

2. Create an Outbound Links Trigger

Google Tag Manager Version 2 uses triggers to define when a tag should fire, for example, when a specific kind of click happens, a certain page is loaded, or a particular form is submitted. To set up a trigger for outbound link clicks, follow these steps:

  1. Click “New” on the triggers page to create a new trigger.
  2. Replace “Untitled Trigger” with a descriptive name like “Outbound Links”.
  3. Choose Event:  Select “Click”.
  4. Configure Trigger:
    1. Select Targets “Just Links”.  This requires that the click is on a link, not on anything else, like a button or other page element.
    2. Tick checkbox “Wait for Tags” and set the Max wait time as 2000 milliseconds. This allows the trigger to wait up to two seconds for all the tags that use this trigger to be ready before taking the user to the link.
    3. Tick checkbox “Check Validation”. This checks that a link is actually a valid link that takes the user to another page.
  5. Enable When:
    1. Select options: Page URL matches RegEx “.*”. This enables the trigger on all pages of the website.
  6. Fire On:
    1. Select options: Click URL does not match RegEx “.*example\.com.+”. This makes sure the link is not an internal link to another page on your site. Use your website’s domain instead of example.com.
  7. Save trigger.
Google Tag Manager trigger configuration

3. Create an Outbound Link Click Event Tag

This tag will use the variable you enabled in step 1 and the trigger you created in step 2 to do the actual work of tracking outbound link clicks.  The tag defines how and when the event should be sent to Google Analytics. Create it by following these steps:

  1. Click “New” on the Tag page to create a new tag.
  2. Replace “Untitled Tag” with a descriptive name like “Outbound Link Click Event”.
  3. Choose Product: Select “Google Analytics”.
  4. Choose a Tag Type: Select “Universal Analytics” or “Classic Google Analytics”, depending on which tracking codes you currently use on your website.
  5. Configure Tag:
    1. Tracking ID: Enter the Tracking ID of the Google Analytics property for your website.
    2. Track Type: Select “Event”.
    3. Category: Enter “Outbound links”.
    4. Action: Enter “Click”.
    5. Label: Enter “{{Click URL}}”
    6. Non-Interaction Hit: Select True.  This means that this event will not change your bounce rate, because it will not be counted as an interaction on your site. This makes sense for outbound links, but for many other events you may want to count the event as an interaction.
  6. Fire On:
    1. Select “Click”.
    2. From the “Choose from existing Click Triggers” menu that pops up, select the “Outbound Links” trigger you created in step 2.
  7. Save tag.
Google Tag Manager Tag configuration

4. Save a Version, Test, and Publish

Before you make any more changes to your container, you should save a version of the container so that you can come back to this point if you need to. To do this, click “Create Version”.  You can give the version a name that describes what you changed in these steps, for example, “Outbound Links Tracking”, by clicking on the pencil icon next to the current version name (the default is a number).

The tags you just created will not start working until you publish them, but first you should thoroughly test that they are working as expected.  This is especially important when you have created triggers that wait for tags and check validation. You can test the setup with the Publish > Preview and Debug function.  See the Tag Manager Support articles on how to use preview and debugging.

If all goes well, publish your version so that the tags can start working on your site.

If you’ve followed all the steps above, you now have the necessary trigger and tag in your Google Tag Manager container to start tracking outbound links.

Stay tuned in the following weeks for the next parts of this guide! Part two will show you how to track downloads from your website and Part three will introduce tracking form submissions using the example of a contact form.

If you have any questions about setting up event tracking with Google Tag Manager, please send me an email.

Don't miss our GTM Articles.

Check out our Analytics services.