Joe Hessert
  • Writing
  • Business
  • SEO

Search Engine Optimization

Google Analytics External Link Tracking

10/8/2017

23 Comments

 
Google Analytics External Link Tracking

Outbound & External Link Tracking with Google Analytics

If you have a website, you probably use Google Analytics to keep track of, well, just about everything.

And while the default set-up of Google Analytics does a good job of tracking where your site traffic is coming from, and how users move around your website, one thing that isn't tracked out-of-the box is events, or interactions by your users.

Knowing how your site's visitors are interacting with your content allows you to gain a lot of insight about what's working (and what isn't). The more you know, the more you can do to improve the performance of your website.

One of the first types of event tracking you should set up (especially if you do any affiliate marketing), is external link tracking in Google Analytics. It's easy to do, and there are several approaches you can take to effectively track external link clicks by your website users.

​In this article I'll provide an overview, and guide, for 3 ways to set up event tracking for external links in Google Analytics. Hopefully one of the approaches outlined here is the right fit for you!

3 Simple Ways to Track External Link Clicks with Google Analytics

3 Ways to Track External Link Clicks in Google Analytics
Here are 3 simple ways to track external link clicks in Google Analytics. I'll explain each method in this article, and walk you through how to successfully implement them, and provide useful resources from around the web.
​
  • Manually Add Event Tracking to the Code of Individual Links
  • Add a Site-Wide Script to Track External Link Clicks in Google Analytics
  • Use Google Tag Manager to Track External Link Clicks
​

How Event Tracking in Google Analytics Works

Setting up Event Tracking in Google Analytics is a fancy way of saying that you have javascript on your site that monitors user actions on your website, and tracks those actions in a way you've specified to your website's Google Analytics view. Events like page load are tracked by default in Google Analytics, but you can add custom event tracking to monitor user downloads, ad clicks, video plays, link clicks, and more.

In order for the actions that users take on your site to be recorded in a way that makes sense, webmasters should first determine which types of interactions are most important to them, and then set up event tracking with clear and concise labeling, so that it's easy to understand and interpret the data that Google Analytics records.

When event tracking is set up, Google Analytics fires off data which includes 4 primary labels, 2 of which are required. These labels are:  
Field Name Value Type Required Description
eventCategory text yes Typically the object that was interacted with (e.g. 'Video')
eventAction text yes The type of interaction (e.g. 'play')
eventLabel text no Useful for categorizing events (e.g. 'Fall Campaign')
eventValue integer no A numeric value associated with the event (e.g. 42)
Link Tracking: Google Analytics Events
The way you label each event field name will determine how it shows up in your Google Analytics view.

​For example if you are setting up event tracking for outbound links in Google Analytics, you might set the eventCategory to "outbound" or "oubound link," the eventAction might be defined as "click" or "link click," and the eventLabel could be set to be defined with a label of your link ... something like "Sidebar Ad #1" or the actual URL of the link that's clicked (href.match).

The eventValue field is optional, but if you want to have a numeric value (monetary or otherwise) associated with the event action, you can add one.

If  you plan to do a lot of event tracking on your website, take your time and plan out how you'll categorize these events ... that way you can quickly check on the performance of different types of events (i.e. "How are my Video Plays Doing?" or "What Are the Most Popular Downloads on My Site?" or, "Which forms are people interacting with most?"
 

How to Add Google Analytics Event Tracking to Individual Links

If you don't have very many external links to track, or you want to track internal link clicks to pages to evaluate blog sidebar links, footer links, navigation links, etc. to determine what content your users are most interested in, you can add the event tracking manually to individual links on your website within the link code.

I wouldn't recommend doing this if you are an affiliate adding links to products and services throughout every post and page, but if you run a small blog, and are just curious about the performance of certain links, or want to test a few different landing page layouts during a paid campaign, this is a good option.

Here's the code you'll want to add to your links within the <a> brackets:




So that when your link code is finished it will look like this:



Of course you'll want to label the event fields appropriately for your site, updating the eventCategory, eventAction, and eventLabel text to something that is easy to remember and identify, so that the data you collect is easy to understand.

If you have a value you want to associate with each event,  you can add that as a fourth label field in the exact same way.

​After adding this code to your links, you can check your Google Analytics view in real time after clicking the links with event tracking, and if it's properly implemented, you should see the events firing, and the clicks being recorded.

How to Track All External Link Clicks in Google Analytics with 1 Script

The simplest way to track all outbound link clicks if you aren't using Tag Manager is to add a single script to the footer of your website, which I've provided below to help save you time. While I didn't write this code (credit to SitesForProfit.com), I have tested it on some of my websites and it works flawlessly if you have a Universal Analytics install on your website.

The way it works is that it tracks all outbound link clicks, skipping over any link clicks which lead users to other pages on your website (this is already tracked in GA). This script will label these events in the "outbound" eventCategory, with "click" as the eventAction, and use the destination URL as the eventLabel.
I like this method because it's a fast and easy solution if you have Universal Analytics for your website. Simply add the above code to your footer, below your existing GA script, publish your site, and verify that events are firing by clicking an external link on your website and checking in Google Analytics to confirm that the event shows up. Simply go to Real Time > Events in Google Analytics, and look for the event to fire immediately after you click an external link.

This is a perfect solution for affiliates who have a website with links already in place, but who aren't using Google Tag Manager. Rather than adding event tracking to individual links, simply drop this script in your site footer, and you'll have all of your external/affiliate link clicks tracked in Google Analytics. This way you can quickly set up a goal based on this event to see how each page or blog post is converting, discover which links are getting clicked most, and further optimize your website to get more affiliate referrals from your traffic.

Tracking External Link Clicks with Google Tag Manager

Good news - Google is making it easier than ever before to track events and monitor user interactions with your website. Google Tag Manager makes it easy for folks without much experience coding or writing scripts to add event tracking quickly and easily to their external links.

I've found the Google Tag Manager tutorials from Julian at MeasureSchool.com to be very clear, concise, and useful, so rather than reinvent the wheel, I'm just going to embed their terrific tutorial video and write-up the instructions he offers below the video for those who don't like watching video tutorials.

​I highly recommend his website and YouTube channel if you're new to Google Tag Manager and want to learn.   
How to Install Google Analytics Outbound Link Click Tracking with Google Tag Manager:
  1. Add a New Trigger named "Outbound Link Click" (or similar)
  2. Make it a "Click" event trigger.
  3. Set the Trigger Type to "Link Click," check "Wait for Tags, and set the Max wait time to 2000 milliseconds (2 seconds). Leave "Check Validation" clicked.
  4. To have this event fire on all pages on your site, the options for "Enable When" should be set to: Page URL > matches RegEx > .*
  5. Finally, specify that the event should fire on "Some Clicks" to have only external link clicks tracked on your website.
  6. Specify that this event tracking should fire on the following trigger criteria: Click URL > does not contain > yourdomain.com (updating yourdomain.com to reference your domain name).
  7. Go to the Variables menu, and make sure all fields under "Clicks" are triggered, so all available data is recorded for each click event triggered.
  8. Now that your trigger is set up, go to the "Tags" menu and "Add New" and label it "GoogleAnalytics - Event - Outbound Links,"
  9. Choose Google Analytics, and Universal Analytics (if that's what you have running on your site), and set the track type to "Event."
  10. Set your Event Tracking Parameters: Outbound Links > {{Click URL}} > {{Page Path}}
  11. Set "Non-Interaction Hit" to "False," which will make your outbound link clicks affect your bounce rate.
  12. On the "Fire On" menu, click "More" and select the Outbound Link Click trigger you just set up.
  13. Click "Create Tag," then test it using the Google Tag Manager debugger, and confirm the events are firing in the Real Time > Events section of your Google Analytics view.
  14. Once confirmed that everything is working properly, publish your new tag in Google Tag Manager.

Some Helpful Resources & Links

In case you didn't quite find what you were looking for in this article, here are links to a few other resources which might help you with Google Analytics external link tracking:
​
  • Guide to analytics.js (The JavaScript Library for Google Analytics)
  • AutoTrack on GitHub (Automatic and enhanced Google Analytics Tracking for common user interactions on the web)

You May Also Be Interested in This Link-Tracking Tool

Since you're obviously into tracking links, I wanted to share a tool that I've found to be helpful.

​It's called ClickMagick and it has a range of features for click tracking which can enhance your site and help you laser-target your marketing efforts. My favorite feature is their link-based re-targeting. I use this feature as an affiliate to create re-targeting ads based on specific affiliate product link clicks (so if someone clicks a link to a red kayak on Amazon, I can re-target them on Facebook or via Google Ads with an ad specific to that third-party product they were interested in). This can be a tricky thing to accomplish when you're promoting someone else's products, which is why I value this tool.

There's a 2-week free trial so you can take ClickMagick for a test drive to see if it will work for you.

ClickMagick Link Tracking

Full disclosure, I'm an affiliate of ClickMagick.

I like and use their product. I wouldn't recommend this tool otherwise.
You May Also Like:  How to Add Social Meta Tags to Your Website
23 Comments
user666
1/22/2018 05:27:31 am

How to Track All External Link Clicks in Google Analytics with 1 Script Solution is not working on my website... although i added GA code with my ID... i even added an alert in the java script code and it wasn't fired.. Can you help? maybe i am missing something

Reply
Joe link
1/22/2018 07:32:15 am

Do you have universal (vs. basic) analytics installed?

I might try stripping out the pieces you added and seeing if that helps. Should work as-is on any universal analytics site without modifications.

Reply
user890
2/23/2018 10:07:29 pm

Hello,

Ready to use solution. Thank you for putting article and info much appreciated. I used the code directly on website and it produced the results in google analytics

Is there a possibility to track "Accordion Tabs" clicks or Tab hits via extended code.

Reply
Joe link
2/25/2018 07:54:40 am

Hi there, thanks for visiting and for the comment. Tracks on accordion links or content tabs can definitely be tracked. Usually, tracking by the link ID is the easiest method. I'd recommend using Google Tag Manager to track these link clicks as events if you have GTM installed on your website. You can modify the script to reference links of a certain ID instead of links to a different domain if GTM is not an option. Good luck!

Reply
JPS
2/25/2018 06:55:54 am

Hi, your script is wrong. When i add it to my footer, it reveals some errors.

Did you verify some "(" or ")" in this script ?

For example, you start function like that :
(function trackOutbounds() {

Why this "(" before ?? I think there are some others errors in this script, it's not good

Reply
Joe link
2/25/2018 07:52:29 am

Hi JPS,

Thanks for visiting and for the comment. I see what you're saying, but the script is actually working perfectly for me on several of my sites. I didn't actually write the script (I link to the person who did), so you might visit his blog and ask him.

Reply
Calvo link
3/2/2018 05:40:46 pm

I am relatively new to the web industry.

I am trying to use the script provided below the section called, “How to Track All External Link Clicks in Google Analytics with 1 Script.”

I have never seen GA scripts in footers? All GA data I have seen is in the header. Not being a wise guy, but why would I have GA scripts in my footer, as opposed to the header (which is the only place I've, personally, ever seen GA scripts, so far)?

Reply
Joe link
3/2/2018 06:23:58 pm

Hi, Calvo

Thanks for visiting and for the comment! You can drop it in the header if you prefer, it will work the same way. I usually put it in the footer since that script is not a priority relative to other scripts (nobody will click a link until the page loads fully anyway, so I drop it lower in the page's code so the necessary stuff gets fired and renders sooner). That may not be best practice, but it's why I do it that way.

If you're using GTM then obviously the header is where you want to deploy the tag manager/analytics script.

Reply
The Tongue
4/10/2018 09:08:05 pm

You've added the an event listener to the onLick event in your href code.

Reply
Cody link
4/20/2018 12:33:36 am

Hey Joe,

Ended up here from a little troubleshooting. I had been using the GTM method and for some reason when I ONLY had the "Click URL" variable configured, the outbound link didn't pass through to Google Analytics (it showed as "not set"). After enabling all of the built-in click variables it works fine now. Any idea why?

Anyway, great article — the best write-up I've read on the subject.

Reply
Joe link
4/23/2018 01:00:53 am

Hey, Cody

Thanks for the kind words - and for sharing your experience with the "not set" issue (and what worked)!

So glad you found the article helpful.

Reply
Michael Loveridge
6/18/2018 10:53:32 am

Using the Outbound Tracking script and it was working fabulously until my WP theme updated the GA script from Universal Analytics to the new gtag.js script. Now your tracking script fails to load events. I believe it needs to be rewritten to push the new gtag event structure but I can't seem to get it right. Here is what I have so far:

gtag('event', 'click',
{'event_category' : 'outbound',
'event_label' : url},
{'hitCallback': hitCallbackHandler(url,win)},
{'non_interaction' : true
});

I would really love your thoughts on how I might get this working. Also, here is the documentation on pushing events to the new gtag.js: https://developers.google.com/analytics/devguides/collection/gtagjs/events

Reply
John
6/19/2018 10:28:37 am

The best tutorial in the internet for doing that, helped me a lot! Thanks!

Reply
Joe link
5/10/2019 04:01:47 pm

Thanks, John! Really appreciate it. :)

Reply
Laura
6/25/2018 09:46:07 am

Great write up thank you, I've bookmarked this as I know I'll forget it again next time I have to do it! On the Tag Manager one you might want to add a step before everything else to configure the variable "Click URL" otherwise it doesn't appear as an option when you are choosing variables. I haven't used Tag Manager for about a year and I forgot about doing that initially. Only took me about 10 minutes to remember why, but if I was a complete beginner I can see that it would possibly have stumped me for ages!

Reply
Vijay Lathiya link
11/28/2018 08:00:29 am

Informative post!
Thanks for sharing with us.

Reply
Integrated health and wellness link
1/25/2019 10:36:32 am

Great Blog Thank You

Reply
Andrea link
1/30/2019 04:45:05 am

Hey,

I just tried your code for tracking outbound links and it works for tracking button clicks that go to outbound domains. But somehow the links that point to outbound domains don't get tracked...Any thoughts on what I'm missing out here?

Reply
Luca
4/27/2019 05:00:49 am

Thank you for this article but I tried and didn't work.

I included the code after the analytics code and although I can see it in the source code of the page it doesn't register events in real time

I also tried to add the Tag but Google must have changed the interface since this article was created and they don't match

Reply
Patrick McGovern link
5/6/2019 09:36:28 pm

YES! The Track Outbound Link Clicks script worked! I had tried many things that did not work, since we cannot run GTM on our Shopify site. This did the trick and we immediately started seeing events under Category: Outbound in Realtime Analytics, with the URL listed under Event Label. Great stuff. Thank you!

Reply
Joe link
5/10/2019 04:00:23 pm

Glad it helped, Patrick!

Reply
Faith Taylor link
9/20/2019 11:05:29 am

Great guide, and yep - I can confirm with this guide, I was able to track my external links. Thanks for sharing!

Reply
Unwana Akpan link
10/25/2020 06:30:35 am

My bounce rate is increasing by the day, I will set up the google tag manager, thank you!

Reply



Leave a Reply.

Thanks for Stopping By

  • Writing
  • Business
  • SEO