Skip to content

Commit 6d81523

Browse files
authored
Merge pull request #350 from alphagov/ga4-tag-manager
Support for GA4 Tag Manager
2 parents d0327a9 + bfec239 commit 6d81523

File tree

4 files changed

+28
-6
lines changed

4 files changed

+28
-6
lines changed

CHANGELOG.md

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
## Unreleased
22

3+
### New Features
4+
5+
- [Adds support for GA4 as a separate tracking parameter from Universal Analytics](https://github.com/alphagov/tech-docs-gem/pull/350)
6+
7+
NB: [Universal Analytics is now gone](https://support.google.com/analytics/answer/11583528?hl=en) so anyone still using the older approach is likely facing broken analytics, or has developed a workaround.
8+
We'll return at a later date with a major breaking change that deprecates UA code.
9+
310
## 5.0.2
411

512
### Fixes
@@ -60,7 +67,7 @@ To use the service_link at the start of the path to the favicon images, you need
6067

6168
- [Allow non-GOV.UK favicon and opengraph assets](https://github.com/alphagov/tech-docs-gem/pull/387)
6269

63-
To use a non-crown assets, you need to
70+
To use a non-crown assets, you need to
6471
- add `favicon.ico`, `favicon.svg` and `opengraph-image.png` to your `source/images` folder.
6572
- set `show_govuk_logo: false`
6673

@@ -158,22 +165,22 @@ You can now [configure your Tech Docs Template (TDT) to build your documentation
158165

159166
Thanks [@eddgrant](https://github.com/eddgrant) for contributing this feature and the associated fixes.
160167

161-
This change was introduced in [pull request #291: Support sites deployed on paths other than "/" (by generating relative links)](https://github.com/alphagov/tech-docs-gem/pull/291).
168+
This change was introduced in [pull request #291: Support sites deployed on paths other than "/" (by generating relative links)](https://github.com/alphagov/tech-docs-gem/pull/291).
162169

163170
## 3.1.0
164171

165172
### New features
166173

167-
There are some steps you should follow as the Technical Documentation Template (TDT) now uses GOV.UK Frontend 4.0.0.
174+
There are some steps you should follow as the Technical Documentation Template (TDT) now uses GOV.UK Frontend 4.0.0.
168175

169176
1. Update your documentation site to use the latest template version. You can [follow the TDT guidance on using the latest template version](https://tdt-documentation.london.cloudapps.digital/maintain_project/use_latest_template/).
170-
2. Check your documentation site displays correctly. If your site does not display correctly, you can refer to the [GOV.UK Frontend 4.0.0 release note](https://github.com/alphagov/govuk-frontend/releases/tag/v4.0.0) for more information.
177+
2. Check your documentation site displays correctly. If your site does not display correctly, you can refer to the [GOV.UK Frontend 4.0.0 release note](https://github.com/alphagov/govuk-frontend/releases/tag/v4.0.0) for more information.
171178

172179
## 3.0.1
173180

174181
### Fixes
175182

176-
We’ve made the following fixes to the tech docs gem in [pull request #281: Don't break TOC when OpenAPI description includes headers](https://github.com/alphagov/tech-docs-gem/pull/281):
183+
We’ve made the following fixes to the tech docs gem in [pull request #281: Don't break TOC when OpenAPI description includes headers](https://github.com/alphagov/tech-docs-gem/pull/281):
177184

178185
* we now render OpenAPI Markdown with the same Markdown renderer as other documents
179186
* table of contents (TOC) uses `TechDocsHTMLRenderer` to render the headings with IDs

example/config/tech-docs.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@ footer_links:
1919
Accessibility: /hidden-page.html
2020
Hidden Page: /hidden-page.html
2121

22-
# Tracking ID from Google Analytics (e.g. UA-XXXX-Y)
22+
# Tracking ID (if using GA4 e.g G-XXXXXX)
23+
ga4_tracking_id:
24+
25+
# Tracking ID from Google Universal Analytics (e.g. UA-XXXX-Y)
2326
ga_tracking_id:
2427

2528
# Enable multipage navigation in the sidebar
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<% if config[:tech_docs][:ga4_tracking_id].is_a?(String) && !config[:tech_docs][:ga4_tracking_id].empty? %>
2+
<!-- Google tag (gtag.js) -->
3+
<script async src="https://www.googletagmanager.com/gtag/js?id=<%= config[:tech_docs][:ga4_tracking_id]%>"></script>
4+
<script>
5+
window.dataLayer = window.dataLayer || [];
6+
function gtag(){dataLayer.push(arguments);}
7+
gtag('js', new Date());
8+
gtag('config', '<%= config[:tech_docs][:ga4_tracking_id] %>');
9+
</script>
10+
<% end %>

lib/source/layouts/core.erb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
<!doctype html>
22
<html lang="en" class="govuk-template <%= config[:tech_docs][:show_govuk_logo] ? 'govuk-template--rebranded ' : '' %>no-js">
33
<head>
4+
<%= partial 'layouts/analytics_head' %>
5+
46
<meta content="IE=edge" http-equiv="X-UA-Compatible">
57
<meta charset="utf-8">
68
<meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover">

0 commit comments

Comments
 (0)