The process of deploying GA4 to various environments: development, test and live.
Environment - is a set of necessary elements of technical / software infrastructure, which is the basis for the operation of a given website/application. Google Tag Manager environments are simply multiple versions of the same container. When we have a website with a different version for development, testing, production and QA, instead of creating separate GTM containers for each version, we can set up separate environments in the same container that will work independently in each version.
Types of environments in GTM.
There are two types of environments in GTM. Custom environments and default environments. Default environments are pre-built, and custom environments are created by the user.
Implementing different environments
- To start working with environments, go to the administrator tab. Then select environments under the container.
GTM offers two built-in environments by default, Live and Latest. The live environment is already running on your production site, so you don't need to create one. - To create an environment for your test or QA site, click the NEW button in the environment area and enter a suitable name and easy-to-understand description for your environment so other team members can easily find it. Tick enable debug mode to be able to display preview mode for testing.
- To add a code snippet to your test site, click the actions drop-down menu and click Get Code Snippet.
Note that this code snippet is different from the container snippet added on all pages. Place the environment code snippets in a similar way that you added the container codes. The first snippet should be right after the opening head tag and the second just after the opening body tag.
Combining Google Analytics with GTM environments
We currently have several Google Tag Manager environments. In general, a standard website can have three different environments:
- Developer
- Testing
- Live
So here we have different versions for testing and related tasks. It is strongly recommended to create another property in Google Analytics and test your site before going live so that live stats and testing don't mix.
Create apropriate variables in GTM.
If you don't have the Environment Name built-in environment variable enabled, enable it.
Then create variables for each GA4 property in GTM:
- Create a user-define variables
- create a new user-defined constant variable (value - enter GA tracking ID) and save,
- copy this variable and save other property IDs. - Create lookup table variable:
- create a new user-defined variable,
- select variable type as lookup table,
- select input variable as environment name,
- click the Add New Row button,
- add analysis property variables as shown in the image below,
- make sure the names of the inputs on the left are similar to the names of the created environments. - In most cases, creating such a table is sufficient and the environments work fine. However, sometimes it is not. When the above solution doesn't work, you should look for other inputs eg. Page HostName and then in the left column of the table insert the address of the given environment.
Modify Google Analytics 4 tags.
Now the last step is to modify the existing Configuration Tag you created. Open the analytic tag and replace the Tracking ID with the lookup table variable you created earlier.
This will allow data to flow from each environment to the appropriate analytics service.
Share preview mode
To share any environment in preview mode, click the actions and select the share link to get a preview mode link. This link will allow anyone to view the environment in preview mode.
Anna Bacciarelli
During twelve years of professional work, I have gained experience in various positions in many fields. The variety of classes and professional experience taught me openness, independence, creativity, a positive approach to people and teamwork.Currently, I would like to focus on a new, extremely interesting path that is IT, and more specifically internet analytics. From the beginning of 2022, I have been gaining experience using the following tools: Google Analytics, Google Tag Manager and Google Data Studio.
If you enjoyed the article please share it:
The article "How to Configure User ID in Google Analytics 4" by Julius Fedorovicius, published on Analytics Mania, provides a comprehensive guide on implementing User ID tracking in Google Analytics 4 (GA4). This feature enables businesses to monitor user interactions across multiple devices and sessions, offering a unified view of user behavior.
Susan, an e-commerce entrepreneur, runs a thriving online store selling home decor. One day, her purchase funnel started showing a steep drop-off at the payment page. Unfortunately, Susan was unaware of this issue until weeks later, after losing significant revenue and customer trust. Why? She didn't have custom GA4 alerts set up to monitor her website metrics in real-time.
Some time ago I listened to a podcast from the Technical Marketing Handbook series from Simo Ahava, whose guest was Adam Halbardier from the Google Tag Manager product team. During the conversation, the topic of transparency of data handled by the Server-Side container appeared.
If you plan email marketing campaigns you are interested in the same as with other campaigns, to measure their impact on your business. When you are starting with this topic it is good to know that without additional effort you will not be able to access this impact. You will see no results because Google Analytics will treat traffic from the email campaigns as direct traffic (when users are using your own app) or as referrals (when users are using web email clients).