From cc03f68dd458a55b066a205fa438a9449f23079b Mon Sep 17 00:00:00 2001 From: Aga Dufrat Date: Thu, 11 Jul 2024 15:45:36 +0100 Subject: [PATCH] Don't use GTM from govuk_publishing_components until we can upgrade MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The GTA doesn’t work as expected for DGU. It appears that gtm_cookies_win=x allows GTM Preview to change the environment of a page, which means that they win over gtm_auth and gtm_preview parameters. The fix was added to govuk_publishing_components in v39.2.3: https://github.com/alphagov/govuk_publishing_components/pull/4097 However due to a number of issues with upgrading we are using 28.7.1 version. This replicates code from https://github.com/alphagov/govuk_publishing_components/blob/a9be4e9f18693e3a2a7dcf87b7b396fbb283d579/app/views/govuk_publishing_components/components/_google_tag_manager_script.html.erb --- Gemfile | 2 +- app/views/layouts/application.html.erb | 22 +++++++++++++++++----- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/Gemfile b/Gemfile index 965b55f1..db5e5504 100644 --- a/Gemfile +++ b/Gemfile @@ -11,7 +11,7 @@ gem "elasticsearch-rails", "~> 7.2.1" gem "faraday" gem "faraday_middleware" gem "govuk_elements_rails" -gem "govuk_publishing_components", "~> 28.7.1" +gem "govuk_publishing_components", "~> 28.7.1" # TODO: Revert https://github.com/alphagov/datagovuk_find/pull/1286 once 39.2.3+ gem "htmlentities" gem "jbuilder" gem "jquery-rails" diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 1efef26d..bccbddf8 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -5,12 +5,24 @@ <% 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"] - } %> + <% + gtm_auth = ENV["GOOGLE_TAG_MANAGER_AUTH"] + gtm_preview = ENV["GOOGLE_TAG_MANAGER_PREVIEW"] + + gtm_attributes = [] + gtm_attributes << "gtm_auth=" + gtm_auth if gtm_auth + gtm_attributes << "gtm_preview=#{gtm_preview}>m_cookies_win=x" if gtm_preview + gtm_attributes = gtm_attributes.join('&') + %> + <% end %> +