Analytics & Testing, WordPress

Using Campaigns to track Category Popularity in WordPress and Google Analytics

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();
&lt/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”!

Google Analytics Campaigns

Download a Sponsored Marketing Whitepaper:
2018 Paid Search & Shopping Trends Report for Retailers

2018 Paid Search & Shopping Trends Report for Retailers

See how your paid search & shopping campaigns stack up against our analysis of Ecommerce industry data. Download Now

7 Comments

  1. 1
  2. 2

    Are…

    _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”;

  3. 3
    • 4

      Hi Fred,

      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

This site uses Akismet to reduce spam. Learn how your comment data is processed.