Tracking analytics in a world with adblockers
Knowledge is power they say, and knowing your visitors brings a lot of advantages and insights with it. But the world has changed significantly since Google entered the analytics market in 2005. Today the web users are slowly but surely installing ad-blockers on their browsers and speed is only going to increase. And along with ads, the analytics tracking also get blocked, especially from the well known providers that you’re most likely using. So if you want to keep the benefits in this changing environment, you need to adapt and go local.
The best possible option for this is to install analytics tracking software on the same server that hosts your site. Which, if you have your own website that you manage, is literally going to take less than 15 minutes, if you have decent internet.
The obvious choice is Piwik. It’s a powerful alternative to the venerable Google Analytics and it’s also free and open source. So While you can just use it as a drop-in replacement of your current big name analytics suite, there are some tweks that will allow you to track users even with ad-blockers.
- Start by uploading the contents of the downloaded zip to a folder with name not containing any references to analytics, tracking, monitoring or Piwik itself. Most ad-blockers will catch such sub-folders or sub-domains by default and you would’ve just wasted your time. The name could even be random string of characters, although this can be suspicious for users or inconvenient for you, so use backend/ for instance. Open this new sub-folder/domain and you will see the installation wizard.
- Click next to confirm that your hosting is decent and Piwik don’t have any issues. Continue.
- If your hosting allow for unlimited MySQL DBs, great! Create a new one for Piwik and enter the details. If you’re limited and you used them all, you can reuse an existing one and let the table prefix do its thing. It’s just not very practical from administrative point of view. Click Next again.
- Once the DB structure is created, you will be asked to create the super user account. I hope I don’t have to convince you to use non-obvious name and strong, unique password for this step. Bonus point if you let your Password manager create it.
- The next step is where you enter the website you want to track analytics for. Enter it. Obvious, I know.
- The last step is where the main change will happen. You are given a tracking code, that can be pasted on the site header, inserted in any of the official plugins or, as we plan to do, updated to something more useful. So copy the code and change it like this:
var _paq = _paq || ;
var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script');
Basically – remove the comment, change the domain by adding
js/, update both instances of
u+'piwik.php'to be just
uand you’re done!
What this change does is to trick the ad-blocker into thinking it is just a regular folder with a regular php file in it, instead of the easily blockable piwik.js. What happens in reality, is that the same JS file is executed that returns the valuable user details to your server.
This of course is something that if you’re big enough can easily be caught and blocked, but for small to medium websites it will be great workaround as long as you choose proper folder name. Once you confirm that everything is working, you can check the documentation for fine tuning the analytics to your needs and your local laws.
Which reminds me – please honor the browsers “Do Not Track” header by setting up the appropriate setting in the tracking script, like the one shown above.