Hi everyone,
We have one website with two environnements : prod and dev
We would like to use the same Tag Manager to not have to duplicate all configuration, but we don’t want to have statistics from dev and production on the same dashboard. How can we do ? Do we have to create a new website ? We don’t get it.
Thanks for your help
Did ever figure out a solution? We are facing the same issue
You could try Custom Dimension to check differences between prod and dev Tag Manager.
Hi @BenLaKnet, @marv, @Michele-ARTRA
I see 3 different solutions.
-
Add a custom visit dimension as BenLaKnet suggested to differentiate dev and prod. Then you can segment visits in the Matomo dashboard.
-
Create in the MTM container a 2nd configuration variable, containing the dev configuration (different site ID). But in this case you’ll have to duplicate prod tags into dev tags. Not really what you wanted…
-
If the only difference between dev and prod is the site ID you can also use this solution, a little bit more complex to create, but without difference between dev and prod:
- Create an
env
value in datalayer that has to be initialized before the _mtm bootstap script. This datalayer value must contain the environment value… - Create
matomoServerUrl
andmatomoSiteId
values in datalayer that will contain target matomo server and site ID. - Define the Matomo configuration variable thanks to datalayer:
- Matomo URL =
{{matomoServerUrl}}
- Matomo idSite =
{{matomoSiteId}}
- Matomo URL =
- Create a high priority html tag (first fired at page view trigger) with following content:
- Create an
<script>
(function () {
'use strict';
try {
// cf. https://github.com/matomo-org/tag-manager/issues/212
var env = window.MatomoTagManager.dataLayer.get('env'), srv, siteid;
if(typeof env === 'string' && env) {
switch (env.toLocaleLowerCase()) {
case 'production':
srv = 'production-matomo-server';
siteid = '1'; // Production site ID
break;
case 'staging':
srv = 'staging-matomo-server';
siteid = '1'; // Staging site ID
break;
default:
// By default, use of predefined values (test environment)
break;
}
if (srv && siteid) {
window.MatomoTagManager.dataLayer.push({
matomoServerUrl: 'https://' + srv + '/',
matomoSiteId: siteid});
}
}
}
catch (e) {
console.error('MTM container not found.');
}
})();
</script>