Another use overcomes one of the inherit limitations of Google Analytics.  We often want to know when a visitor follows a link to another website, but unless we have access to the analytics on that page we can’t get that information.  We have traditionally overcome this in GA by creating events when a user clicks that link, but it has generally been difficult to make that work for every link – creating each event by hand is tedious at best, and adding the event through a script is far from reliable.  GTM, though, lets us do this easily.

  • Create a new tag
  • Use the same procedure to create the tag as we did with the download, changing only the Category event tracking parameter.
    • Make the Tag Type be Universal Analytics
    • Add your Tracking ID
    • For the Track Type, choose Event
    • Under Event Tracking Parameters, add “download” (or whatever you want the label to be when you look for the event in the GA dashboard) to the Category box.
    • Under Event Tracking Parameters, add “click” to the Action box.
    • Under Event Tracking Parameters, use the {{Click URL}} built-in variable to pass the link clicked upon to the “download” category in the GA dashboard.
  • Set the Non-Interaction Hit to be True for this tag.
  • The trigger setup will also be similar.
    • Use the Just Links option
    • For the trigger configuration use Page URL - matches RegEx - *
    • Again click the Some Link Clicks selection
  • We will now  make sure the destination link does not match our website by using RegEx comparison against one of GTM’s built-in variables:
    Click URL Hostname - does not match RegEx - [Your Host Name]
  • Save your Tag/Trigger

Note that if you use the same tag to track multiple sites you will need to slightly modify this process.

  • Create a custom variable named Offsite Check. The variable type should be Custom Javascript
  • Add this snipped of code as the variable content:
    function() {
    return {{Click URL}}.indexOf({{Page Hostname}}) > -1;
    }
  • Set the trigger to fire when Offsite Check equals false.

Outbound links that remain on-site

If you want to track outbound links that go to other pages on your site, you need to again make the trigger slightly different.

  • On “Enable this trigger when all of these conditions are true,” make the content
    Page URL matches RegEx .*
  • Change “This trigger fires on” to All Link Clicks