How to set up dual tracking with Matomo and Piwik PRO
It is possible to track analytics data in both Matomo and Piwik PRO on the same website. This may be useful if you are migrating between platforms, comparing analytics data, or maintaining parallel analytics setups.
How dual tracking works
Matomo and Piwik PRO use the JavaScript _paq command queue. If both tracking scripts run on the same page without modification, conflicts can occur because the two trackers will try read and execute commands from the same queue. To prevent this, the Piwik PRO tracking code is modified so each platform processes its own tracking commands independently. The Matomo tracking code uses _paq, while Piwik PRO will use _ppas.
This guide explains two approaches for dual tracking and includes guidance on consent management:
- Add the Piwik PRO tracking code to Matomo Tag Manager (MTM).
- Modify and use both Matomo and Piwik PRO tracking codes.
Note that both platforms may still set similarly named first-party cookies, such as _pk_id and _pk_ses, because they share common origins in the same open-source analytics project. Even though the cookie names are similar, the trackers are configured separately and send data to different endpoints.
Before you start
- Make sure you have the following Piwik PRO values from Settings > Data collection:
- Tracking domain is used for
setTrackerUrl. - Static resources domain is used to load
ppas.js. - Site ID identifies the Piwik PRO site to send the data to.
- Tracking domain is used for
- Do not use the Piwik PRO Tag Manager container snippet inside Matomo Tag Manager. That snippet is designed to load the Piwik PRO tag manager container, not just the analytics tracker.
- Do not use Matomo’s
_paq.push(['addTracker', ...])for Piwik PRO. That method is for adding another Matomo tracker and does not work with the Piwik PRO tracker.
Option 1: Add the Piwik PRO tracking code to Matomo Tag Manager
You can use a Custom HTML tag in MTM to send tracking data to Piwik PRO alongside Matomo. This approach uses the Piwik PRO tracking code, not the Piwik PRO Tag Manager container code.
Create the Custom HTML tag
- Open your Matomo Tag Manager container and go to Tags.
- Click Create New Tag and select Custom HTML as the tag type.
-
Paste the following code into the tag and replace these values with the correct Piwik PRO references:
YOUR_TRACKING_DOMAINYOUR_STATIC_RESOURCES_DOMAINYOUR_PIWIK_PRO_SITE_ID
-
Add a Pageview trigger and save the new tag.
<script> var _ppas = window._ppas = window._ppas || []; _ppas.push(['setUserIsAnonymous', 1]); _ppas.push(['setTrackerUrl', 'https://YOUR_TRACKING_DOMAIN/ppms.php']); _ppas.push(['setSiteId', 'YOUR_PIWIK_PRO_SITE_ID']); _ppas.push(['trackPageView']); _ppas.push(['enableLinkTracking']); (function() { var d = document; var g = d.createElement('script'); var s = d.getElementsByTagName('script')[0]; g.async = true; g.defer = true; g.src = 'https://YOUR_STATIC_RESOURCES_DOMAIN/ppas.js'; s.parentNode.insertBefore(g, s); })(); </script> - Test the MTM container or configure custom events and goals.
Track custom events and goals
In many cases, you can configure goals directly in the Matomo or Piwik PRO interface. However, some interactions may need to be tracked manually, in which case, you can send events or goal conversions using the tracker queue. For example, to send a custom event to Piwik PRO from MTM.
- In Matomo Tag Manager, create a new Custom HTML tag and add the following code:
-
Assign an All Links Click trigger that fires only when the contact link is clicked. Define the trigger condition, for example,
Click Destination URLcontains/contact.html.
- Save the new tag and test the MTM container.
<script>
_paq.push(['trackEvent', 'Link', 'Click', 'Contact Form']);
</script>
For Piwik PRO JavaScript tracking methods, refer to the Piwik PRO developer documentation.
Test the Matomo Tag Manager setup
- In MTM, enable the Preview / Debug mode for your container.
- Open your website with the preview session active.
- Click the link or element that should trigger the event (for example, the contact page link).
- Confirm that the Custom HTML tag fires when the click occurs.
- You can also verify the request using your browser’s Developer Tools > Network tab.
- Filter for
ppmsor your Piwik PRO tracking domain. - Trigger the event again and confirm that a request is sent to the Piwik PRO tracking endpoint.
Option 2: Modify and use both Matomo and Piwik PRO tracking codes
If you are not using Matomo Tag Manager, you can implement dual tracking by adding both the Matomo and Piwik PRO tracking codes directly to your website. Each platform uses its own JavaScript tracking queue: _paq for Matomo and _ppas for the modified Piwik PRO.
Use the example code below and replace the custom values with your Matomo and Piwik PRO URLs and site ID.
<script>
var _paq = window._paq = window._paq || [];
_paq.push(['trackPageView']);
_paq.push(['enableLinkTracking']);
(function() {
var u = 'https://mysite.matomo.cloud/';
_paq.push(['setTrackerUrl', u + 'matomo.php']);
_paq.push(['setSiteId', '1']);
var d = document, g = d.createElement('script'), s = d.getElementsByTagName('script')[0];
g.async = true;
g.src = u + 'matomo.js';
s.parentNode.insertBefore(g, s);
})();
</script>
<script>
var _ppas = window._ppas = window._ppas || [];
_ppas.push(['setUserIsAnonymous', 1]);
_ppas.push(['setTrackerUrl', 'https://mysite.piwik.pro/ppms.php']);
_ppas.push(['setSiteId', 'xxxxx-xxxx-xxxx-xxxx-xxxxxxxxx']);
_ppas.push(['trackPageView']);
_ppas.push(['enableLinkTracking']);
(function() {
var d = document, g = d.createElement('script'), s = d.getElementsByTagName('script')[0];
g.async = true;
g.defer = true;
g.src = 'https://mysite.containers.piwik.pro/ppas.js';
s.parentNode.insertBefore(g, s);
})();
</script>
When a visitor loads the page, the Matomo tracker sends tracking data to the Matomo instance. Piwik PRO sends the same page view and link tracking data to your Piwik PRO instance. Both trackers operate independently and send requests to their respective endpoints.
Test the dual tracking setup
After implementing dual tracking, verify that both Matomo and Piwik PRO receive data correctly.
- Open your website and use the browser’s Developer Tools > Network.
- Reload the page. Confirm that requests are sent to both analytics endpoints:
matomo.php(Matomo)ppms.php(Piwik PRO)
- Check the analytics dashboards
- In Matomo, open Visitors > Real-Time report.
- In Piwik PRO, check the Real-time reports or Events section.
- In Matomo, open Visitors > Real-Time report.
- Trigger the custom event (for example, clicking the contact link).
- Confirm that the event appears in both platforms.
Implement consent management
Before enabling tracking, verify whether analytics tracking on your website requires user consent under applicable privacy regulations. If consent is required, integrate both Matomo and Piwik PRO with the consent manager platform (CMP) so that analytics tracking only occurs when statistics consent is granted. The exact implementation depends on the CMP used and your organisation’s privacy requirements.
To control when the Custom HTML tag for the Piwik PRO tracking code fires in Matomo Tag Manager, base the trigger on the consent state provided by your CMP. You can implement this by listening for a consent event pushed to the data layer.
The following example uses Cookiebot and a Custom Event trigger that fires only when the Cookiebot event cookie_consent_statistics is available in the dataLayer.
- Create a Custom Event trigger in Matomo Tag Manager that fires when
Event nameequalscookie_consent_statistics. - Assign this trigger to the Custom HTML tag containing the Piwik PRO tracking code. This ensures the tag fires only after statistics consent has been granted.
- After configuring the consent trigger, verify that tracking only occurs when statistics consent is granted.
Test consent behaviour
- Open your website and use the browser’s Developer Tools.
- In the CMP, decline statistics and check the Network tab to verify that no tracking requests are sent and no cookies are set.
- Accept statistics and confirm that the tracking requests appear and Matomo and Piwik PRO cookies are set.
- Use the MTM Preview / Debug mode to confirm the Piwik PRO tracking tag fires only when the required conditions are met.
- After granting consent, if requests appear in the Network tab and the data is visible in both analytics dashboards, the tracking setup is working correctly.
By configuring both trackers correctly and ensuring that consent conditions are respected, organisations can run both systems in parallel while maintaining a consistent tracking setup.