Only a couple weeks after starting this blog, I was surprised to discover that I am already getting a couple dozen visitors from Google per day. It's interesting to see what they were searching for, since it makes me feel like I have an audience, so I thought I'd display them in the sidebar over there. I did this with two pieces:
recent_google Blosxom
plugin (Perl, 1kb)
update_recent_google
script that keeps the plugin state up to date (3kb)
The Blosxom plugin is trivial and documents itself. It just provides a variable $recent_google::recent that gets expanded to either the contents of a state file (when doing dynamic rendering), or else an SSI command to do the same (when doing static rendering). This is a trick I have used on some other plugins, in order to let me render the whole blog statically to .shtml files, which can then use SSI to still pull in small dynamic pieces like the Now Playing box, or in this case, the recent Google searches.
Most of the work is done by the update_recent_google.pl script, which I run from cron once an hour. It reads the last 1000 lines of your Apache log file (to which you must have access), and creates a little bit of HTML that goes in the state file to be included in the blog page.
Nothing that simple could possibly be fun to hack of course, so I had to go one better and find an IP geolocation service that would make it possible to display where the visitor came from as well. There are several companies that sell this information, but usually for $300-400 for a year's subscription and unlimited usage, which is vastly overkill for my goofy 5 or 10 lookups a day. But fortunately, I found one place, Maxmind, that sells a "Web service" version that lets you do 50,000 lookups using a simple http interface for $20. Perfect for my goofy Google plugin. If you want your goofy Google plugin to do the same, you just need to get your own Maxmind license key and put it in the script where it says, "Put your license key here". Otherwise, it should be hardly any more difficult to hack out the Maxmind stuff and make the output look like whatever you want.
So, Google visitors, know that I have paid US $0.0004 to find out where you come from, just because I care about blogging the best blog experience for you that I can. The least you could do is click one of my Amazon links and buy something.
01 Dec 2005 13:19 PT - persistent link - trackback - 0 comments

4171622

