How do I track my staging/dev/production websites automatically using the same Tag Manager container?
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:
-
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)
-
Create a “Lookup Table” as explained in Manage Variables in Matomo Tag Manager (see the section Advanced Variable Settings Default Value Lookup Table), 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
-
Change the Site ID configured in your “Matomo Configuration” variable to the new Lookup Table variable that was just created, for example
{{SiteID}}
-
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 likecontainer_eKkj8u2C_staging_13f53cfa9b905e5dc5654e48.js
(This is generated automatically when selecting the environment you wish to use)
- For example the “Live” tag manager code will be something like
-
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.