From 7d358a67af172c6526a4e53f4200068d543da8a6 Mon Sep 17 00:00:00 2001 From: Christopher Willis-Ford <7019101+cwillisf@users.noreply.github.com> Date: Tue, 6 Jun 2023 14:31:14 -0700 Subject: [PATCH] build: enable GTM environments feature - Document all GA/GTM-related variables in `template-config.js` - Add `gtm_env_auth` variable (from `GTM_ENV_AUTH` environment variable) to enable alternative GTM environments This will let us test new GTM configurations in staging without sending the data to our production data stream. --- src/template-config.js | 19 ++++++++++++++++++- src/template.ejs | 7 ++++--- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/src/template-config.js b/src/template-config.js index 13cf2ed0e..c74763530 100644 --- a/src/template-config.js +++ b/src/template-config.js @@ -28,6 +28,23 @@ module.exports = { og_image_height: 860, // Analytics & Monitoring + // ---------------------- + + // GA4 Measurement ID + // Looks like 'G-XXXXXXXX' + ga4_id: process.env.GA4_ID || '', + + // Universal Analytics Property ID + // Looks like 'UA-99999999-9' ga_tracker: process.env.GA_TRACKER || '', - gtm_id: process.env.GTM_ID || '' + + // Google Tag Manager ID + // Looks like 'GTM-XXXXXXX' + gtm_id: process.env.GTM_ID || '', + + // Google Tag Manager env & auth info for alterative GTM environments + // Looks like '>m_auth=0123456789abcdefghijklm>m_preview=env-00>m_cookies_win=x' + // Taken from the middle of: GTM -> Admin -> Environments -> (environment) -> Get Snippet + // Blank for production + gtm_env_auth: process.env.GTM_ENV_AUTH || '' }; diff --git a/src/template.ejs b/src/template.ejs index cfafbc05f..f2302c91f 100644 --- a/src/template.ejs +++ b/src/template.ejs @@ -8,8 +8,9 @@ + 'https://www.googletagmanager.com/gtm.js?id='+i+dl+'<%- htmlWebpackPlugin.options.gtm_env_auth %>'; + f.parentNode.insertBefore(j,f);})(window,document,'script','dataLayer','<%- htmlWebpackPlugin.options.gtm_id %>'); + <% } %> @@ -67,7 +68,7 @@
<% if (htmlWebpackPlugin.options.gtm_id) { %> - + <% } %>