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














Pingback: Trending Upward | Poorly Performing Pages - How Do We Know?
Pingback: Top 10 .eduGuru Posts of 2008 | .eduGuru