Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the proper way to setup Live environment on Google Tag Manager?

Using Google Tag Manager, I want to use the Environments feature. While the Environments setup is pretty straightforward, there is a special case regarding the Live environment setup. More specifically, documentation mentions:

Note: 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.

Now, in order to setup GTM in my website for Live, I have 2 possible snippets: the "default" snippet (Which can be obtained by Admin > Install Google Tag Manager in my container) and the "Live" snippet (which can be obtained via Admin > Environments > "Live" > (Actions) Get Snippet).

The problem here is that the first script does not seem to map properly to the Live environment, as using it in a Lookup Table, maps to the default value.

On the other hand, the second script seems to be working properly. My concern is that it uses 2 additional parameters (gtm_auth and gtm_preview), and I am not sure if they should be defined to Live environment. Additionally, several blogs suggest the use of the first script on the Live environment.

My question - and concern is, which of the 2 scripts is the optimal to use in order to setup Live Environment in GTM, in terms of proper installation, usage and security?

Please consider that suggesting the usage of different containers is not an option.

like image 405
Nick Louloudakis Avatar asked Nov 08 '22 00:11

Nick Louloudakis


1 Answers

What you're experiencing is the expected behavior. As per documentation the built-in Environment Variable is defined as follows:

Environment Name: Returns the user-provided name of the current environment, if the container request was made from an environment "Share Preview" link or from an environment snippet. For the built-in environments, it will return "Live", "Latest", or "Now Editing". In all other cases it returns an empty string.

In this case, when using the "Share Preview" or the snippet from Admin > Environments > "Live" > (Actions) Get Snippet will result in the variable to be populated.

When using the snippet from Admin > Install Google Tag Manager in my container, the variable will be empty since it isn't an environment snippet.

In terms of installation, I would suggest using the non-environment snippet version for live, as less information is shared publically (values from gtm_auth & env parameters)

like image 180
XTOTHEL Avatar answered Nov 15 '22 12:11

XTOTHEL