How to setup Google Tag Manager to Track Outbound Links Using Event Tracking

Webmasters usually need to track the clicks (hits) on all the outbound links on their websites. This is especially important if you want to bill your clients basis the number of clicks received on your site (or in other words to find out the traffic that you send to an advertisers website), find out which links are more frequently clicked by users (and are thus more popular or strategically placed) or if you are just interested in knowing from which pages most number of users exit to an external page.

All this information can be retrieved with the help of Google Tag Manager (GTM) along with Google Analytics (GA). While GA itself can provide a sea of information to the webmasters about their website, the real potential can be unlocked by using GTM alongside.

This article is a step-by-step guide for configuring GTM for tracking all the outbound links (links of external websites on your site) on the website. The GTM tag would exclude tracking clicks on internal links (links to the website’s own web pages).

NOTE: We strongly recommend that you read our guide on implementation of Google Analytics through Google Tag Manager

For the purpose of this guide, we assume that the user has some experience of using Google Tag Manager. Hence we will not discuss how to setup Google Tag Manager. In case you are just getting started with Google Tag Manager, then you must first read our guide on how to setup Google Tag Manager.

Further, we presume that the user has prior experience working with Google Analytics. In case you haven’t added Google Analytics to your website, we recommend reading our guide on setting up Google Analytics through tag manager.


Creating an Event Tracking Tag for tracking outbound links

Creating the event tracking link consists of four distinct steps.

  • First we would enable a built-in variable to get the URL of the element that users click on.
  • Create a User-Defined, Auto-Event Variable for capturing the hostname of any link that is clicked on our website.
  • Then, we will create a trigger that would define when the tag gets fired in order to capture the outbound link URL.
  • We will create the event tag to record the outbound link.
  • Finally, we test the tag and deploy it.

We will then proceed to Google Analytics to view the outbound links and the pages on which outbound links occurred.

Important: It is important that Google Analytics is properly configured on your website. If not, then you can either insert the Google Analytics code using this plugin or you can use Google Tag Manager to insert the tracking code (recommended).

Let us understand each step in detail below.

(A)   Enable Click URL Variable


  • On the dashboard of Google Tag Manager, click Variables on the left hand side menu.

Event Tracking Through Google Tag Manager Screenshot

  • Under Built-In Variables click “Configure”.

Event Tracking Through Google Tag Manager Screenshot

  • In the menu that pop-out from the side, scroll down to the Clicks section and select the checkbox in front of Click URL.

Event Tracking Through Google Tag Manager Screenshot

  • You will notice that the Click URL variable now appears under the Built-In Variables section on the main dash board page.

Event Tracking Through Google Tag Manager Screenshot


(B)   Creating A User-Defined Variable for Capturing Links

  • On the dashboard, click Variables
  • Under User-Defined Variables click New. 
  • Name your variable as “Clicked URL Hostname” (or some other logical name of your choice)
  • Click Variable Configurations. On the menu that pops-out from the side of the screen, choose Auto-Event Variable under Page Elements.

  Event Tracking Through Google Tag Manager Screenshot

  • Under Variable Type choose Element URL from the drop-down menu. 
  • Ignore Set default Value. 
  • Under Component Type, choose Host Name from the drop down menu. 
  • Select the checkbox for Strip ‘www.’ 
  • The final screen should look something like this.

      Event Tracking Through Google Tag Manager Screenshot 

  • Click Save to save the variable. The new variable should show up under User-Defined Variables


(C)   Creating A Trigger For Outbound Links

Google Tag Manager makes use of Triggers to define (and control) when a tag should fire. To understand clearly, think of Triggers as conditions which must be true for a tag to fire (get activated).

  • Click Triggers from the left side menu on the dashboard. Click New to create a new trigger.
  • At the top, rename the trigger from “Untitled Trigger” to something logical such as ”Outbound URL Link Trigger”.
  • Click on “Trigger Configuration”

Event Tracking Through Google Tag Manager Screenshot

  • In the menu that pops out from the side, click “Just Links” (which is located under the heading Click). This will ensure that the trigger is fired when the click is on a link.
  • Select the checkbox for “Wait for Tags” and leave the default wait time of 2000 ms. This will ensure that the trigger waits for two seconds to allow all the tags that use this trigger to be ready before the user is taken to the link that is clicked.
  • Select the check box for “Check Validation”. This checks for the authenticity of the link that has been clicked by the user.
  • Under the “Enable this trigger when…” option, select Page URL in the first drop down.
  • Choose matches RegEx in the second drop down. In the text box that follows, type “.*” (without the double quotes, of course!). This regular expression (RegEx) ensures that the trigger is enabled on all the pages. For almost all the websites, enabling the trigger on each page would make perfect sense.
  • We only want this trigger to fire on outbound links. Hence, for the option “This trigger fires on….”, select Some Clicks.
  • Now, under the option “Fire this trigger when…”, choose Clicked URL Hostname (User Defined Variable that you had created in Step B above) in the first drop down. Choose does not contain in the second dropdown. In the text box, type “” (again without the double quotes). Replace “mydomain” with your own URL. This will ensure that the trigger does not fire for any internal links on a page.

