govuk_tech_docs 5.1.0 → 5.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6dc363343ebff60652f16de327d4bc64c8c7d043ca22de573699c62fd177e354
4
- data.tar.gz: ff3c5f3505a3592592c088d0e652279eaba401a886fb76bf100e29e266b19d64
3
+ metadata.gz: 815d430d2f6a2cc8dcf9141688e49ad697bac3c166d719b5cc73d6075c7e945c
4
+ data.tar.gz: 9e177ece8704db4e26b59851d7c0e7a82ae6ed4ec5637b14f3502d651b14078f
5
5
  SHA512:
6
- metadata.gz: 68280ebd9b54a3b89962caa936fdda0754459284ac714e5399af7d785f997a52cf4c65c71f0f8fc3dd402a03c38705a8d3b4f0a859ce5590492be3be8c37265b
7
- data.tar.gz: bb17570b442df5edffacbb28f4fa5837b8066b63a30cec06ba6952f0bf2f50ea6bb0be536828c08bce108275d4ecd964e0ab768ba1a420d456bd0d68bc83dd78
6
+ metadata.gz: 661ddbea41fa5e33921213f230e74fe300cb65883f7f3c88f926851d7ef5dfc917365f33412fdbf559204591a3213bc749f476484ea104019ccdeb1bd1e86c51
7
+ data.tar.gz: ac22c72e66a82cf66c8366ee1bc26c1991433b2da627406221c4465ed073757a0ca1635010ea0a5872e9f53b1d9374cf560b2dcea99cd2f7c002bfe3bf1aec2f
@@ -1,6 +1,6 @@
1
1
  name: Test
2
2
 
3
- on:
3
+ on:
4
4
  push:
5
5
  branches:
6
6
  - main
@@ -14,7 +14,7 @@ jobs:
14
14
 
15
15
  strategy:
16
16
  matrix:
17
- ruby: ['3.1', '3.2', '3.3']
17
+ ruby: ['3.2', '3.3', '3.4']
18
18
 
19
19
  steps:
20
20
  - uses: actions/checkout@v4
data/CHANGELOG.md CHANGED
@@ -1,11 +1,14 @@
1
- ## Unreleased
1
+ ## 5.2.0
2
2
 
3
- ### New Features
3
+ ### New features
4
4
 
