Update: there is a dedicated article on helpcenter describing how to make Piwik PRO work with Matomo.
Piwik PRO is compatible with Matomo on the tracking code level to make it easy to switch between those two solutions. However, this also means that both tracker libraries use the same command queue to push analytics events. Because of that, it’s not possible to run both Matomo and Piwik PRO on one site without some additional configuration.
How to add Piwik PRO tracking to a site with Matomo code installed?
This guide assumes that Piwik PRO Consent manager is used and anonymous tracking is enabled.
- Go to Tag Manager module
- Deactivate the default Piwik PRO tag
- Add a new Custom code (async) tag
- Use the following tag code:
<script type="text/javascript">
var _ppas = _ppas || [];
(function () {
var trackAnonymously = {{ Piwik PRO Anonymization }}('analytics');
if (trackAnonymously) {
_ppas.push(['setUserIsAnonymous', 1]);
_ppas.push(['setVisitorCookieTimeout', 1800]);
}
}());
_ppas.push(['enableLinkTracking']);
_ppas.push(['setDomains', ['youdomainname.com/']]);
_ppas.push(['enableHeartBeatTimer']);
_ppas.push(['trackPageView']);
_ppas.push(['enableJSErrorTracking']);
(function(p,i,w,ik) {
var g=ik.createElement('script'),s=ik.getElementsByTagName('script')[0];
_ppas.push(['setTrackerUrl', p]);
_ppas.push(['setSiteId', w]);
g.type='text/javascript';g.async=true;g.defer=true;g.src=i;s.parentNode.insertBefore(g,s);
})('//youraccountname.piwik.pro/ppms.php','//youraccountname.piwik.pro/ppas.js','yoursite ID',document)
</script>
Here you have to replace the following things according to your setup:
-
youdomainname.com/
to your own domain name -
youraccountname.piwik.pro
to your Piwik PRO account name -
yoursite ID
to your Piwik PRO site ID (you can find it in Administration → Sites & apps → your website (below the name).
- Set consent type “does not require consent” (this scenario assumes that anonymous tracking is in use)
- Select existing “All page views” trigger
- Save the tag
- Add an additional Custom code (async) tag with the following tag code:
<script type="text/javascript">
var _ppas = window._ppas || [];
(function () {
var consents = {{ Consents }};
var consentType = 'analytics';
_ppas.push(['setVisitorCookieTimeout', 33955200]);
if (typeof consents !== 'undefined' &&
consents.hasOwnProperty('current_state') &&
consents.current_state.hasOwnProperty(consentType) &&
consents.current_state[consentType] === 1 &&
consents.hasOwnProperty('previous_state') &&
consents.previous_state.hasOwnProperty(consentType) &&
consents.previous_state[consentType] !== 1
) {
_ppas.push(['deanonymizeUser']);
}
}());
</script>
- Set tag’s consent type to
Analytics
(this tag will deanonymize user after the consent is given) - Set tag’s trigger to
All page views
- Save the tag
- Publish all tags
Important note: since there’s a non-default command queue in use (_ppas
instead of _paq
), all other tracker features have to be set up without using the predefined templates. All the snippet codes and docs can be found here. Just remember to change _paq
to _ppas
.