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:
- Google Analytics 2.0 by Jerri L. Ledford, Mary E. Tyler
- Programming PHP by Rasmus Lerdorf, Kevin Tatroe, Peter MacIntyre
Thanks so much for the kind words! Sorry that I caused you to work on the weekend - it seems to be my modus operandi of recent! You need to move your office closer to your living room, more to come!
:)
Thanks Again!
Doug
Thanks, Doug. At the moment, the office is closer to the refrigerator. Not a bad trade-off.
;-)
I'm still having one heck of a time getting the custom filters to catch this data appropriately, though! Arrgh. Very weak documentation.
I've noticed the same thing. I'm going to be on vacation for the next week, but when I return I'll put some serious time into trying to figure out where the breakdown is. In the meantime, if you find the problem, let me know!
Just wondering if you have had a chance to figure out the custom filters. After spending hours researching how to populate the campaign variables without using a query string, this thread is the closest I have seen to a solution.
To be honest, Dylan, this has slipped through the cracks. I'll put some time into it over the next day or two and see if I can't get it working properly.