Don't understand how to track different environment with the same tag manager

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.

  1. Add a custom visit dimension as BenLaKnet suggested to differentiate dev and prod. Then you can segment visits in the Matomo dashboard.

  2. 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… :thinking:

  3. 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 and matomoSiteId 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}}
    • Create a high priority html tag (first fired at page view trigger) with following content:
(function () {
'use strict';
try {
    // cf.
    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
            case 'staging':
                srv = 'staging-matomo-server';
                siteid = '1'; // Staging site ID
                // By default, use of predefined values (test environment)

        if (srv && siteid) {
                matomoServerUrl: 'https://' + srv + '/',
                matomoSiteId: siteid});
 catch (e) {
    console.error('MTM container not found.');