Feed Tracking

Feed Tracking

I set up a Feedburner account to try to track this site’s syndication activity. Feedburner repackages your syndication feeds so that’s possible, since a feed is not an actual web page viewed in a browser. If they were, you could track them through your web logs or a service like StatCounter. Up to now, I had no idea how many people were visiting this site through RSS readers (such as Firefox’s Live Bookmarks) or through an agregator like Bloglines.

Geeky notes follow on how I implemented this, so I don’t forget.

Some Background

Feedburner works by republishing an existing RSS feed on their own web server, which allows them to collect the tasty statistics that are otherwise unavailable through normal web page counters. Web Page counters work through HTML and Javascript, which are features only available on…web pages! Since RSS is not a web page, the HTML/Javascript tricks that power web counters aren’t available. You’ve got to collect the data on the server side.

Just so you know, you theoretically don’t need to use a service like StatCounter or Feedburner to get site statistics if you already have access to your web server logs. However, extracting the information from server logs is a tedious affair compared to visiting a spiffy service provider that makes all that data pretty to look at. These services also do additional processing to weed out duplicate data. It’s totally worth it.

The Game Plan

The tricky part is that I already had the default WordPress system feed in service, and I knew that people had subscribed to it. The last thing I wanted to do was send an email out telling everyone to switch over, and I’m not sure how to even tell RSS aggregators like Bloglines to update (maybe a redirect is a feature of RSS, but I didn’t know).

So I did the switcheroo as described in the Feedburner forums:

  1. Create a separate feed URL just for Feedburner
  2. Point Feedburner to the new, separate feed URL
  3. Redirect your old feed URL to Feedburner, so current subscribers are happy

Doing this is a little involved (hence these notes), so you might consider using that nice Feedburner WordPress Plugin that does all this for you. If you have a tweaked version of your .htaccess file, you may have to do everything manually (which is the only reason I’m not using it).

Be Warned! There is the real possibility of screwing up your website! Not permanently, but you will probably have to recreate your .htaccess file via the WordPress admin panel.

If that happens, go to Options->Permalinks, scroll to the bottom of the page, and you’ll see what your .htaccess file should look like, assuming there was nothing else special about it…

1. Setting Up The New Feed URL

The first step is to create that private Feedburner URL (step 1). Only Feedburner uses this URL; it’s the source RSS that FB will redistribute and track.

I create the private Feedburner URL by duplicating the existing mod_rewrite rule for the WordPress feed, located in the almighty .htaccess file. The following line:

RewriteRule ^feed/(feed|rdf|rss|rss2|atom)/?$ /index.php?&feed=$1 [QSA,L]

…becomes two lines; the second line has been changed from “feed” to “feedburner”:

RewriteRule ^feed/(feed|rdf|rss|rss2|atom)/?$ /index.php?&feed=$1 [QSA,L] RewriteRule ^feedburner/(feed|rdf|rss|rss2|atom)/?$ /index.php?&feed=$1 [QSA,L]

[note] These RewriteRule lines are a single line, but wrap when displayed in this article format. So pretend everything is just on one line everwhere you see RewriteRule…[/note]

So the new private URL, for use only by Feedburner is:

https://davidseah.com/feedburner/rss2

You’ll “burn” this URL in step 2. Note that we haven’t updated the OLD feed URL yet…that happens in step 3.

2. Setting Up Feedburner

Ok, go to feedburner.com and get a new feed URL. This is the one we want everyone to use, because Feedburner will be tracking hits to it. Mine looks like:

http://feeds.feedburner.com/DavidSeah-BetterLivingThroughNewMedia

Then I specified what feed to burn…it’s the new FeedURL from the previous step:

https://davidseah.com/feedburner/rss2

You’re done with Feedburner setup, so on to Step 3!

3. Redirecting the Old Feed to Feedburner

Now, to point the old FeedURL to the new, we just modify the existing rewrite rules. It’s back to the .htaccess file! There are two lines that need modification in my file:

