Analytics and page tagging are part of a broader technology context within the enterprise and should be managed with the same attention as other deployments. Here at E-Nor, we encourage our clients to consider the bigger picture and guide them to mature in their analytics implementation, integration, and reporting processes. Part of that maturity is careful management of Google Analytics and Google Tag Manager in development and live production environments.
When first including Google Analytics tags (and Custom HTML tags that support GA, such as for data layer population) in Google Tag Manager, you probably don’t want to start off in your live environment. Like any other code change, you risk errors in your Google Analytics tag configuration and the resulting report data and even the off-chance that a Custom HTML tag breaks your site and causes you to lose sales.
Before we continue the discussion, let’s consider two fundamental points:
You can use a single GTM container or separate GTM containers in your development and production environments. While either approach is workable, my esteemed colleagues in the E‑Nor tech team would advise you to use a single container across both environments for easier management.
You can use a single GA property or separate GA properties for your development and production environments. We detail both of these options below.
For this scenario, there are three main steps:
If you’re using the same Google Analytics property ID in your development and production environments, your should create separate views and apply hostname filters such as shown below.
Enable the built-in Page Hostname variable to make it available in tags and triggers.
Instead of applying the generic All Pages trigger to your GA tags during testing, you can apply a trigger as below that will fire only when the hostname indicates that the page is loading from the development server.
As a related note, it’s considered best-practice to store your GA property ID as a Constant variable in GTM as shown below so you can reuse the same property ID in various tags (pageview, event, social, and Ecommerce) without hard-pasting each time.
Constant variable in GTM for the GA property ID.
We can reuse the GA Property ID variable in all of our Google Analytics tags.
In this scenario, you’re recording activity from your development and production environments into separate Google Analytics properties. Since we’re using the same GTM container, our task is to direct to the right GA property based on hostname.
When first testing GA tags in this case, perform the same initial steps as above: apply a trigger that fires the tag only in your development environment. You can also use the Constant variable for your development GA property ID, also as shown above.
Once you have verified that the new tags have not interfered with any functionality on your development pages and are sending data to Google Analytics correctly, you have two basic options to move the tags to production and to begin capturing the data in the production GA property:
One of Google Tag Manager’s many strengths is its ability take an input an process it into a different output. The Lookup Table variable exemplifies this functionality: we’ll provide a dynamic input – in this case, the development or production hostname – and output the dev or live GA property ID into our GA tags as shown below.
This Lookup Table takes the hostname as an input and outputs the dev or live GA property ID accordingly.
Finally, create a Google Analytics pageview tag that uses the lookup table variable for the Property ID setting.
This GA Event tag uses the Lookup Table to dynamically insert GA property ID.
That’s it – you now have a single GA pageview tag that will dynamically switch between your development and production Google Analytics properties according to the hostname on which the tag fires. Any tag configurations (such as custom dimensions, content groupings, or event values) will apply to both Google Analytics properties from a single tag.
As demonstrated above, GTM’s flexibility and dynamism can help you manage your GA tag deployments in testing and live environments. Whether you’re using a single or separate Google Analytics properties, Google Tag Manager enables the process control that you need.
As consumers become increasingly digitally savvy, and more and more brand touchpoints take place online,…
Marketers are on a constant journey to optimize the efficiency of paid search advertising. In…
Unassigned traffic in Google Analytics 4 (GA4) can be frustrating for data analysts to deal…
This website uses cookies.