Ruhi Pedhamkar
Ruhi Pedhamkar

Reputation: 61

In google tag manager, how can we use staging and live environment to send data to different Google Analytics accounts

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

Answers (2)

BigMugOfCoffee
BigMugOfCoffee

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. Here's an example.

Upvotes: 1

Bronwyn V
Bronwyn V

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.

  1. In the Custom Environments listing, find the entry for the environment you would like to install.
  2. Click the Actions menu for that entry.
  3. Select Get Snippet.
  4. Copy the resulting code snippet and install it so that it will appear in the code of the target environment.
  5. 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.

  1. Click Publish in the upper right corner of Tag Manager.
  2. Choose a selection from the Environment menu for where you want to publish your changes.
  3. 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

  1. Turn "on" the builtin variable for Environment Name.
  2. Create a Lookup Table variable, name it along the lines of Lookup - GA Tracking IDs.
  3. For Input Variable, use {{Environment Name}}.
  4. For Input value, enter the Environment Name, for Output value, enter the GA Tracking ID for the site that has the relevant Environment's container snippet installed.
  5. Set the Default Value to the GA Tracking ID for the Property for the live website.
  6. Plug {{Lookup - GA Tracking IDs}} variable into Tracking ID option of the GA Settings Variable.
    enter image description here

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.

  1. Ensure the inbuilt variable for Page Hostname is turned "on" (it should be by default).
  2. Create a Lookup Table variable, name it along the lines of Lookup - GA Tracking IDs.
  3. For Input Variable, use {{Page Hostname}}.
  4. In the first table row, for Input enter the hostname for your staging site eg stagingsite.com, and for Output, enter the staging site's GA Tracking ID.
  5. Check the option Set Default Value and enter the GA tracking ID for your live site.
  6. Plug {{Lookup - GA Tracking IDs}} variable into Tracking ID option of the GA Settings Variable. enter image description here

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. enter image description here

Upvotes: 7

Related Questions