I don't run google analytics on my blog. I find the idea somewhat...narcissistic. However, I was interesting in finding out how many people were going to download The Little MongoDB Book. So, I wrote a simple service and put it up at load.io
There are a couple neat things about this. Looking at access logs, The Little MongoDB Book has been downloaded around 10 000 times in the last 24 hours. That's more than 3x what this is showing. What's up? First, a lot of people are linking directly to the PDF. If this was a webpage I could have hooked into an onload event and solved that problem. As is, I'm only tracking clicks on my specific links to the pdf.
The other interesting thing is that the tracking code uses a tracking image to cause a hit (the oldest trick in the tracking book). Images are downloaded asynchronously and when you start to navigate away from the page (say, when you are following an href), the browser cancels all incomplete asynchronous requests. You can see the source code for the script at http://js.load.io/js/0.1/hit.js. Its using a setTimeout to try to buy itself some time, but there's really no guarantees. So you'll lose some tracking this way. An alternative would be to send the link to load.io and redirect back to the resource - but that's pretty much a URL shortening service. If anyone has a better idea, i'd love to hear it.