Tracking outgoing clicks with Google Analytics

By Nick DeNardis - Fri, Dec 5, 2008-->


Analytics, Web development, Webmaster Tools

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 “https://” 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"></script>
<script type="text/javascript"></script>

2. From there include jquery

<script src=""

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^="https://"]').click( function() {
        pageTracker._trackPageview('/outgoing/' + $(this).attr('href'));
        return true;

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 “https://[]/” from tracking since those will go to internal pages even though they have a fully qualified URL in the attribute.


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.

Share StumbleUpon It! reddit

Like this post? Be sure you've subscribed to the .eduGuru RSS feed or email to get all the latest news and articles.

Analytics, external, google, javascript, links, tracking

Read Related Posts on .eduGuru:

  1. Tracking Flash Interaction with Google Analytics
  2. 3 Quick Tips to Tag and Track with Google Analytics
  3. Wofford Monthly Web Analytics Summary - March 2008

This post was written by:

Nick DeNardis

Nick DeNardis - who has written 26 posts on .eduGuru

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's LinkedIn Bio

20 Responses to “Tracking outgoing clicks with Google Analytics”

  1. Avatar image
    Ben Floyd Says:

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


  2. Avatar image
    Kyle James Says:

    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.


  3. Avatar image
    Gilzow Says:

    Good post. We did something almost identical this year at ( 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.


  4. Avatar image
    Nick DeNardis (author) Says:

    @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?


  5. Avatar image
    Ross Johnson Says:

    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.


  6. Avatar image
    Brian Clifton Says:

    Nice post Nick. Also have a look at the following:

    (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


  7. Avatar image
    Nick DeNardis (author) Says:

    @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?


  8. Avatar image
    Adam Says:

    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.


  9. Avatar image
    Gilzow Says:

    @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 in their browser.

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


  10. Avatar image
    Erick Says:

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


  11. Avatar image
    jl255 Says:

    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!


  12. Avatar image
    Ian Says:

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


  13. Avatar image
    Will Says:

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


  14. Avatar image
    Daniel Says:

    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


  15. Avatar image
    mev Says:

    To track clicks on outbound links can also be used _trackEvent. It is much more comfortable and functional ( i posted about it here )


  16. Avatar image
    Brad Dunn Says:

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




    • Avatar image
      Brad Dunn Says:

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


  17. Avatar image
    Nick DeNardis (author) Says:

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



  1. Trending Upward | Poorly Performing Pages - How Do We Know? says:

    [...] actual exit links (as opposed to someone closing out of your site via the browser), check out the great post by Nick DeNardis on .eduGuru about tracking exit links in Google [...]

  2. [...] Tracking Outgoing Clicks with Google Analytics [...]

Leave a Reply

Spam protection by WP Captcha-Free