Fall Sale! Code FALL2024 takes 25% 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 = Web Developer. Security Specialist. WordPress Buff.
Banhammer: Protect your WordPress site against threats.
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 »
USP Pro: Unlimited front-end forms for user-submitted posts and more.
Thoughts
Went out walking today and soaked up some sunshine. It felt good.
I have an original box/packaging for 2010 iMac if anyone wants it free let me know.
Always ask AI to cite its sources.
All free plugins updated and ready for WP 6.6 dropping next week. Pro plugin updates in the works also complete :)
99% of video thumbnail/previews are pure cringe. Goofy faces = Clickbait.
RIP ICQ
Crazy that we’re almost halfway thru 2024.
Newsletter
Get news, updates, deals & tips via email.
Email kept private. Easy unsubscribe anytime.