Subscribe:   Posts   |   Email   |   Facebook   |   Twitter

Internet Marketing and Web Development in Higher Education and other tidbits…

Tracking outgoing clicks with Google Analytics

05 Dec 2008

written by Nick DeNardis

Tracking outgoing clicks with Google Analytics

I wanted my first post as a .eduGuru to be something spectacular, unfortunately all the ideas I had were taking too long to write, so here is something short and sweet.

Building on my last post, Tracking Flash Interaction with Google Analytics, I showed how to track flash actions with Google Analytics. The pageTracker._trackPageview() function is key to this tracking, but it can also be expanded past flash and into the uncharted territory of “outgoing links.”

In the analytics world outgoing links are the black hole of tracking, people are on your site, they click, and are gone forever. After stumbling on the article Google Analytics Tip by the Texas A&M Webmasters I decided to expand on it.

Instead of having the javascript called inline for every link, with one simple jquery (or your favorite javascript library) call it can be added to all the anchor tags with an external reference. Right now the example below is limited to just “http://” for proof of concept.

Here is how it works

1. Load the newest version of Google Analytics on your page. (this include must be loaded before any clicks can be tracked)

<script type="text/javascript">
  var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
  document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js'
  type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
  var pageTracker = _gat._getTracker("UA-xxxxxx-x");
  pageTracker._trackPageview();
</script>

2. From there include jquery

<script src="http://jqueryjs.googlecode.com/files/jquery-1.2.6.min.js"
type="text/javascript"></script>

3. Run this script on document load to attach the “click” to all the external links

<script type="text/javascript">
  $(document).ready( function() {
    $('a[@href^="http://"]').click( function() {
        pageTracker._trackPageview('/outgoing/' + $(this).attr('href'));
        return true;
    });
  });
</script>

Voilà! Check out your Google Analytics and search for “/outgoing” in your Top Content area to see the most popular outgoing links.

Later Expansion

To expand on this example for production use, it is wise to also include “https://”, “ftp://” and exclude any “http://[yourdomain.edu]/” from tracking since those will go to internal pages even though they have a fully qualified URL in the attribute.

Warning

These new “/outgoing” links WILL show up as “visits” in your site on Google Analytics potentially skewing visitor hits. I recommend setting up an addition Profile for “Outgoing Tracking” and include only traffic from “^/outgoing/”. In addition exclude “^/outgoing/” from your main profile.

The content of this post is licensed: ©2008 All Rights Reserved


About the author

Nick DeNardis

Nick is the Associate Director of Web Communications at Wayne State University by day. By night he hosts the video blog EDU Checkup where he reviews higher education web sites live. Nick is an active member of the higher education web community and is an officer of Refresh Detroit, a group of web professionals whose goal is to promote web standards, usability, and accessibility.

Nick DeNardis Nick's Facebook Nick's LinkedIn Bio Nick's Twitter Account Nick's Flickr Photos Nick's YouTube Profile Nick's Digg Profile Nick's Delicious Bookmarks Nick's StumbleUpon Nick's SlideShare Presentations Nick's Last.FM Music

This post was written by - who has written 31 posts on .eduGuru


  • http://webmaster.tamu.edu Ben Floyd

    Also check out the Google AJAX API for common javascript APIs (such as jQuery) at http://code.google.com/apis/ajaxlibs/. It uses Google’s Content Delivery Network (CDN) to serve up the javascript file instead of using your local network bandwidth.

  • http://doteduguru.com Kyle James

    Genius! Quit simple, but incredibly effective. Of course you have to do some extra work in GA to get your filters and profiles setup properly, but talk about a whole new wave of premium intelligence.

    I’d recommend setting up a profile that filters out the “outgoing” subdirectory.

  • http://missouri.edu/ Gilzow

    Good post. We did something almost identical this year at missouri.edu (http://is.gd/ap0W) and have been very pleased with the results. Kyle is correct in that you have to set up filters to really get a better sense of the data.

    Setting up a second profile to record this data is a great idea that I hadn’t considered.

  • http://educheckup.com/ Nick DeNardis

    @Ben Good point, we have just begun working with the new AJAX API, its super nice. Will eventually do a followup post on it.

    @Kyle Simple and effective for sure! I just realized how many external clicks we were getting. Now I know where all those “bounces” are going.

    @Gilzow Nice work man! That is some good work. You find anything interesting with the results?

  • http://3.7crea.tv Ross Johnson

    Excellent tip, I can see a lot of uses for this.

    See what type of content users are interested in.

    See if any ill placed external link could be decreasing your conversion rate in the conversion funnel.

    probably more.

  • http://www.advanced-web-metrics.com Brian Clifton

    Nice post Nick. Also have a look at the following: http://www.advanced-web-metrics.com/blog/2008/06/08/updated-tracking-script-for-gajs/

    (originally from Sep 2007!)

    Info there for both urchin.js and ga.js users

    I would be interested in your comments.

    Best regards, Brian Clifton

  • http://educheckup.com/ Nick DeNardis

    @Brian Nice article! I am surprised I did not stumble on it before. I like your approach, it is definitely more robust than my proof of concept.

    I like that you supplied some analytics with your post. We just started doing this and are just acquiring analytics.

    With your results have you made any changes to the way you post or how you link to external sites?

  • Pingback: Trending Upward | Poorly Performing Pages - How Do We Know?

  • http://netvantagemarketing.com Adam

    This really is a handy metric that people need to measure. I have a client that has a site which is basically just an online directory, so it’s nothing but outgoing links.

    This will be the only real analytics of interest – seeing where we’re sending them. Can’t wait to get it up and running.

  • http://missouri.edu/ Gilzow

    @Nick the most interesting thing we have seen so far is that students use our main page frequently to get to the student webmail portal instead of just typing webmail.mizzou.edu in their browser.

    @Brian Clifton you have XSS vulnerabilities at your website ;-)

  • http://www.tamu.edu/ Erick

    @Gilzow exactly the same thing we saw when we put it on our front page.

  • Pingback: Top 10 .eduGuru Posts of 2008 | .eduGuru

  • http://www.sgclub.com jl255

    Hi, tks for this great tip! Would you be able to provide some guidance on how to set up new profiles and filtering on Analytics to make sure the right traffic is tracked? I’ve no idea how to do that. TKs!

  • http://www.iandowens.com Ian

    Thanks for the tutorial. Exactly what I was looking for. I appreciate your time for the post!

  • Will

    uncaught exception: Syntax error, unrecognized expression: [@href^="http://"] I got this guy. It works if you remove the @ as of jquery 1.3.2

  • http://www.bestcellphonetracker.com Daniel

    That is great information. Im glad that I can relate to this sorta stuff. I know if you have any cell phone tracking software problems you can just use this Cell Phone Tracker

  • http://chenado.net mev

    To track clicks on outbound links can also be used _trackEvent. It is much more comfortable and functional ( i posted about it here http://chenado.net/en/1029.html )

  • Brad Dunn

    If you want to make sure that the script filters out your domain from the selection, modify the selector to:

    $(“a[href*='http://']:not([href*='"+window.location.hostname+"'])”)

    source: http://www.thewhyandthehow.com/tracking-outbound-links-with-jquery-and-analytics/

    • Brad Dunn

      Where are my manners? Great article, by the way. Glad I read through it.

  • http://nickdenardis.com/ Nick DeNardis

    Brad,
    Thanks for the additional code! Glad you enjoyed the article :-)

Proud Member of BlogHighEd University Web Developers eduStyle

© .eduGuru - Internet Marketing and Web Development in Higher Education and other tidbits…. Powered by Wordpress. | Advertiser policy