Reputation: 61
I am trying to use GTM environment feature with lookup table and want to send data of individual environment to different Google analytics property. is this possible? Can we use a single GTM container with live and staging environment and send data to two different Google Analytics properties.
Upvotes: 5
Views: 3515
Reputation: 43
Not sure I'm fully understanding the question, but if it's "Can I use one GTM container to send data to 2 different GA properties," the answer is yes. You can install the GTM container in both environments, and then create separate constant
variables whose values are set to the different GA properties' tracking codes you want to send data to.
Then, in each tag's Google Analytics Settings Variable
field, you can click "override" and populate the Tracking ID
field with the correct GA property's tracking ID.
Upvotes: 1
Reputation: 774
If Using GTM Environments
Something to note from the GTM help docs:
An alternative way to use environments is to use an environment's preview function. Share the preview link for whatever version of the environment you'd like to preview. With this method, you don't have to install and deploy a special environment code snippet.
If the production environment is in relation to the live site and has the default GTM container code installed on it, it doesnt need to be specified within GTM.
Every container is set up with a "Live" environment by default, which always points to the container version that is currently published. You don't need to define the Live environment.
Other environments will each have their own specific container code, installed to the applicable environment eg the container code for the staging environment will be installed on the staging site website.
Install your container snippets. This process is similar to installing a standard Tag Manager container snippet, except that you have to do this on every server that has a corresponding environment defined in Tag Manager. This step may require assistance from a developer or systems administrator to complete.
- In the Custom Environments listing, find the entry for the environment you would like to install.
- Click the Actions menu for that entry.
- Select Get Snippet.
- Copy the resulting code snippet and install it so that it will appear in the code of the target environment.
- Save and publish the website's code changes.
When you have custom environments defined, the Publish dialog will add a menu so that you can define to which server the changes will be published.
- Click Publish in the upper right corner of Tag Manager.
- Choose a selection from the Environment menu for where you want to publish your changes.
- Click Publish.
More info on using Environments can be found in the GTM Help Center https://support.google.com/tagmanager/answer/6311518?hl=en
To send hits to different GA Properties based on Environment
Alternatively - To send hits to different GA Properties based on the Hostname
You can use a single GTM container and send data to two different GA Properties based on different Hostnames
eg livesite.com and stagingsite.com using a Lookup Table Variable.
For either of the above scenarios.. the Lookup Table Variable that you created, then gets plugged into the into Tracking ID option of the GA Settings Variable, which then gets added to your GA tags within GTM.
Upvotes: 7