Drupal and FeedBurner

Submitted by scott on July 26, 2006 - 8:10pm.

I recently decided to play around with FeedBurner and get some useful stats on my RSS feed. If you ever wanted to know how many people subscribe to your feed, what they use, and track hits then you should check out FeedBurner. Plus it's free! (you can pay for a pro account that gives you even more ways of slicing and dicing your stats)

Instructions for integrating FeedBurner into Drupal

In order to use FeedBurner you need to tell FeedBurner where your RSS feed exists and then you need to direct all of your site visitors to subscribe not to your Drupal feed but rather to the feed that FeedBurner will create for you. This way all your feed traffic will pass through FeedBurner so they can calculate all those fancy stats.

There are several ways to integrate this. Here are a few:

  1. You could setup FeedBurner to point directly to your Drupal feed and then modify your site theme so that the RSS links point to the FeedBurner RSS url. Plus you'd also want to modify the RSS url for autodiscovery (the feature that lets your browser or feed reader detect that an RSS feed is present on the current webpage). To change the autodiscovery feature you can follow this thread on Drupal.org. Now when someone subscribes to your site they will use your FeedBurner RSS feed so you can track stats.
  2. The above option has a big problem. Those subscribers that have already subscribed to your RSS feed will still be grabbing your feed from Drupal rather than from FeedBurner. So all your current subscribers will be ignored in the FeedBurner stats. Blah. To get around this you can modify your .htaccess file and redirect your traffic to your drupal rss feed to the feedburner rss feed! Aha! It's fixed! Um, not quite... If you do this you will break FeedBurner because it also uses your drupal rss feed! So you'd be redirecting feed burner back to itself! Frustrated yet? So in order for this to work you need Feedburner to have a special "hidden" url to get to your RSS feed (that doesn't get redirected). This allows FeedBurner to get to your drupal feed and subscribers to your Drupal feed to get redirected to the FeedBurner feed. Then you could do the other hacks in option 1 to make sure new subscribers use your FeedBurner feed too.
  3. You SMRT people out there may have picked up on something. Why do we need to do all that stuff in Option 1 if we are already redirecting our Drupal feed url to FeedBurner? Good call! Simple answer? You don't! So this option is the simplified way to integrate FeedBurner. It involves creating a special "hidden" url so FeedBurner can get to your Drupal RSS feed and some rewrite rules in your .htaccess file to redirect all traffic to your drupal feed to your FeedBurner feed. That's it! This will take care of new subscribers to your feed and current subscribers with minimal fuss. This option also lets you have control over your feed since all feed requests goes through your site.

More details inside...

So how do we implement Option 3?

Here's a breakdown of how to create that special "hidden" url for FeedBurner. In Drupal you can create aliases for URLs, which is just another URL that points to something. This is done in the Administration/url aliases menu.

Adding a URL alias in Drupal

The above image shows me creating a url alias for rss.xml which is the system path for the main Drupal RSS feed. I'm creating an alias for this with a name of fbfeed. So now I can access my Drupal feed using the alias path fbfeed. In FeedBurner when you are specifying the URL of your original feed you'd type: http://www.example.com/fbfeed

Note: Obviously you need to substitute www.example.com with your actual domain name.

Now FeedBurner knows where your feed is using a special alias to it that won't be redirected. The next step is to redirect all traffic to your Drupal feed to your Feed Burner feed.

To do this you need to modify the .htaccess file in your Drupal site directory. We are going to add some instructions for our webserver to redirect traffic. Here are two ways to do this:

  1. Redirect all traffic for your drupal feed to Feed Burner feed. Insert these lines in your .htaccess file, substituting your Drupal feed URL and FeedBurner URL.
    Redirect temp http://example.com/rss.xml http://feeds.feedburner.com/YourHost
    Redirect temp http://example.com/node/feed http://feeds.feedburner.com/YourHost
  2. Use mod rewrite to redirect your Drupal feed to the Feed Burner feed. This can be handy if you have multiple domains running on the same code.
    RewriteCond %{HTTP_HOST} ^www\.example\.com$
    RewriteRule rss.xml http://feeds\.feedburner\.com/YourHost [R,L]
    RewriteCond %{HTTP_HOST} ^www\.example\.com$
    RewriteRule node/feed http://feeds\.feedburner\.com/YourHost [R,L]

    Note the [R,L] at the end of the RewriteRule. This tells mod rewrite to do a temporary redirect (302 response) and to stop processing rewrite rules.

Note: A temporary redirect (302) instructs clients that the requested resource temporarily resides at a different URI but since it's only temporary the client should continue to use this URI to connect to the resource.

What are the benefits of using temporary redirects rather than using permanent redirects or modifying your templates to point directly to Feed Burner? You don't hand over the keys to your RSS feeds to FeedBurner. Instead you are just lending them the keys for a while. Subscribers are being piped through your system to FeedBurner and not the other way around. If you ever decide not to use FeedBurner anymore...just remove the redirect and your site will serve up your RSS like normal. Or maybe another service that is better than FeedBurner comes along. All you need to do is manipulate your redirect rules and voila! All your subscribers will be updated without them having to do a thing.

On Last Note: I think these instructions will only work with clean urls turned on. You'd need to modify the URLs a bit.

FeedBurner Drupal Module

Everyone reading this might be interested in the <a href="http://drupal.org/project/feedburner">FeedBurner module</a> that I've started. It provides automatric redirection for visits that aren't by FeedBurner or FeedValidator, multiple feed redirections, user blog feed redirections, FeedFlare integration, etc.

Question

I understand that with the Drupal alias actually the feed used by Feedburner will be

www.example.com/fbfeed, which in fact will point to www.example.com/xml.rss.

 

Now I redirect www.example.com/xml.rss to the feedburner feed, which is for instance

feeds.feedburner.com/example/ghjk

so that previous users automatically grab the Feedburner feed instead of the old one.

 

This is the question: don't I have again the loop problem?

feeds.feedburner.com/example/ghjk --> www.example.com/fbfeed --> www.example.com/xml.rss --> feeds.feedburner.com/example/ghjk

 

 

Good Question

The answer is no because the alias system of Drupal does server side manipulations to determine what resource the aliased URL is requesting and serves it up. This will by-pass the .htaccess redirect rules. So the URL alias for your RSS feeds that FeedBurner uses will not get stuck in a loop as you suggest but will return the RSS feed to FeedBurner.

Great info if you use

Great info if you use Drupal, (which I plan to in the future, as soon as I get my blog up and running - Scotty, watch out, I'm going to be annoying you with questions when that happens) but what I'm more interested in is what did you find out about the traffic to your RSS feed? One of the dudes using Bloglines is me!

Quentin.

Awesome

Hey that's great news. It will be great to see you join the blogosphere! And don't hesitate to ask me questions related to any of this stuff. Drupal can be seem really complex at first, but once you get over that hurdle you really appreciate the power and flexibility it has.

As for my stats, well I'm hardly an A list blogger but I'm not aiming for fame. I do this for fun. I have roughly 8 subscribers using Bloglines, NewsGator, My Yahoo, NetNewsWire, and various other readers (some websites). According to FeedBurner I have had 25 hits in the last 3.5 hours (why 3.5??) on my feed.

Also note that these instructions, while parts are Drupal specific, the general idea can be used for any RSS feed. Especially the Redirect info (just update the paths). The main part that would be different would be the creation of an alias for the RSS feed for FeedBurner to use and that should be fairly easy.

Keep me posted on the blog!