From 7bd5a70b37c43a77fddbbd453658a5941239d1d5 Mon Sep 17 00:00:00 2001 From: Rebecca Pearce <17481621+beccapearce@users.noreply.github.com> Date: Mon, 6 Nov 2023 17:07:48 +0000 Subject: [PATCH 1/2] Add Google Tag Manager snippet 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 | 9 +++++++++ app/views/layouts/application.html.erb | 3 +++ 2 files changed, 12 insertions(+) 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 00000000..367cad15 --- /dev/null +++ b/app/views/layouts/_google_tag_manager.html.erb @@ -0,0 +1,9 @@ +<% if ENV["GOOGLE_TAG_MANAGER_ID"] %> + <% content_for :head do %> + <%= 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 %> +<% end %> diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index e4f8699c..ba123ec5 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -4,6 +4,9 @@ <%= javascript_include_tag "application" %> <%= csrf_meta_tag %> <% end %> + +<% render "layouts/google_tag_manager" %> + <% content_for :page_title, " | GOV.UK Service Manual Publisher" %> <% content_for :app_title do %>GOV.UK Service Manual Publisher<% end %> From 39434f045e6d232b77ade46e9be93d61cb0584f6 Mon Sep 17 00:00:00 2001 From: Rebecca Pearce <17481621+beccapearce@users.noreply.github.com> Date: Tue, 7 Nov 2023 11:01:10 +0000 Subject: [PATCH 2/2] Add govuk publishing components as a dependency Govuk publishing components was previously installed on this app as a dependency of govspeak. However now we are using a publishing component snippet to add our google tag manager snippet so we should make it an explicit dependency of the app. --- Gemfile | 1 + Gemfile.lock | 1 + 2 files changed, 2 insertions(+) diff --git a/Gemfile b/Gemfile index ad407bf4..6b103610 100644 --- a/Gemfile +++ b/Gemfile @@ -11,6 +11,7 @@ gem "gds-sso" gem "govspeak" gem "govuk_admin_template" gem "govuk_app_config" +gem "govuk_publishing_components" gem "highline" gem "kaminari" gem "mail-notify" diff --git a/Gemfile.lock b/Gemfile.lock index 2aaa4d13..503ae644 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -703,6 +703,7 @@ DEPENDENCIES govspeak govuk_admin_template govuk_app_config + govuk_publishing_components govuk_schemas govuk_test highline