RewriteRule ^feed/(feed|rdf|rss|rss2|atom)/?$ /index.php?&feed=$1 [QSA,L] RewriteRule ^(feed|rdf|rss|rss2|atom)/?$ /index.php?&feed=$1 [QSA,L]

…are edited to point to FeedBurner, instead of the WordPress Feed PHP:

RewriteRule ^feed/(feed|rdf|rss|rss2|atom)/?$ http://feeds.feedburner.com/DavidSeah-BetterLivingThroughNewMedia [QSA,L] RewriteRule ^(feed|rdf|rss|rss2|atom)/?$ http://feeds.feedburner.com/DavidSeah-BetterLivingThroughNewMedia [QSA,L]

And that pretty much seems to do the trick.

Test your feed URL on your website (it should look all different now, if it’s properly coming from Feedburner.com). Test bloglines. Test Live Bookmarks. Check your HTML code for the meta tags that define your syndication feeds. Sometimes it takes a while for the agregators to catch on to the change, so wait a while before checking. You might have to flush your browser cache also, if you are checking the RSS link manually.

If you are using a caching plugin for WordPress, you may have to add the new /feedburner URL to the do not cache list. This bit me on the ass a couple of times.

Note 1: I’m not very familiar with mod-rewrite, but I did have to change the top rule that looks like this where it says 49, because this is the number of lines (I think) that the rewrite condition works with. If you don’t increment the number, the very last rewrite condition won’t be used, which will break your site in a subtle fashion. The line looks something like this, and is at the very top:

RewriteRule ^.*$ – [S=49]

Note 2: You could also theoretically modify your WordPress installation if you know PHP, but it would be a significant amount of work that Feedburner has already done. And besides, I like to run my WordPress installation as vanilla as possible to make security updates easier. It would be nice if future versions of WordPress provided the option for “hosted RSS feeds”as the current code embeds meta tags in your HTML that point to the default WordPress RSS feed URL. Even better, it would be nice to get a hook to the RSS reading…I wonder if you could snag the referrer from one of the_rss action or something similar and build it into a plugin…but there’s still a lot of annoying data collection and management you’d have to do.

6 Comments

  1. David W. 19 years ago

    I just found a reference for that [S=n] thing:

    ‘skip|S=num’ (skip next rule(s))
    This flag forces the rewriting engine to skip the next num rules in sequence when the current rule matches. Use this to make pseudo if-then-else constructs: The last rule of the then-clause becomes skip=N where N is the number of rules in the else-clause.

  2. John Zeratsky 19 years ago

    Excellent notes, David! Very thorough!

    Another thing that makes feed stats difficult (and the reason most people use us) is that it’s almost impossible to figure out how many actual people are reading your feed by looking at hits in your server logs. For example, My Yahoo may only update your feed twice a day, but thousands of people could read your feed there. On the other hand, my local copy of NetNewsWire updates itself every hour, but I’m the only one who uses it.

    Our system looks at hits, IP addresses, user-agent self-id, and tries to line it all up to create (what we think is) a good measure of the actual number of subscribers you have.

    Thanks again for the awesome review and tutorial.

  3. Dave 19 years ago

    Thanks for the additional notes, John, and for providing such a great service. The user experience there is just fantastic too…awesome!

  4. John Zeratsky 19 years ago

    Thanks for the very kind words. Please let us know if there is anything we can do to improve upon the user experience in any way. We’re making tweaks all the time, and always looking to improve!

  5. Tim 19 years ago

    Does this re-direct all feeds or just RSS? I’ve done with for my RSS feed, but now I’m trying to figure out what to do with the wordpress atom feed.

  6. Dave 19 years ago

    Hi Tim,

    In this example, I’m only redirecting RSS specifically to Feedburner, and not doing anything with atom. I should probably do something about that. The two RSS feeds are directed to Feedburner, but Atom is not.

    I have SmartFeeds turned on for my feeds, so I’m going to redirect the atom feed also to the same URL. I have no idea what uses Atom, so I’ll have to see how this works.