When you’re tracking multiple different environments, for example a Staging, Development or Production (Live) website, using the same Tag Manager Container can simplify your testing and container deployment strategy.

This FAQ assumes that you already have a Tag Manager container setup with a “Matomo Configuration” variable. If you don’t yet have a Tag Manager container setup, you can follow the steps in our Tag Manager User Guide

With Matomo Tag Manager, the Site ID that is used for the container to send tracking data to Matomo is determined by the “Matomo Analytics” variable.
The Site ID can be set automatically with an Advanced variable using a lookup table that can be used to set the Matomo Site ID based on the URL/Hostname of the website where the container is published. This can make deployments between Testing and Production environments easier.

To set this up with Matomo Tag Manager, you can follow these steps:

  1. Create each “Website” you wish to track as its own measurable in Matomo (For example a “Measurable/Website” for each Staging, Dev or Production site)

  2. Create a “Lookup Table” as explained in our Tag Manager User Guide setting each hostname/URL to the URL of your different environments. Be sure to set the value of each URL to the correct Site ID for each environment

  3. Change the Site ID configured in your “Matomo Configuration” variable to the new Lookup Table variable that was just created, for example {{SiteID}}

  4. Deploy the different “Environments” you wish to track to each applicable website. For example the “Staging” environment tracking code should be deployed to your “Staging” website and the “Dev” environment to your development website.

    • For example the “Live” tag manager code will be something like container_eKkj8u2C.js and the “Staging” tag manager code will be something like container_eKkj8u2C_staging_13f53cfa9b905e5dc5654e48.js
      (This is generated automatically when selecting the environment you wish to use)
  5. Deploy any changes you wish to test to the correct “Environment” that has been configured for that website environment

You can find out more about deploying changes to your Tag Manager container in this section of our Tag Manager User Guide.