Skip to content

Commit

Permalink
Support for GA4 Tag Manager
Browse files Browse the repository at this point in the history
adding support for GA4 tag manager. Can activate by setting `ga4_tracking_id` config variable.

Have not reviewed the custom analytics tracking javascript relating to search operations

Co-authored-by: Hauwa Muhammad  <HauwaHakimi@users.noreply.github.com>
  • Loading branch information
heathd and HauwaHakimi committed May 9, 2024
1 parent 5994807 commit 53dfb2c
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
5 changes: 4 additions & 1 deletion example/config/tech-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ footer_links:
Accessibility: /hidden-page.html
Hidden Page: /hidden-page.html

# Tracking ID from Google Analytics (e.g. UA-XXXX-Y)
# Tracking ID (if using GA4 e.g G-XXXXXX)
ga4_tracking_id:

# Tracking ID from Google Universal Analytics (e.g. UA-XXXX-Y)
ga_tracking_id:

# Enable multipage navigation in the sidebar
Expand Down
10 changes: 10 additions & 0 deletions lib/source/layouts/_analytics_head.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<% if config[:tech_docs][:ga4_tracking_id].is_a?(String) && !config[:tech_docs][:ga4_tracking_id].empty? %>
<!-- Google tag (gtag.js) -->
<script async src="https://www.googletagmanager.com/gtag/js?id=<%= config[:tech_docs][:ga4_tracking_id]%>"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', '<%= config[:tech_docs][:ga4_tracking_id] %>');
</script>
<% end %>
2 changes: 2 additions & 0 deletions lib/source/layouts/core.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<!doctype html>
<html lang="en" class="govuk-template no-js">
<head>
<%= partial 'layouts/analytics_head' %>

<meta content="IE=edge" http-equiv="X-UA-Compatible">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover">
Expand Down

0 comments on commit 53dfb2c

Please sign in to comment.