Segmentation in Google Analytics for WordPress Readers

    October 16, 2007

One of the things I’ve been wanting to do for a while seems to be finally nearing completion. Google Analytics allows you to segment users into custom segments, and there’s one segment I’ve been aching for.

I want to be able to segment RSS readers, to be able to see the different browsing behavior of new visitors versus my loyal visitors.

Getting to the point where I actually can acquire that data has been a pretty long ride. I first had to create a way to change the URL’s used in RSS feeds, so I could detect this different URL, 301 redirect it to the right URL, and set a cookie while doing that. To do that I filed a bug in WordPress’ Trac, which I wrote a fix for as well, someone else improved on it, and it was committed into the WordPress core. As of WordPress 2.3, you can apply a filter to the_permalink_rss, which allows me to add ?source=rss to any URL (or &source=rss when the blog uses the default ?p= permalinks).

The next step is detecting that parameter in the URL, and 301 redirecting to the original post URL. Before doing that 301 redirect however, I drop a cookie, which lasts for 30 days, identifying the user as an RSS reader. This allows me to, in the last step, add the following code to the Google Analytics script tag when the user has that cookie:

  1. __utmSetVar("RSS");  

I will know if this works tomorrow, and if it does, I’ll release a new version of my Google Analytics for WordPress plugin with this possibility in it. Since I can imagine other people want to identify RSS readers for other purposes, I’ll release that small bit of code as a single plugin as well.