External Link Tracking with Google Analytics - The Right Way
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:
How to measure outbound clicks from your site using Google Analytics and Tag Manager https://t.co/U8jLdCIaSv /by @ThomasPetracco #measure pic.twitter.com/AaP8rGsfnI
— Google Analytics (@googleanalytics) May 13, 2019
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.
Outbound/External Link Tracking
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:
- Type = Auto-Event Variable
- Variable Type = Element URL
- 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:
- Trigger Type = Click - Just Links
- Check Wait for Tags
- Check Check Validation
- Enable this trigger when… = Page Path contains /
- Check Some Link Clicks
- 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:
- Tag Type = Google Analytics - Universal Analytics
- Track Type = Event
- Category = External Links
- Action = Click
- Label = {{Click URL}}
- 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.