Skip to content

Commit

Permalink
Use GA4 init code
Browse files Browse the repository at this point in the history
- runs the new GA4 init code, which starts the analytics code only after cookie consent
- note that this will not run anywhere but integration because the code it refers to is only included on integration
- remove test that checked for the existing of the Google Tag Manager component, as we're not using it anymore
  • Loading branch information
andysellick committed Sep 9, 2022
1 parent adcc437 commit 1c5f5c9
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 39 deletions.
12 changes: 12 additions & 0 deletions app/assets/javascripts/analytics.js.erb
Original file line number Diff line number Diff line change
Expand Up @@ -144,3 +144,15 @@ window.GOVUK.analyticsVars.linkedDomains = linkedDomains
if (typeof window.GOVUK.analyticsInit !== 'undefined') {
window.GOVUK.analyticsInit()
}

<% if ENV["GOOGLE_TAG_MANAGER_ID"] %>
if (typeof window.GOVUK.analyticsGA4.init !== 'undefined') {
window.GOVUK.analyticsGA4 = window.GOVUK.analyticsGA4 || {}
window.GOVUK.analyticsGA4.vars = window.GOVUK.analyticsGA4.vars || {}
window.GOVUK.analyticsGA4.vars.id = '<%= ENV["GOOGLE_TAG_MANAGER_ID"] %>'
window.GOVUK.analyticsGA4.vars.auth = '<%= ENV["GOOGLE_TAG_MANAGER_AUTH"] %>'
window.GOVUK.analyticsGA4.vars.preview = '<%= ENV["GOOGLE_TAG_MANAGER_PREVIEW"] %>'

window.GOVUK.analyticsGA4.init()
}
<% end %>
10 changes: 0 additions & 10 deletions app/views/root/_error_page.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,6 @@
global_bar = render "components/global_bar"
%>

<% content_for :head do %>
<% 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 %>
<% end %>

<%= render "govuk_publishing_components/components/layout_for_public", {
emergency_banner: emergency_banner,
full_width: false,
Expand Down
10 changes: 0 additions & 10 deletions app/views/root/_gem_base.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,6 @@
global_bar << global_banner if global_banner
%>

<% content_for :head do %>
<% 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 %>
<% end %>

<%= render "govuk_publishing_components/components/layout_for_public", {
account_nav_location: account_nav_location,
draft_watermark: draft_environment,
Expand Down
19 changes: 0 additions & 19 deletions test/integration/google_tag_manager_component_test.rb

This file was deleted.

0 comments on commit 1c5f5c9

Please sign in to comment.