From 41080fe5b2aac51212cf794c83038efcfe9f52eb Mon Sep 17 00:00:00 2001 From: Rebecca Pearce <17481621+beccapearce@users.noreply.github.com> Date: Mon, 6 Nov 2023 17:18:55 +0000 Subject: [PATCH] Move google tag manager snippet In order to be consistent with the other publishing apps we have moved the google tage snippet into a partial. This matches the way this was done in all the other publishing apps owned by the publishing experience team. Google Tag Manager (GTM) can be included on all pages of the app by configuring the following environment variables: GOOGLE_TAG_MANAGER_ID GOOGLE_TAG_MANAGER_AUTH GOOGLE_TAG_MANAGER_PREVIEW All three variables are optional. If none are set, GTM will not be included on the page. If only GOOGLE_TAG_MANAGER_ID is set, the default environment of the GTM container will be used. If GOOGLE_TAG_MANAGER_AUTH and GOOGLE_TAG_MANAGER_PREVIEW are set, the specified GTM container environment will be used. This is used for managing the rollout of changes to integration so they can be tested before rolling out to production. --- app/views/layouts/_google_tag_manager.html.erb | 7 +++++++ app/views/layouts/application.html.erb | 8 +------- 2 files changed, 8 insertions(+), 7 deletions(-) create mode 100644 app/views/layouts/_google_tag_manager.html.erb diff --git a/app/views/layouts/_google_tag_manager.html.erb b/app/views/layouts/_google_tag_manager.html.erb new file mode 100644 index 0000000000..9f24e3abbd --- /dev/null +++ b/app/views/layouts/_google_tag_manager.html.erb @@ -0,0 +1,7 @@ +<% if ENV["GOOGLE_TAG_MANAGER_ID"] %> + <%= render "govuk_publishing_components/components/google_tag_manager_script", { + gtm_id: ENV["GOOGLE_TAG_MANAGER_ID"], + gtm_auth: ENV["GOOGLE_TAG_MANAGER_AUTH"], + gtm_preview: ENV["GOOGLE_TAG_MANAGER_PREVIEW"] + } %> +<% end %> diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 9c77c04d6e..f5970a7c18 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -13,13 +13,7 @@ dataLayer.push({ 'gtm.blacklist': ['html', 'customScripts', 'nonGoogleScripts', 'customPixels'] }); - <% if ENV["GOOGLE_TAG_MANAGER_ID"] %> - <%= render "govuk_publishing_components/components/google_tag_manager_script", { - gtm_id: ENV["GOOGLE_TAG_MANAGER_ID"], - gtm_auth: ENV["GOOGLE_TAG_MANAGER_AUTH"], - gtm_preview: ENV["GOOGLE_TAG_MANAGER_PREVIEW"] - } %> - <% end %> +<% render "layouts/google_tag_manager" %> <% end %>