Save up to 25% on pro security plugins w/ our Security Bundle »
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.

Jeff Starr
About the Author
Jeff Starr = Designer. Developer. Producer. Writer. Editor. Etc.
SAC Pro: Unlimited chats.
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
Fall season almost here :)
My greatest skill on social media is the ability to simply ignore 98% and keep scrolling without interacting.
Enjoying this summer, getting some great positive energy. Refreshing and inspiring.
☀️ Pro plugin giveaway! Enter to win 1 of 4 lifetime licenses for our WordPress security plugins, including 10-site Security Bundle!
There is no end to what humans can achieve when they work together.
Excellent (and free) tool to test your site's SSL configuration.
Plugin updates! All of our free and pro plugins ready for WordPress 6.2.
Newsletter
Get news, updates, deals & tips via email.
Email kept private. Easy unsubscribe anytime.