Using Campaigns to track Category Popularity in WordPress and Google Analytics
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.
In my last post, I discovered a means of tracking WordPress categories by dynamically passing the category names in the script code for Google Analytics. The problem with the approach is that each time you instantiate the tracking function, it results in a page view. So, if you have multiple categories identified, you wind up executing multiple page views. Yuck!
So I did some digging and identified that you can set up a campaign in Google Analytics and capture the category names as keywords for that campaign. With some minor changes in the code, you can easily build a campaign, called “Category”.
Modifying your Analytics Code
Within your site’s footer, you will find your Google Analytics script tag:
<script type="text/javascript">
_uacct = "UA-xxxxxx-x";
urchinTracker();
</script>
And replace that with this code (be sure to substitute your UA- code in lieu of the xxxxxx-x):
<script type="text/javascript">
_uacct = "UA-xxxxxx-x";
<?php if (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>
You must now set up a custom filter for your campaign! Within a couple days, you’ll be able to track campaigns in Google Analytics! The campaign name will be “category”, the ad source will be “post”, the ad type will be “request” and the version will be “1.0″!


_ucsr=”post”;
_ucmd=”request”;
_ucct=”1.0″;
…all required or can I get away with just adding a campaign name and campaign terms?
_uccn=”keywords”;
_uctr=”list,of,keywords”;
I’m still fine-tuning and have changed quite a few things in my filters since writing this. You won’t believe it… but I can’t remember how I set it up! (Doh!) I need to do some reverse engineering.
Unfortunately, Google Analytics has some terrible documentation!
Doug