Showcase related content to keep visitors clicking

Posted

I've drummed up a lot of visitors by posting links on dzone and StumbleUpon, but the visitors aren't very sticky -- many will visit the single page I linked to and then move on. Looking at my site exits in Google Analytics, I noticed that my category pages had much lower exit rates than my single post pages. This wasn't exactly a surprise, if I thought about it: a visitor to a single-post might see my list of recent posts, but there was no guarantee that any of them would be related to what they came to the blog to read about. Visitors to category pages, on the other hand, would see a collection of related content. I wanted to give visitors an easy way to see other posts that might interest them, so I just installed the Other Posts from Category plugin. The plugin adds links to posts that are in the same category (or categories) as the main post, and it's very configurable via the Wordpress admin. It didn't make sense to me to just have the list at the end of the post -- visitors might never make it there to discover other items that would interest them. A jQuery one-liner copied the list and put it at the top of the post, too:

$('div.ddop').clone().insertAfter('div.post p.byline');
I'll be watching my pages per visit and site exit metrics to see whether it makes a difference --

Filed under  //  analytics   blogging   seo  
Comment (1)
Posted

Track outbound clicks with Google Analytics and jQuery

Posted

Update: Make sure you check out the new _trackEvent method of the Google Analytics pageTracker method. If your analytics account offers event tracking, this is the right way to do it if you don't want your events to count as pageviews. I've written a new post about tracking outbound clicks using the new method. -- Sometimes, you may want to know what outbound links a user is clicking on -- say, if you're linking to an affiliate's site and want to be able to count the clicks you're sending. Google Analytics offers this bit of code to accomplish this:

and says:
Google Analytics provides an easy way to track clicks on links that lead away from your site. Because these links do not lead to a page on your site containing the UTM JavaScript, you will need to tag the link itself. This piece of JavaScript assigns a pageview to any click on a link - the pageview is attributed to the filename you specify.
Two problems here: one, it's Javascript in an onclick tag, which is ugly and bad; two, you've got to add that to every link you want to track. No fun. Progressive enhancement says you should use Javascript to add behaviors that will only work with Javascript. I wanted to add this tracking ability to my blog, to see which outbound links people were clicking on. jQuery to the rescue:
$('a').each(function() {
  var $a = $(this);
  var href = $a.attr('href');

  // see if the link is external
  if ( (href.match(/^http/)) && (! href.match(document.domain)) ) {

    // if so, add the GA tracking code
    $a.click(function() { 
      pageTracker._trackPageview('/outgoing/' + href);
    });
  }

});
In my case, I wanted to track the post title (if there was one), in addition to the outgoing link's href. So:
$('a').each(function() {
  var $a = $(this);
  var href = $a.attr('href');

  if ( (href.match(/^http/)) && (! href.match(document.domain)) ) {
    $a.click(function() { 
      // get the post title if there is one 
      // and add it to the string for tracking
      var postTitle = $a.parents('div.post').find('h2:first');
      href = href.replace('http://',''); // cleanup for nice GA reports
      href = (postTitle.length > 0) ? postTitle.text() + '/' + href : href;

      pageTracker._trackPageview('/outgoing/' + href);
    });
  }

});
You can use the same method to unobtrusively add tracking code to file downloads:
var fileTypes = ['doc','xls','pdf','mp3'];

$('a').each(function() {
  var $a = $(this);
  var href = $a.attr('href');
  var hrefArray = href.split('.');
  var extension = hrefArray[href.length - 1];

  if ($.inArray(extension,fileTypes) != -1) {
    $a.click(function() { 
      // get the post title if there is one 
      // and add it to the string for tracking
      pageTracker._trackPageview('/documents/' + href);
    });
  }

});
See Google's help page for more information. Note that this example assumes you're using the new tracking code; you'll have to adjust accordingly if you're using the old tracking code. If you're using the new tracking code, it will look like this:
var pageTracker = _gat._getTracker("UA-XXXXXX-X");
pageTracker._initData();
pageTracker._trackPageview();

Filed under  //  analytics   google analytics   howto   jquery   progressive enhancement   seo  
Comments (6)
Posted