Back in May, I started using Google Analytics again after a two-year hiatus. When I removed the GA code from the site in 2013, I said that while I was OK with a lot of Google’s tracking, it was presumptuous of me to assume that you were OK with it. I changed my mind partly because it didn’t seem as though more than a handful of people really cared about being tracked by Google Analytics (and those who did knew what steps to take to avoid it) but mostly because I thought I’d need the data from it if I were going to sell sponsorships. In other words, selfish reasons.

It still bothered me, though.1 So I went about looking for a replacement that wouldn’t send my readers’ info off to some third-party site. I tried using AWStats, but couldn’t get it configured to my liking because of permissions problems with the log files. More important (because I’m sure there’s a solution to the permissions problem if I just dig deeper), I often get hit by bots that generate thousands of hits that parse as page views. That makes my stats look great, but it isn’t accurate or honest.2

I found Piwik, which looked like a decent locally hosted alternative to Google Analytics, so I installed it and have been running it along with GA for the past few weeks.

For the first couple of days, the results were dismal. Piwik values for visits and page views were consistently just a small fraction of what GA reported. I have no idea which result is more correct, but I know that GA’s figures are accepted, so a utility that doesn’t come close is of no value.

But before abandoning Piwik, I decided to change how I used it. The Piwik docs say to insert its JavaScript code near the bottom of your pages—just above the </body>tag., and that’s what I had done. But the Google Analytics code was inserted in the <head> section. What would happen if I put the Piwik code there?

The results were much closer. With the Piwik code just below the Google Analytics code, its counts for visits and page views are comparable to GA’s. Piwik’s figures are still lower, but by only 15–20%. This seems acceptably close to me.

I’m going to keep running both analytics tools for a while to see if these early results stand up over time, but I’m encouraged so far. And this may turn out to be more than just a conscience assuager. If Safari’s new content blocking leads to extensions that prevent Google Analytics from working—and those extensions become popular—self-hosted tools like Piwik may become the only game in town.

1. I can block the bots, but it’s an exhausting game of whack-a-mole that I just don’t feel like playing. Since moving to a static site from WordPress, the bots have had no noticeable effect on the site’s performance, so I don’t stress about them. ↩︎