External Link Tracking with Google Analytics - The Right Way

. Posted in: Data Collection, Data Quality
Tags: Google Analytics, Google Tag Manager

Why is it that such a simple thing as external link tracking in Google Analytics is almost always done wrong? Just today, I even saw a tweet from the official @googleanalytics account promoting a post on external link tracking:

And the post has it wrong. Sigh. Well, to be fair, this approach (which is described in tonnes of similar posts) will, in fact, track clicks on external links. But depending on which guide you follow, that’s not all it will track. You may find that you’re tracking other clicks as external (or outbound) clicks:

  • Clicks on mailto links
  • Clicks on tel links
  • Clicks on javascript links

In effect, you’ll end up with a lot of events saying they are tracking external links when they’re not. So the first problem is that you’ll get too many events. Secondly, if you have a goal based on those events, you’ll have way too many goal completions.

Actually, it all comes down to configuring the trigger in Google Tag Manager correctly. But here’s the step by step guide:

Variables

Create a new variable and name it Click Hostname. Then configure it:

  1. Type = Auto-Event Variable
  2. Variable Type = Element URL
  3. Compontent Type = Host Name

Also make sure to enable the built-in Click URL variable.

Trigger

Create a new trigger and name it click - external links. Then configure it:

  1. Trigger Type = Click - Just Links
  2. Check Wait for Tags
  3. Check Check Validation
  4. Enable this trigger when… = Page Path contains /
  5. Check Some Link Clicks
  6. Fire this trigger when… = Click Hostname does not contain yourdomain.com

Tag

Create a new trigger and name it GA EV - External Links (or whatever your naming convention is). Then configure it:

  1. Tag Type = Google Analytics - Universal Analytics
  2. Track Type = Event
  3. Category = External Links
  4. Action = Click
  5. Label = {{Click URL}}
  6. Select your Google Analytics settings variable or input your tracking ID

Done

And that’s it. From now on you’ll only track clicks on actual external/outbound links.

Obviously, you can name the variables, trigger, tag and event dimensions any way you like. In this setup, the clicked URL will be tracked in the Event Label.