Yes, you can use Piwik PRO and Matomo together, but you need to make some adjustments to track all the data correctly.
Piwik PRO and Matomo both use the _paq.push()
command to send data. This is because both tools come from the same open-source product. In Piwik PRO, we’re working on changing the _paq.push()
command to _ppas.push()
so that it doesn’t interfere with Matomo. But before we do that, you need to use a manual setup.
There are two ways to set it up: (1) use modified Piwik PRO tracking code and Matomo tracking code (2) use only Matomo tracking code but modify it.
Option #1: Use modified Piwik PRO tracking code and Matomo tracking code
Option #1 is good if you want a completely separate setup for Piwik PRO and Matomo. It requires a little more custom code, but it allows you to use all of our features, some of which Matomo doesn’t have. In this method, you keep the Matomo tracking code as it is and modify the Piwik PRO tracking code.
To modify the Piwik PRO tracking code, follow these steps:
- Log in to Piwik PRO.
- Go to Menu > Tag Manager.
- Navigate to Tags.
- Name the tag and select the following type: Custom code (async) (custom asynchronous tag).
- In Tag code, add this code.
<!-- Piwik PRO --> <script type="text/javascript"> var _ppas = _ppas || []; _ppas.push(['setUserIsAnonymous', 1]); _ppas.push(["trackPageView"]); _ppas.push(["enableLinkTracking"]); (function() { var u = "https://example.piwik.pro/"; _ppas.push(["setTrackerUrl", u + "ppms.php"]); _ppas.push(["setSiteId", "XXX-XXX-XXX-XXX-XXX"]); 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 + "ppas.js"; s.parentNode.insertBefore(g, s); })(); </script>
In this code, change the following elements:
- https://example.piwik.pro/: The address you use to log in to Piwik PRO.
- XXX-XXX-XXX-XXX-XXX: The ID of the site or app in Piwik PRO where you want to send data. (Where to find it?)
- In Advanced tag settings, choose Consent type: No consent is required.
- In Tag triggers, add the following trigger: All page views.
- Click Save.
- Go to Tags.
- Click Add a tag again. Now you need to add a tag responsible for deanonymizing the user who consents to data collection.
- Name the tag and select the following type: Custom code (async) (custom asynchronous tag).
- In Tag code, add this code:
<script> _ppas.push(['deanonymizeUser']); </script>
- In Advanced tag settings, choose Consent type: Analytics.
- In Tag triggers, add the following trigger: All page views.
- Click Save.
- Test your tag in debug mode.
- Deactivate the following tag: Piwik PRO (tracking code). This code is responsible for data collection, but you’ll use a modified version.
Note: If you get an error saying: “Matomo javascript tracker or Piwik PRO javascript tracker was already initiated on this page,” it’s very likely that you haven’t deactivated this tag and now you have two Piwik PRO scripts running.
- Click Publish.
How to use custom events and goals
The _paq.push()
command is also used in custom events and goals, so you’ll need to use the manual setup to set them up.
To add a custom event, follow these steps:
- Add this script as a custom code in Tag Manager. Don’t use the custom event tag.
<script> _ppas.push(["trackEvent", "category", "action"]); </script>
To add a goal, follow these steps:
- Add this script as a custom code in Tag Manager. Don’t use the goal conversion tag.
<script> _ppas.push(["trackGoal", goalID, conversionValue]); </script>
goalID (number | string , required)
The ID of the goal to be tracked. (To find a goal ID go to Menu > Analytics > Goals.)conversionValue (number, optional)
The value of the goal. It’s used to calculate the goal revenue.
Option #2: Use only Matomo tracking code but modify it
Option #2 is usually a good idea if you want to send data from Matomo to our product, for example if you are considering switching from Matomo and want to do some testing. This way, you essentially track the site with only one source (Matomo tracker) and can make comparisons between Matomo reports and ours. The downside of this method is that you can’t use all Piwik PRO features.
To modify the Matomo tracking code, follow these steps:
- Find the Matomo tracking code in your Matomo account. (Where to find it?)
Example:
<!-- Matomo --> <script type="text/javascript"> var _paq = window._paq = window._paq || []; _paq.push(['trackPageView']); _paq.push(['enableLinkTracking']); (function() { var u = "//{$MATOMO_URL}/"; _paq.push(['setTrackerUrl', u + 'matomo.php']); _paq.push(['setSiteId', { $IDSITE }]); var d = document, g = d.createElement('script'), s = d.getElementsByTagName('script')[0]; g.type = 'text/javascript'; g.async = true; g.src = u + 'matomo.js'; s.parentNode.insertBefore(g, s); })(); </script> <!-- End Matomo Code -->
- Add this piece of code to the Matomo tracking code right after
setSiteID
:_paq.push(['addTracker', dataCollectionURL, siteIDinPiwikPRO]);
In this code, change the following elements:
- dataCollectionURL: Your Piwik PRO account URL, followed by
ppms.php
. Example:https://example.piwik.pro/ppms.php
- siteIDinPiwikPRO: The ID of the site or app in Piwik PRO where you want to send data. (Where to find it?)
- dataCollectionURL: Your Piwik PRO account URL, followed by
- Done! Now all of your events sent to Matomo will also be sent to Piwik PRO. Data will appear in reports in about an hour. Data in the tracker debugger will appear instantly.
Note: For now, you can track a site with the Matomo tracking code and send it to Piwik PRO because we’re backwards compatible with Matomo. But as both products grow, there will be some differences and this method may no longer work.
Note: These methods are not yet compatible with our tracking libraries for React and Angular.