Jun
9th

Google Analytics and WordPress: Measuring Category Popularity

Thanks for stopping by my personal blog on Marketing Technology! Over 50,000 visitors a month find my content worth returning for, so don't forget to subscribe to the Marketing Technology Blog RSS feed or to the Marketing Technology Email to have new content sent directly to your inbox. You may also find my other business blog helpful, Social Media Domination.

UPDATE: This methodology will pass multiple page views for a single event and may not be the right direction to go! Please check my next blog post on how to utilize Google Analytics Campaigns to Track Categories as Keywords.

After spending a few hours of analyzing my blog’s post data and combining it with the Analytics data from Google, I decided there had to be an easier way. And there is!

Google Analytics allows you to register additional data with each page that’s viewed. If you look at your code in each of your pages, it looks like this:

<script type="text/javascript">
_uacct = "UA-xxxxxx-x";
urchinTracker();
</script>

You can pass information dynamically to Google by passing the information in the urchinTracker function, like:

urchinTracker(’Track This Information’);

With WordPress, it’s a little more complex since each page is dynamically generated. A post may belong to multiple categories so you need to register each. On a multiple post page, you probably only want to push the first posts’ Categories. On a single page, you pass whatever categories there are for that post or page. With a good template, though, all of that code resides in the footer so the code can get a little complex.

Category Code

Here’s what I came up with:

<script type="text/javascript">
_uacct = "UA-xxxxxx-x";
urchinTracker();
<?php if (have_posts()) { ?>
<?php while (have_posts()) : the_post(); ?>
<?php if($post==$posts[0]) { ?>
<?php
foreach((get_the_category()) as $cat) {
echo "urchinTracker(’/category/".$cat->cat_name."’);\n";
} ?>
<?php } ?>
<?php endwhile; ?>
<?php } ?>
</script>

On pages with posts, the code will loop through the categories for the first post and register those categories with Google Analytics.

Google Analytics Content Drilldown

In content drilldown, I can simply click ‘category’ and I get a count of views by category… whether it’s a single post, my home page with multiple posts, or if someone actually does click on category!

Google Analytics Categories

If you copy and paste the code, be sure to clean up the apostrophes and use your own UA (Google Analytics Code) identifier!

RSS feed | Trackback URI

4 Comments »

Comment by no imageAde (SezWho)
2007-06-10 07:36:46

This is very cool Doug. I had no idea you could tweak it like that. So I started digging further….

Looking at the example on this help page it seems like each call to urchinTracker() represents a new page view. So with your code in your post (and in the HTML of your site) it looks like you’re counting a page view per category for just one view.

Let me know if that doesn’t seem right to you. I just don’t want you ending up like those you describe at http://www.douglaskarr.com/2007/06/07/cookie-deletions/ :)

Rate this:
2.9
Comment by no imageDouglas Karr (SezWho)
2007-06-10 10:55:29

It’s true! I’m seeing that as we speak. I tend not to track page views as much as visitts so it doesn’t bother me too much. However, I’m going to do some more digging and see if I can eliminate the duplication and pass multiple variables in a call.

I’m also trying to see how I can combine this with the conversion data from adsense to see what the most ‘profitable’ categories are.

More to come!

Rate this:
2.9
 
Comment by no imageDouglas Karr (SezWho)
2007-06-10 12:00:46

Ade,

I found a much better way to actually analyze categories utilizing Google Analytics campaigns. And, it won’t result in this mess!

One note, the method above is great for Ajax applications. You can actually put commands in your onclick events rather than your pages to follow users through your system.

Thanks for calling this to my attention! It made me dig a little deeper.

Doug

Rate this:
2.9
 
 
2007-06-10 11:55:59

[...] Subscribe to Feed to Email « Google Analytics and WordPress: Measuring Category Popularity Jun [...]
 
Name (required)
E-mail (required - never shown publicly)
URI
Your Comment (smaller size | larger size)
You may use <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> in your comment.

My Comment Policy: I moderate comments. Please be patient:

  • Spam will happily be destroyed.
  • Use your real name, not some keywords. Otherwise it will be destroyed.
  • Mean comments aren't necessary. If I don't post them I will reply personally to let you know why.
  • Lewd comments will be edited, I don't want my readers leaving because of offensive content.
Great debate, criticism and colorful commentary is always appreciated and approved!