How To Setup FeedBurner StandardStats With Drupal

FeedBurner, the favorite feed management provider of many bloggers has just added site statistics to its StandardStats service.

Now you can use StandardStats to track not only your feed subscribers but your web site audience. But there's a couple of issues with Drupal sites. Let's see how to handle them.

I decided to move from Performancing Metrics after Nick wrote that Metrics had reached an end; it will go the open source route now.

Setting up FeedBurner's StandardStats is quite easy, and it's explained in the link provided above. I'll just focus in the line of Javascript that has to be pasted in your Drupal's theme.

If you use the code as provided by FeedBurner you won't be able to track your site visits correctly. FeedBurner's instructions don't mention it but the code has to go in your node.tpl.php file. If you've created specific files for different node types, like node-forum.tpl.php, you'll need to paste the code there as well.

Then you need to use some PHP to show just one instance of the code in the home page or listing pages, which repeat node.tpl.php many times.

The original code is:

<script src="http://feeds.feedburner.com/~s/YourFeedAddress?i=http://www.example.com" type="text/javascript" charset="utf-8"></script>

You should use that piece of code inside the block that starts with:

<?php if ($page != 0) { ?>

which is the one working when you visit a node's page.

Then to the home and listing pages. I inserted the following code in node.tpl.php:

<?php if ($id == 1 && $page == 0) { ?>
<script src="http://feeds.feedburner.com/~s/YourFeedAddress?i=http://www.example.com/" type="text/javascript" charset="utf-8"></script>
<?php } ?>

after this line:

<?php if ($page == 0) { ?><h2 class="title"><a href="<?php print $node_url?>"><?php print $title?></a></h2><?php }; ?>

That way I make sure the code appears only for the first of the many nodes listed.

It's just a start and I'm sure the code can be improved but there you have it, the all new FeedBurner StandardStats running with your Drupal site and tracking all your pages correctly.

Trackback URL for this post:

http://www.ventanazul.com/webzine/trackback/27

added a block to content area instead.

I added the code in a block instead of the template. I keep it out of admin, node add/edit pages etc. using the block admin interface.

Used REQUEST_URI instead of node_url as in the feedburner site example. Seems to work OK so far.

<script src="http://feeds.feedburner.com/~s/YourFeedAddress?i=http://www.example.com<?php print $_SERVER['REQUEST_URI'] ?>" type="text/javascript" charset="utf-8"></script>

REQUEST_URI may display different info depending on your server. But it works in my lighttpd setup.

Joe

How do I check if it works?

I've tried to setup feedsburner stats with drupal with the changes to node.tpl.php file in the /themes/engines/phptemplate/ directory.

How do I check if it's working? Do I've to wait till I see stats in Feedburner or are there other ways of checking.

Regards,
Stefan Stranger

Just take a look at your FeedBurner account

It takes an average of 24 hours to see the data on your dashboard.

Alexis Bellido

Only subscriber info

I only get subscriber info on my dashboard. I don't get any site stats. What could be wrong?

Regards,
Stefan Stranger

Drupal FeedBurner module

Just wanted to let everyone reading this know that I've been working on a Drupal FeedBurner module (http://drupal.org/project/feedburner) that helps with feed redirection and also helps with FeedFlare/StandardStats/Ad Network insertion.

FeedBurner is doing great.

FeedBurner is doing great. It will be even better as it's now a part of Google.

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <h1> <h2> <h3> <h4>
  • Lines and paragraphs break automatically.

More information about formatting options