Book Sale! Code WP2025 takes 20% OFF our Pro Plugins & Books »
Web Dev + WordPress + Security

Feedburner Alternative: Homegrown Feed Statistics for Your Blog

If, for whatever reason, you don’t want to use Feedburner to track your feed statistics, this article describes a relatively simple, “roll-your-own” alternative. Instead of redirecting your feed traffic through Feedburner, keep your original feed URLs and place the following code into a file named “feed_stats.php” (or whatever) and upload to your server:

<?php

$thedate = date('Ymd');
$thetime = date('h:i:s');
$logfile = "/path/to/stats/feed_stats.log";
$address = $HTTP_SERVER_VARS['REMOTE_ADDR'];
$request = $HTTP_SERVER_VARS['REQUEST_URI'];
$referer = $HTTP_SERVER_VARS['HTTP_REFERER'];
$browser = $HTTP_SERVER_VARS['HTTP_USER_AGENT'];

$logdata = "$thedate|$thetime|$browser|$address|$my_time|\n\n";

$fp = fopen($logfile, "a");
fwrite($fp, $logdata);
fclose($fp);

?>

Next, create a log file called “feed_stats.log” and enable write permissions via 755 or 777. After uploading the log file to a choice location on your server, edit the “$logfile” variable in your feed_stats.php script to reflect the correct relative file path.

Finally, include feed_stats.php in any feed-generating scripts used on your blog via the following line:

<?php include("path/to/feed_stats.php") ?>

For example, if you are using WordPress, you would place the previous include directive into each of the following files:

  • wp-rss2.php
  • wp-rss.php
  • wp-atom.php
  • wp-rdf.php
  • wp-commentsrss2.php

..depending on which feeds you would like to track. Different blog platforms have similar files, which should be described in the available literature. There is a ton of things you could do with this script. For example, you could modify the code with a few “if()/ifelse()” statements to write to a different log file for each of your different feed types. And so on. The point here, is that there are alternatives (albeit considerably less sophisticated) to the voraciously popular Feedburner service.

About the Author
Jeff Starr = Creative thinker. Passionate about free and open Web.
Digging Into WordPress: Take your WordPress skills to the next level.
Welcome
Perishable Press is operated by Jeff Starr, a professional web developer and book author with two decades of experience. Here you will find posts about web development, WordPress, security, and more »
.htaccess made easy: Improve site performance and security.
Thoughts
Replacing my elaborate 27in iMac desk setup with a 15in Macbook Air.
Launching my new plugin, Head Meta Pro 🚀 Complete meta tags for WordPress.
Migrating sites to a new server, so far so good. Please report any bugs, thank you.
Arc browser looked good but lost me at “account required”. No browsers do that.
Finishing up the pro version of Head Meta Data plugin, launch planned this month.
Finally finished my ultimate block list to stop AI bots :) Blocks over 400+ AI bots!
After 10 years working late at night, my schedule has changed. I am now a “morning person”, starting my day at 6am or earlier.
Newsletter
Get news, updates, deals & tips via email.
Email kept private. Easy unsubscribe anytime.