5
- - [Adds support for GA4 as a separate tracking parameter from Universal Analytics](https://github.com/alphagov/tech-docs-gem/pull/350)
5
+ - [Support using Google Tag Manager for Google Analytics 4](https://github.com/alphagov/tech-docs-gem/pull/436)
6
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.
7
+ ## 5.1.1
8
+
9
+ ### Fixes
10
+
11
+ - [Change npm installation method used](https://github.com/alphagov/tech-docs-gem/pull/433)
9
12
 
10
13
  ## 5.1.0
11
14
 
@@ -13,6 +16,9 @@ We'll return at a later date with a major breaking change that deprecates UA cod
13
16
 
14
17
  - [Add GA4 support](https://github.com/alphagov/tech-docs-gem/pull/350)
15
18
 
19
+ 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.
20
+ We'll return at a later date with a major breaking change that deprecates UA code.
21
+
16
22
  ### Fixes
17
23
 
18
24
  - [Fix syntax highlighting by pinning middleman-syntax to v3.6+](https://github.com/alphagov/tech-docs-gem/pull/427)
@@ -19,10 +19,12 @@ footer_links:
19
19
  Accessibility: /hidden-page.html
20
20
  Hidden Page: /hidden-page.html
21
21
 
22
- # Tracking ID (if using GA4 e.g G-XXXXXX)
22
+ # Tracking IDs
23
+ # Google Analytics 4 using gtag.js (e.g G-XXXXXX)
23
24
  ga4_tracking_id:
24
-
25
- # Tracking ID from Google Universal Analytics (e.g. UA-XXXX-Y)
25
+ # Google Analytics 4 using Google Tag Manager (e.g GTM-XXXXXXXX)
26
+ ga4_gtm_tracking_id:
27
+ # Google Universal Analytics (e.g. UA-XXXX-Y)
26
28
  ga_tracking_id:
27
29
 
28
30
  # Enable multipage navigation in the sidebar
@@ -4,8 +4,8 @@ lib = File.expand_path("lib", __dir__)
4
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
5
  require "govuk_tech_docs/version"
6
6
 
7
- `npm install`
8
- abort "npm install failed" unless $CHILD_STATUS.success?
7
+ `npm ci`
8
+ abort "npm ci failed" unless $CHILD_STATUS.success?
9
9
 
10
10
  unless File.exist?("node_modules/govuk-frontend/dist/govuk/all.scss")
11
11
  abort "govuk-frontend npm package not installed"
@@ -0,0 +1,39 @@
1
+ (function ($, Modules) {
2
+ 'use strict'
3
+
4
+ Modules.CookieBanner = function () {
5
+ let $cookieBanner
6
+
7
+ this.start = function ($element) {
8
+ $cookieBanner = $element
9
+
10
+ if ($cookieBanner && getCookie('cookies_preferences_set') !== 'true') {
11
+ $('#cookie-banner__accept').on('click', acceptCookies)
12
+ $('#cookie-banner__reject').on('click', rejectCookies)
13
+
14
+ $cookieBanner.removeAttr('hidden')
15
+ }
16
+ }
17
+
18
+ function acceptCookies () {
19
+ document.cookie = 'cookies_preferences_set=true'
20
+ document.cookie = 'cookies_policy={"usage":true}'
21
+
22
+ $cookieBanner.attr('hidden', 'hidden')
23
+ }
24
+
25
+ function rejectCookies () {
26
+ document.cookie = 'cookies_preferences_set=true'
27
+ document.cookie = 'cookies_policy={"usage":false}'
28
+
29
+ $cookieBanner.attr('hidden', 'hidden')
30
+ }
31
+
32
+ function getCookie (name) {
33
+ return document.cookie
34
+ .split('; ')
35
+ .find(cookie => cookie.split('=')[0] === name)
36
+ ?.split('=')[1]
37
+ }
38
+ }
39
+ })(jQuery, window.GOVUK.Modules)
@@ -1,5 +1,6 @@
1
1
  //= require _govuk/modules
2
2
  //= require _modules/anchored-headings
3
+ //= require _modules/cookie-banner
3
4
  //= require _modules/in-page-navigation
4
5
  //= require _modules/navigation
5
6
  //= require _modules/page-expiry
@@ -17,6 +17,7 @@ $govuk-new-link-styles: true;
17
17
  @import "govuk/core/index";
18
18
  @import "govuk/objects/index";
19
19
 
20
+ @import "govuk/components/cookie-banner/index";
20
21
  @import "govuk/components/footer/index";
21
22
  @import "govuk/components/header/index";
22
23
  @import "govuk/components/inset-text/index";
@@ -1,3 +1,3 @@
1
1
  module GovukTechDocs
2
- VERSION = "5.1.0".freeze
2
+ VERSION = "5.2.0".freeze
3
3
  end
@@ -7,4 +7,4 @@
7
7
  gtag('js', new Date());
8
8
  gtag('config', '<%= config[:tech_docs][:ga4_tracking_id] %>');
9
9
  </script>
10
- <% end %>
10
+ <% end %>
@@ -0,0 +1,18 @@
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>
4
+ const cookies_policy_cookie = document.cookie
5
+ .split('; ')
6
+ .find(cookie => cookie.split('=')[0] === 'cookies_policy')
7
+ ?.split('=')[1]
8
+
9
+ if (cookies_policy_cookie && JSON.parse(cookies_policy_cookie).usage) {
10
+ (function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
11
+ new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
12
+ j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
13
+ 'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
14
+ })(window,document,'script','dataLayer','<%= config[:tech_docs][:ga4_gtm_tracking_id] %>');
15
+ }
16
+ </script>
17
+ <!-- End Google Tag Manager -->
18
+ <% end %>
@@ -0,0 +1,24 @@
1
+ <% if config[:tech_docs][:ga4_gtm_tracking_id].is_a?(String) && !config[:tech_docs][:ga4_gtm_tracking_id].empty? %>
2
+ <div class="govuk-cookie-banner" data-nosnippet role="region" aria-label="Cookies on <%= config[:tech_docs][:service_name] %>" hidden="hidden" data-module="cookie-banner">
3
+ <div class="govuk-cookie-banner__message govuk-width-container">
4
+ <div class="govuk-grid-row">
5
+ <div class="govuk-grid-column-two-thirds">
6
+ <h2 class="govuk-cookie-banner__heading govuk-heading-m">
7
+ Cookies on <%= config[:tech_docs][:service_name] %>
8
+ </h2>
9
+ <div class="govuk-cookie-banner__content">
10
+ <p class="govuk-body">We’d like to use analytics cookies so we can understand how you use the service and make improvements.</p>
11
+ </div>
12
+ </div>
13
+ </div>
14
+ <div class="govuk-button-group">
15
+ <button id="cookie-banner__accept" type="button" class="govuk-button" data-module="govuk-button">
16
+ Accept analytics cookies
17
+ </button>
18
+ <button id="cookie-banner__reject" type="button" class="govuk-button" data-module="govuk-button">
19
+ Reject analytics cookies
20
+ </button>
21
+ </div>
22
+ </div>
23
+ </div>
24
+ <% end %>
@@ -1,7 +1,8 @@
1
1
  <!doctype html>
2
2
  <html lang="en" class="govuk-template <%= config[:tech_docs][:show_govuk_logo] ? 'govuk-template--rebranded ' : '' %>no-js">
3
3
  <head>
4
- <%= partial 'layouts/analytics_head' %>
4
+ <%= partial 'layouts/analytics_ga4_gtag' %>
5
+ <%= partial 'layouts/analytics_ga4_gtm' %>
5
6
 
6
7
  <meta content="IE=edge" http-equiv="X-UA-Compatible">
7
8
  <meta charset="utf-8">
@@ -51,6 +52,7 @@
51
52
  <script>document.body.className += ' js-enabled' + ('noModule' in HTMLScriptElement.prototype ? ' govuk-frontend-supported' : '');</script>
52
53
 
53
54
  <div class="app-pane">
55
+ <%= partial 'layouts/cookie_banner' %>
54
56
  <div class="app-pane__header toc-open-disabled">
55
57
  <a href="#content" class="govuk-skip-link" data-module="govuk-skip-link">Skip to main content</a>
56
58
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: govuk_tech_docs
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.1.0
4
+ version: 5.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Government Digital Service
@@ -417,6 +417,7 @@ files:
417
417
  - lib/assets/javascripts/_govuk/modules.js
418
418
  - lib/assets/javascripts/_modules/anchored-headings.js
419
419
  - lib/assets/javascripts/_modules/collapsible-navigation.js
420
+ - lib/assets/javascripts/_modules/cookie-banner.js
420
421
  - lib/assets/javascripts/_modules/in-page-navigation.js
421
422
  - lib/assets/javascripts/_modules/navigation.js
422
423
  - lib/assets/javascripts/_modules/page-expiry.js
@@ -481,7 +482,9 @@ files:
481
482
  - lib/source/images/search-button.png
482
483
  - lib/source/images/search-result-caret.svg
483
484
  - lib/source/layouts/_analytics.erb
484
- - lib/source/layouts/_analytics_head.erb
485
+ - lib/source/layouts/_analytics_ga4_gtag.erb
486
+ - lib/source/layouts/_analytics_ga4_gtm.erb
487
+ - lib/source/layouts/_cookie_banner.erb
485
488
  - lib/source/layouts/_footer.erb
486
489
  - lib/source/layouts/_header.erb
487
490
  - lib/source/layouts/_page_review.erb