Doug Karr Made Me Work on the Weekend!

Posted on in Software

I've been working hard lately to take back my weekends. Other than Security Updates, I generally try to stay off the computer and enjoy some downtime with the family. Of course, I still check my RSS feeds, and today I stumbled across an excellent post by Douglass Karr at The Marketing Technology Blog that I couldn't resist.

Doug is using campaigns in Google Analytics to track the popularity of categories on his website. This is an absolutely brilliant idea, and one that I had to implement immediately. Since the categories on this site are related but somewhat dissimilar (server administration vs. network administration, for example), it would be interesting to know what users are more interested in.

I implemented Doug's code and it worked fine right off the bat. I've decided that I really only want to track categories on pages where the reader's interest in the category really matters. In other words, I don't want my archive pages to have a category associated with them. The same goes for author pages, although that's obviously an interesting bit of information for multi-author sites. So, below is the code I implemented. It's merely a modified version of Doug's code that skips the meat of Doug's code if the page isn't a single post or a category page. (By the way, don't forget to change _uacct to match your account code!)

<script type="text/javascript">
_uacct = "UA-xxxxxxx-x";
<?php if ( ! (is_single() or is_category()) ) {}
  elseif (have_posts()) {
    while (have_posts()) : the_post();
      if($post==$posts[0]) { ?>
_uccn="category";
_ucsr="post";
_ucmd="request";
_ucct="1.0";
<?php $kwd = ""; foreach((get_the_category()) as $cat) {
$kwd = $kwd.$cat->cat_name.","; } ?>
_uctr="<?php echo $kwd; ?>";
<?php } endwhile; } ?>
urchinTracker();
</script>

There you have it. Thanks for calling me into the office, Doug. I really appreciate it!

Related Reading:

My Bookshelf

Reading Now

Other Stuff