Beantin webbkommunikation

Beantin Beta Blog

Experiments, investigations, and tests of web things
June 7, 2012

Piwik: Disable cookies in async tracking snippet

From version 1.8 of open source web analytics package Piwik it’s been possible to set Piwik not to create and use cookies for the tracking of visitors to your site. In addition to that, Piwik also honours the Do Not Track setting in your browser.

Once enabled, not only does Piwik stop creating and using cookies for visitor tracking, it also deletes the cookies that may already have been created.

The FAQ explains how to disable the setting of all cookies for a visitor. The example code it gives is for the standard version of the tracking snippet code. On the sites where I’ve implemented Piwik I’ve used the asynchronous version of the tracking code.

You need to add the disable cookies line immediately before the trackPageView line.


Here is a copy of the async tracking snippet with the disableCookies line added:

<!-- Piwik --> <script type="text/javascript"> var _paq = _paq || []; (function(){ var u=(("https:" == document.location.protocol) ? "https://{$PIWIK_URL}/" : "http://{$PIWIK_URL}/"); _paq.push(['setSiteId', {$IDSITE}]); _paq.push(['setTrackerUrl', u+'piwik.php']); _paq.push(['disableCookies']); _paq.push(['trackPageView']); _paq.push(['enableLinkTracking']); var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0]; g.type='text/javascript'; g.defer=true; g.async=true; g.src=u+'piwik.js'; s.parentNode.insertBefore(g,s); })(); </script> <!-- End Piwik Code -->

Remember to set or change $IDSITE and $PIWIK_URL to your site and piwik installation’s values.

Related Posts Plugin for WordPress, Blogger...


Filed under Configuration, Piwik.

Tags: , , ,

Theme Beantin created by James Royal-Lawson. Privacy Policy