Tracking Link Clicks to External Sites with Google Analytics

Recently I needed the ability to track outbound/external links to one of my affiliates from my website, Husky Floor Liners. I love using the the “Site Overlay” feature in Google Analytics, but noticed that all of my prime links were showing that 0% of visitors were clicking on them! I then decided to change the links that were getting clicks to affiliate links, so that hopefully my sales would increase. After a few days, I went back into the Google Analytics Site Overlay feature and saw that now almost all of my links were getting 0% clicks. I then figured out that Google did not track clicks to external websites, and that the site overlay feature was ONLY for internal links. Blast.

My Solution

I began doing a lot of research, and found that it was possible to track external link clicks with Google Analytics using a little piece of Javascript in the link code. Here is the article on tracking outbound link clicks from Google Analytics.

The article was good, but I still had a few questions that took time to find answers to. After talking to my friend Amelia, who had already figured it all out, it became clear to me. I thought I would simplify the instructions and answer them here in a way that I could understand.

  1. Your Google Analytics code needs be at the top of the page in order to use the External Link Click tracking feature in Google Analytics. So, if you area already using Google Analytics, move the tracking code from the bottom of your page, to right after the <body> tag of your page.
  2. Add this code to your links: onClick=”javascript: pageTracker._trackPageview(‘/outgoing/example.com’); For example, if you were linking to my site:(<a href=”http://andyisaacson.com” onclick=”javascript: pageTracker._trackPageview(‘/outgoing/dumbwebguy’);”>andyisaacson.com</a>)
  3. Change the “/outgoing/example.com/” to whatever you want. You do NOT have to create that actual directory on your website. Whatever you put in the _trackPageview variable will show in your Google Analytics. So, if you want to specifically track a link to my website from your website, you could put whatever you want in there to help you remember. You could put: /outgoing/andyisaacson.com, /outgoing/dumbwebguy, /guythat/thinksheknowssomething, or anything. Just make sure that you dont have that actual directory on your website.

There you go! Its really easy. Like I said, the part that stumped me was what to put in the “/outgoing…”. The answer is that it does not really matter.

Now, use this feature to your advantage. In my situation I wanted to track every external link on my site to see which one had the best click-through’s. Unfortunately, the Google Analytics External Link Clicks do not track with the Site Overlay feature. However, you can still figure out which links are doing the best by seperating the tracking directories. I created a new tracking directory name for each link on my site. Here are some examples:

/huskyliners/buynowbutton
/huskyliners/homepagepicture
/huskymats/moreinfolink

I tried to simplify this and explain things as best as possible. Hopefully I did not make things more confusing. If you have any questions, please post in the comments box below.

Author: admin

5 Comments to “Tracking Link Clicks to External Sites with Google Analytics”

  1. John Grimes says:

    The only problem I can see with this approach is that clicks on external links will be counted as page views and bundled up with the other (internal) page views in the charts and totals.

    Or does Google Analytics recognise the the /outgoing prefix and exclude these URLs from the totals?

    The other way to track external links is to use event tracking, using a function something like:

    pageTracker._trackEvent(‘link’, ‘external’, href)

  2. Emily says:

    By moving the Google Analytics code to the top under did you find that the rest of your analytics tracked as normal but now included the external link information also? I am nervous to move the code up and have the analytics for the rest of my site stop tracking properly. Any help would be appreciated. Thanks!
    Emily

  3. Emily says:

    Will this code work if you use templates on your site with your Google Analytics? For example, I only have to add my google analytics code to three templates which are used for all content to fit into automatically. Would putting the code at the top and adding the extra code into the URL work that same for template sites or is it only usable when you add the Google Analytics code to every individual Web page?

  4. AjEG says:

    I wonder if an even simpler method would be to just create a webpage on your site with a filename and page title of the external link and redirect code (like below). This way, the link is tracked in Site Overlay, and the filename will show up in all tracking. It does still count page views towards your internal, but for me that is something I can factor out in the Google Analytics reports.

    page title

  5. Gary Freeh says:

    Howdy there,Excellent blog post dude! i’m Fed up with using RSS feeds and do you use twitter?so i can follow you there:D.
    PS:Have you thought putting video to your blog to keep the people more enjoyed?I think it works.Sincerely, Gary Freeh

Leave a Reply