Skip to content

Commit

Permalink
Merge pull request #2868 from alphagov/ga4-consent
Browse files Browse the repository at this point in the history
Use GA4 init code
  • Loading branch information
andysellick authored Sep 13, 2022
2 parents b8fd1e3 + 1c5f5c9 commit 6311480
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 @@ -32,16 +32,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 6311480

Please sign in to comment.