Skip to content

Commit 0471790

Browse files
committed
Support Google Tag Manager approach to analytics
We already support the other approach to tracking data for Google Analytics 4: gtag.js. We need to support the Google Tag Manager approach to address new needs https://support.google.com/tagmanager/answer/7582054 https://developers.google.com/tag-platform/tag-manager/datalayer
1 parent aeb3282 commit 0471790

File tree

3 files changed

+12
-0
lines changed

3 files changed

+12
-0
lines changed

example/config/tech-docs.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ footer_links:
2222
# Tracking IDs
2323
# Google Analytics 4 using gtag.js (e.g G-XXXXXX)
2424
ga4_tracking_id:
25+
# Google Analytics 4 using Google Tag Manager (e.g GTM-XXXXXXXX)
26+
ga4_gtm_tracking_id:
2527
# Google Universal Analytics (e.g. UA-XXXX-Y)
2628
ga_tracking_id:
2729

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<% if config[:tech_docs][:ga4_gtm_tracking_id].is_a?(String) && !config[:tech_docs][:ga4_gtm_tracking_id].empty? %>
2+
<!-- Google Tag Manager -->
3+
<script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
4+
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
5+
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
6+
'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
7+
})(window,document,'script','dataLayer','<%= config[:tech_docs][:ga4_gtm_tracking_id] %>');</script>
8+
<!-- End Google Tag Manager -->
9+
<% end %>

lib/source/layouts/core.erb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
<html lang="en" class="govuk-template <%= config[:tech_docs][:show_govuk_logo] ? 'govuk-template--rebranded ' : '' %>no-js">
33
<head>
44
<%= partial 'layouts/analytics_ga4_gtag' %>
5+
<%= partial 'layouts/analytics_ga4_gtm' %>
56

67
<meta content="IE=edge" http-equiv="X-UA-Compatible">
78
<meta charset="utf-8">

0 commit comments

Comments
 (0)