Use Piwik for more Reliable Visitor Statistics (avoid referral spam and ad blockers)

· 370 words · 2 minute read

Online marketers rely on statistics about their visitors to constantly adapt offers and learn about traffic sources. Google Analytics is the current tool of choice for most of them. Unfortunately GA is suffering from two major issues that won’t go away any time soon

:

  1. Ad Blockers: A rising number of users blocks ads with these browser plugins. All of them will prevent GA from loading. On tech-heavy sites this will lose you around 1/3 of visitors. Even iOS supports Ad Blockers. Google Analytics blocked by Ad Blocker.  

    • Referral Spam: Due to the client-side nature of Java Script and thus Google Analytics, it’s easy to fake website visits and just poison your statistics with any data. Spammers know that webmasters are interested in sites referring to them. So they place spam links to lure them to e-commerce or malware sites.
### Solution

Piwik allows you to self-host a statistics system very similar to GA with most of the features and none of the issues described above. By default Ad Blockers will block piwik as well, but since it's under your control, you can simply redirect your endpoints. For Nginx these lines are enough:

<pre class="lang:apache decode:true "># Avoid AdBlockers

rewrite ^/pk.php /piwik.php; rewrite ^/pk.js /piwik.js;

Then your tracking code should point to the new endpoints:

<pre class="lang:js decode:true ">&lt;!-- Piwik --&gt;

<script type=“text/javascript”> var _paq = _paq || []; _paq.push([‘trackPageView’]); _paq.push([‘enableLinkTracking’]); (function() { var u="//MYHOST.COM/"; _paq.push([‘setTrackerUrl’, u+‘pk.php’]); _paq.push([‘setSiteId’, 1]); var d=document, g=d.createElement(‘script’), s=d.getElementsByTagName(‘script’)[0]; g.type=‘text/javascript’; g.async=true; g.defer=true; g.src=u+‘pk.js’; s.parentNode.insertBefore(g,s); })(); </script> <noscript><p><img src="//MYHOST.COM/pk.php?idsite=1" style=“border:0;” alt="" /></p></noscript> <!– End Piwik Code –>

When visiting this site with an Ad Blocker, you should still see your stats coming in.

As an added benefit there are no cookies involved. So you don't need one of these annoying notices.

### Ethics

Is it ethical to track people who are using Ad Blockers? Most users use these plugins to avoid downloading ads and thus get a faster browsing experience. Their next-highest concern is probably being tracked across all sites to serve them personalized ads. The data your one site is gathering won't be correlated with their Facebook and Google profile. So I'd say it's OK to use this technique. The same data can be obtained from web logs.