The final configuration screen should look something like this.

Event Tracking Through Google Tag Manager Screenshot

  • Click Save to save the trigger. After saving, the trigger should be visible under Triggers.


(D)  Creating Event Tag for Tracking Outbound Links

We will now create a tag that will use the User Define Variable created in Step B and the trigger created in Step C. The tag will send its output to Google Analytics where you would be able to see the outbound links that were clicked on your website.

Creating User Defined Variable For Google Analytics Tracking ID
  • Ignore this subsection (and jump to next subsection “Creating Event Tracking Tag”) if you already have a Google Analytics Setting Variable defined for your website. To create this User Defined Variable, read on. Click Variables and then click New under User Defined Variables.
  • Name the variable UA Tracking ID (or something similar). Now click Variable Configuration.
  • Scroll down on the window that pops out from the side of the screen and locate Utilities. Click Google Analytics Settings. Under Tracking ID, copy paste your Google Analytics Tracking ID. This can be found on the admin panel in Google Analytics (Admin – Property – Tracking Info – Tracking Code – Tracking ID). This ID starts with UA.
  • Leave Cookie Domain as “auto”. Click on More Settings and scroll down to Advertising. It is recommended that you click on “Enable Display Advertising Features”. Your configuration screen shall look something like shown below. Now click Save.

Event Tracking Through Google Tag Manager Screenshot

  • The new variable (UA Tracking ID) should appear under the list of User Defined Variables.
Creating Event Tracking Tag
  • Now, on the dashboard, click Tags
  • On the pop-up, change the name of your tag from Untitled Tag to something easily understandable such as Outbound Link Tracking.
  • Click Tag Configuration. Under Choose Tag Type, click Universal Analytics. (In case your site has old analytics code integrated, then choose Classic Google Analytics). If the analytics code (found in Google Analytics admin panel), starts with “UA- xxxxxxxx-x”, then your website has Universal Analytics code integrated. UA stands for Universal Analytics.
  • Under Track Type, select “Event”
  • Under Event Tracking Parameters, type the Category as “Outbound” and Action as “Link Clicks”.
  • Click the “+” sign next to the Label In the menu that pops out, select “Click URL”. The text field of Label will get automatically populated with “{{Click URL}}”.
  • Leave the Value field blank.
  • Change Non-Interactive Hit to “True”. This means that this event will not change your bounce rate, because it will not be counted as an interaction on your site. (In case you want to count an outbound link as an interaction then keep this field value as False). This makes sense for outbound links, but for many other events you may want to count the event as an interaction.
  • Under Google Analytics Settings, select “{{UA Tracking ID}}” variable.
  • Click Triggering and choose “Outbound URL Link Trigger” that you have created in created in Step C above. Your final configuration screen would appear something as shown below.

Event Tracking Through Google Tag Manager Screenshot

  • Click Save to save the tag. The tag would now appear under the list of tags.
  • Click Overview in the left side menu to land on the main dashboard.


(E)   Testing and deploying the tag

  • Click Preview near the top right corner of the screen. This will open the dashboard in Preview Mode for testing the tag.
  • Now open a new tab on the same browser window and enter the URL of your website in the address bar.
  • Once the page loads, the screen will be divided in two parts. The upper half will show your webpage whereas the lower half will show the tags which have fired as well as the ones which have not fired.
  • Click some external links on your site to verify that the outbound link tracking tag fires.
  • Now head over to Google Analytics. Under Real Time tracking, click events. Once you click an external link, GA should show one live event.
  • To see a list of all the outbound links that were clicked on your website, go to Behaviour – Events – Top Events.
  • To view the pages on which external links were clicked, go to Behaviour – Events – Pages.
  • Once you are satisfied that the tag is firing correctly, click on the Submit Name your version and add a description of the changes you made, tags/variables/triggers that you created in this version etc. and click Publish. It is important that you thoroughly check the tag before publishing it to the live site.

You can now track all the outbound links that are clicked on your website.

Happy Tagging!

We would love to know whether this step-by-step guide was helpful. Let us know on what topics/areas you would want us to write in future.

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *