Skip to content

Commit

Permalink
Add GA4 analytics
Browse files Browse the repository at this point in the history
Use the `load-analytics' script of govuk_publishing_components to add
GA4 analytics to collections-publisher. Includes extra configuration to
set the correct domains for GA4 to initialise and code to automatically
accept all cookies to make tracking work.
  • Loading branch information
patrickpatrickpatrick committed Mar 13, 2024
1 parent ceaa582 commit 550cb77
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 0 deletions.
1 change: 1 addition & 0 deletions app/assets/config/manifest.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//= link_tree ../images
//= link application.css
//= link application.js
//= link domain-config.js
3 changes: 3 additions & 0 deletions app/assets/javascripts/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,6 @@
//= require @webcomponents/custom-elements/custom-elements.min.js

//= require components/markdown-editor.js

window.GOVUK.approveAllCookieTypes()
window.GOVUK.cookie('cookies_preferences_set', 'true', { days: 365 })
41 changes: 41 additions & 0 deletions app/assets/javascripts/domain-config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
window.GOVUK = window.GOVUK || {}
window.GOVUK.vars = window.GOVUK.vars || {}
window.GOVUK.vars.extraDomains = [
{
name: 'production',
domains: [
'collections-publisher.publishing.service.gov.uk'
],
initialiseGA4: true,
id: 'GTM-MG7HG5W',
gaProperty: 'UA-26179049-1',
gaPropertyCrossDomain: 'UA-145652997-1',
consentApiUrl: 'production'
},
{
name: 'staging',
domains: [
'collections-publisher.staging.publishing.service.gov.uk'
],
initialiseGA4: true,
id: 'GTM-MG7HG5W',
auth: 'oJWs562CxSIjZKn_GlB5Bw',
preview: 'env-5',
gaProperty: 'UA-26179049-20',
gaPropertyCrossDomain: 'UA-145652997-1',
consentApiUrl: 'staging'
},
{
name: 'integration',
domains: [
'collections-publisher.integration.publishing.service.gov.uk'
],
initialiseGA4: true,
id: 'GTM-MG7HG5W',
auth: 'C7iYdcsOlYgGmiUJjZKrHQ',
preview: 'env-4',
gaProperty: 'UA-26179049-22',
gaPropertyCrossDomain: 'UA-145652997-1',
consentApiUrl: 'staging'
}
]
7 changes: 7 additions & 0 deletions app/views/layouts/design_system.html.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
<% content_for :head do %>
<meta name="govuk:components_gem_version" content="<%= GovukPublishingComponents::VERSION %>" />
<%= javascript_include_tag "domain-config" %>
<%= javascript_include_tag "govuk_publishing_components/load-analytics" %>
<% end %>
<%= render "govuk_publishing_components/components/layout_for_admin",
product_name: "Collections Publisher",
environment: GovukPublishingComponents::AppHelpers::Environment.current_acceptance_environment,
head: yield(:head),
browser_title: yield(:page_title).presence || yield(:title) do %>
<%= render "govuk_publishing_components/components/skip_link" %>
Expand Down

0 comments on commit 550cb77

Please sign in to comment.