Spring Sale! Save 30% on all books w/ code: PLANET24
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 = Designer. Developer. Producer. Writer. Editor. Etc.
BBQ Pro: The fastest firewall to protect your WordPress.
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 »
Banhammer: Protect your WordPress site against threats.
Thoughts
I live right next door to the absolute loudest car in town. And the owner loves to drive it.
8G Firewall now out of beta testing, ready for use on production sites.
It's all about that ad revenue baby.
Note to self: encrypting 500 GB of data on my iMac takes around 8 hours.
Getting back into things after a bit of a break. Currently 7° F outside. Chillz.
2024 is going to make 2020 look like a vacation. Prepare accordingly.
First snow of the year :)
Newsletter
Get news, updates, deals & tips via email.
Email kept private. Easy unsubscribe anytime.