Google Analytics and WordPress: Measuring Category Popularity
Happy New Year! Marketing Technology finds and reports on the latest technology that will enable your business to effectively market to your audience, for acquisition or retention strategies. Subscribe now the Marketing Technology Blog RSS feed or to the Marketing Technology Email to have new content sent directly to your inbox. You'll 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!

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

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/
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!
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