How do I send tracking requests to two or more Matomo servers?
It is possible to track the same website across multiple Matomo servers. This can be useful for organisations that maintain separate analytics environments, e.g., an agency and a client may each want their own analytics.
There are two ways to configure this setup:
- Send identical tracking data to multiple Matomo servers: Used when both environments need the same full dataset, such as page views, events, and Ecommerce interactions. It ensures both systems receive identical tracking data.
- Send different data to multiple Matomo server: For cases where you want to specify which tracking actions are sent to which Matomo server. For example, if an agency already has complete tracking in place, a partner can track additional events without affecting the agency’s reports.
Both approaches are supported by Matomo’s tracking code.
Send identical tracking data to multiple Matomo servers
Sending tracking requests to multiple Matomo servers is easily done using the Matomo JavaScript tracker.
The standard Matomo JavaScript tracking code contains the following lines for tracking to a single Matomo server:
_paq.push(['setTrackerUrl', u+'matomo.php']);
_paq.push(['setSiteId', YOUR_SITE_ID_HERE]);
To add a second tracking URL to Matomo, we can add the following code below it:
var secondaryTracker = 'https://matomo.example.com/matomo.php';
var secondaryWebsiteId = YOUR_SITE_ID_HERE;
// Also send all of the tracking data to the new Matomo server
_paq.push(['addTracker', secondaryTracker, secondaryWebsiteId]);
It is not necessary to have the same Site ID in both the Matomo servers. Each tracker can have a unique Site ID for the website you are tracking.
Adding additional Matomo servers can likewise be added with the following:
var tertiaryTracker = 'https://matomo2.example.com/matomo.php';
var tertiaryWebsiteId = YOUR_SITE_ID_HERE;
_paq.push(['addTracker', tertiaryTracker, tertiaryWebsiteId]);
There is no limit to the number of trackers you can add via this method to send tracking requests to multiple Matomo servers.
Send different data to multiple Matomo servers
If you want to be more specific about the data being sent to each Matomo server, use this approach to send different data to different Matomo servers. For example, a partner only wants to track custom events but the main Matomo setup at the agency already collects full tracking. Sending all events to both would complicate the primary dataset.
In the following example code, the standard Matomo tracking snippet is updated. Instead of calling setSiteId
and setTrackerUrl
inside _paq.push()
, it uses Matomo.addTracker()
after the script has loaded.
It is not necessary to have the same site ID in both Matomo servers. Each Matomo server has its own list of websites identified by a unique site ID.
var _paq = window._paq = window._paq || [];
(function() {
var u = "https://example.matomo.cloud/";
var d = document, g = d.createElement('script'), s = d.getElementsByTagName('script')[0];
g.async = true;
g.src = u + 'matomo.js';
g.onload = function() {
var trackerA = Matomo.addTracker("https://example.matomo.cloud/matomo.php", 9); // ID site 9
var trackerB = Matomo.addTracker("https://example.matomo.cloud/matomo.php", 10); // ID site 10
_paq.push(['trackPageView']); // sent to both trackers
trackerA.trackEvent('Category', 'Action', 'Label', 1); // sent only to site 9
trackerB.trackEvent('Category', 'Action', 'Label', 2); // sent only to site 10
};
s.parentNode.insertBefore(g, s);
})();
This approach gives you full control over the tracking data sent to each Matomo server.
- Read more about Multiple Matomo Trackers in the Developer Documentation.
- Discover how to further customise the different Matomo tracker instances.