Info
Content

Working with Matomo/Piwik

In order to work with Matomo or Piwik here is an example on how to change the code in order to prepare it for blocking.

Example original code:

<script type="text/javascript">
var _paq = _paq || [];
_paq.push(['trackPageView']);
_paq.push(['enableLinkTracking']);
(function() {
var u="//www.mywebsite.com/piwik/";
_paq.push(['setTrackerUrl', u+'piwik.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+'piwik.js'; s.parentNode.insertBefore(g,s);
})();
</script>

Example adjusted code:

<script type="text/plain" class="cmplazyload" data-cmp-vendor="s974">
var _paq = _paq || [];
_paq.push(['trackPageView']);
_paq.push(['enableLinkTracking']);
(function() {
var u="//www.mywebsite.com/piwik/";
_paq.push(['setTrackerUrl', u+'piwik.php']);
_paq.push(['setSiteId', '1']);
var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
g.type='text/javascript'; g.setAttribute('data-cmp-ab', '1'); g.async=true; g.defer=true; g.src=u+'piwik.js'; s.parentNode.insertBefore(g,s);
})();
</script>

Matomo tracking

Enable the Matomo API:

We will check if the user has given the consent, if user has given consent to process their data, we will call:

setConsentGiven

If not we will wait for the consent to be given.

requireCookieConsent

So no data will be processed. 

Piwik tracking

Enable Piwik tracking API here:

According to the consent given, if the consent is given then we will run:

deanonymizeUser
setUserIsAnonymous
Back to top