By Richard Szibele
23 May, 2017
I've personally run into the issue of not being able to track users who have Adblock, uBlock or similar add-ons and I've come up with a solution that is guaranteed to work across them all.
This is only possible thanks to the fact that you can install and configure Piwik however you like because it is available under the GPLv3 license, unlike third party providers like Google Analytics or Yahoo Analytics (Flurry) which you have little to no control over.
Let us take a look at how we can use Piwik to track users with ad blockers and other privacy plugins.
Simply put, ad blockers have a blacklist which contain patterns for ad or tracking URLs which they match to and then remove from the page or even block the browser from sending a request to that URL.
For example, the Easy Privacy list – which ensures the users privacy in add-ons like Adblock or uBlock – contains the following patterns for Piwik:
/piwik-$domain=~github.com|~piwik.org /piwik.$script,domain=~piwik.org /piwik.php /piwik/*$domain=~github.com|~piwik.org /piwik1. /piwik2.js /piwik_ /piwikapi.js /piwikC_ /piwikTracker.
Basically, all we have to do is remove all links with Piwik in the tracking code and we've effectively bypassed any of these and also patterns from other privacy lists.
As we can see from the above code, the name Piwik is included in the tracking links. We will need to remove every occurrence of Piwik from those links or else they will get blocked. I run my Piwik instance on the subdomain piwik.szibele.com, so the first logical step is to set up another subdomain without Piwik in it. In my case I've set up a second subdomain p.szibele.com and only use that for tracking.
If you have Piwik set up in a subdirectory on your website, your best bet is to use mod_rewrite on Apache or rename the piwik subdirectory to /p/ or anything else unrelated to web analytics or Piwik.
So, lines 9 and 12 above become:
The tracking pixel code on line 15 becomes:
<noscript><p><img src="//p.Szibele.com/js/?idsite=1&rec=1" style="border:0;" alt="" /></p></noscript>
If the developers for the ad blockers and privacy add-ons do find another, more sophisticated approach to blocking, then I'll be sure to post a follow-up going the extra mile.← back