Skip to content

Commit

Permalink
Merge branch 'main' into ga4-attachment-refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
AshGDS authored Aug 14, 2023
2 parents a455419 + 3659c8c commit beeb017
Show file tree
Hide file tree
Showing 25 changed files with 722 additions and 226 deletions.
15 changes: 14 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,22 @@

## Unreleased

* Add GA4 pageview meta tag: ab_test ([PR #3523](https://github.com/alphagov/govuk_publishing_components/pull/3523))
* Add a reset option into the GA4 scrolltracker ([PR #3544](https://github.com/alphagov/govuk_publishing_components/pull/3544))
* Expand GA4 form tracker ([PR #3546](https://github.com/alphagov/govuk_publishing_components/pull/3546))
* Adjust core functions setIndexes ([PR #3541](https://github.com/alphagov/govuk_publishing_components/pull/3541))
* GA4 pageview changes ([PR #3542](https://github.com/alphagov/govuk_publishing_components/pull/3542))
* Fix select width overlap bug ([PR #3538](https://github.com/alphagov/govuk_publishing_components/pull/3538))
* Add section attribute to scroll tracking ([PR #3537](https://github.com/alphagov/govuk_publishing_components/pull/3537))
* Add navigation-page-type GA4 pageview attribute ([PR #3529](https://github.com/alphagov/govuk_publishing_components/pull/3529))
* Update the documentation for loading component stylesheets individually ([PR #3543](https://github.com/alphagov/govuk_publishing_components/pull/3543))
* Add GA4 video tracking ([PR #3535](https://github.com/alphagov/govuk_publishing_components/pull/3535))
* Move GA4 attachment link tracking to all attachment links ([PR #3515](https://github.com/alphagov/govuk_publishing_components/pull/3515))

## 35.13.1

* Add GA4 pageview meta tag: ab_test ([PR #3523](https://github.com/alphagov/govuk_publishing_components/pull/3523))
* Wrap the text of `start` buttons in a `span` ([PR #3478](https://github.com/alphagov/govuk_publishing_components/pull/3478))

## 35.13.0

* Fix 100% scroll problem ([PR #3521](https://github.com/alphagov/govuk_publishing_components/pull/3521))
Expand Down
140 changes: 70 additions & 70 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
govuk_publishing_components (35.13.0)
govuk_publishing_components (35.13.1)
govuk_app_config
govuk_personalisation (>= 0.7.0)
kramdown
Expand All @@ -13,67 +13,67 @@ PATH
GEM
remote: https://rubygems.org/
specs:
actioncable (7.0.6)
actionpack (= 7.0.6)
activesupport (= 7.0.6)
actioncable (7.0.7)
actionpack (= 7.0.7)
activesupport (= 7.0.7)
nio4r (~> 2.0)
websocket-driver (>= 0.6.1)
actionmailbox (7.0.6)
actionpack (= 7.0.6)
activejob (= 7.0.6)
activerecord (= 7.0.6)
activestorage (= 7.0.6)
activesupport (= 7.0.6)
actionmailbox (7.0.7)
actionpack (= 7.0.7)
activejob (= 7.0.7)
activerecord (= 7.0.7)
activestorage (= 7.0.7)
activesupport (= 7.0.7)
mail (>= 2.7.1)
net-imap
net-pop
net-smtp
actionmailer (7.0.6)
actionpack (= 7.0.6)
actionview (= 7.0.6)
activejob (= 7.0.6)
activesupport (= 7.0.6)
actionmailer (7.0.7)
actionpack (= 7.0.7)
actionview (= 7.0.7)
activejob (= 7.0.7)
activesupport (= 7.0.7)
mail (~> 2.5, >= 2.5.4)
net-imap
net-pop
net-smtp
rails-dom-testing (~> 2.0)
actionpack (7.0.6)
actionview (= 7.0.6)
activesupport (= 7.0.6)
actionpack (7.0.7)
actionview (= 7.0.7)
activesupport (= 7.0.7)
rack (~> 2.0, >= 2.2.4)
rack-test (>= 0.6.3)
rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.0, >= 1.2.0)
actiontext (7.0.6)
actionpack (= 7.0.6)
activerecord (= 7.0.6)
activestorage (= 7.0.6)
activesupport (= 7.0.6)
actiontext (7.0.7)
actionpack (= 7.0.7)
activerecord (= 7.0.7)
activestorage (= 7.0.7)
activesupport (= 7.0.7)
globalid (>= 0.6.0)
nokogiri (>= 1.8.5)
actionview (7.0.6)
activesupport (= 7.0.6)
actionview (7.0.7)
activesupport (= 7.0.7)
builder (~> 3.1)
erubi (~> 1.4)
rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.1, >= 1.2.0)
activejob (7.0.6)
activesupport (= 7.0.6)
activejob (7.0.7)
activesupport (= 7.0.7)
globalid (>= 0.3.6)
activemodel (7.0.6)
activesupport (= 7.0.6)
activerecord (7.0.6)
activemodel (= 7.0.6)
activesupport (= 7.0.6)
activestorage (7.0.6)
actionpack (= 7.0.6)
activejob (= 7.0.6)
activerecord (= 7.0.6)
activesupport (= 7.0.6)
activemodel (7.0.7)
activesupport (= 7.0.7)
activerecord (7.0.7)
activemodel (= 7.0.7)
activesupport (= 7.0.7)
activestorage (7.0.7)
actionpack (= 7.0.7)
activejob (= 7.0.7)
activerecord (= 7.0.7)
activesupport (= 7.0.7)
marcel (~> 1.0)
mini_mime (>= 1.1.0)
activesupport (7.0.6)
activesupport (7.0.7)
concurrent-ruby (~> 1.0, >= 1.0.2)
i18n (>= 1.6, < 2)
minitest (>= 5.1)
Expand Down Expand Up @@ -116,7 +116,7 @@ GEM
faker (3.2.0)
i18n (>= 1.8.11, < 2)
ffi (1.15.5)
gds-api-adapters (89.0.0)
gds-api-adapters (90.0.0)
addressable
link_header
null_logger
Expand Down Expand Up @@ -192,10 +192,10 @@ GEM
mime-types (3.4.1)
mime-types-data (~> 3.2015)
mime-types-data (3.2023.0218.1)
mini_mime (1.1.2)
mini_mime (1.1.5)
mini_portile2 (2.8.4)
minitest (5.18.1)
net-imap (0.3.6)
minitest (5.19.0)
net-imap (0.3.7)
date
net-protocol
net-pop (0.1.2)
Expand Down Expand Up @@ -309,7 +309,7 @@ GEM
opentelemetry-api (~> 1.1.0)
opentelemetry-instrumentation-base (~> 0.22.1)
opentelemetry-instrumentation-rack (~> 0.21)
opentelemetry-instrumentation-graphql (0.26.2)
opentelemetry-instrumentation-graphql (0.26.3)
opentelemetry-api (~> 1.0)
opentelemetry-instrumentation-base (~> 0.22.1)
opentelemetry-instrumentation-http (0.23.1)
Expand All @@ -336,7 +336,7 @@ GEM
opentelemetry-api (~> 1.0)
opentelemetry-common (~> 0.19.3)
opentelemetry-instrumentation-base (~> 0.22.1)
opentelemetry-instrumentation-pg (0.25.2)
opentelemetry-instrumentation-pg (0.25.3)
opentelemetry-api (~> 1.0)
opentelemetry-instrumentation-base (~> 0.22.1)
opentelemetry-instrumentation-que (0.6.1)
Expand Down Expand Up @@ -419,26 +419,26 @@ GEM
puma (6.3.0)
nio4r (~> 2.0)
racc (1.7.1)
rack (2.2.7)
rack (2.2.8)
rack-proxy (0.7.6)
rack
rack-test (2.1.0)
rack (>= 1.3)
rails (7.0.6)
actioncable (= 7.0.6)
actionmailbox (= 7.0.6)
actionmailer (= 7.0.6)
actionpack (= 7.0.6)
actiontext (= 7.0.6)
actionview (= 7.0.6)
activejob (= 7.0.6)
activemodel (= 7.0.6)
activerecord (= 7.0.6)
activestorage (= 7.0.6)
activesupport (= 7.0.6)
rails (7.0.7)
actioncable (= 7.0.7)
actionmailbox (= 7.0.7)
actionmailer (= 7.0.7)
actionpack (= 7.0.7)
actiontext (= 7.0.7)
actionview (= 7.0.7)
activejob (= 7.0.7)
activemodel (= 7.0.7)
activerecord (= 7.0.7)
activestorage (= 7.0.7)
activesupport (= 7.0.7)
bundler (>= 1.15.0)
railties (= 7.0.6)
rails-dom-testing (2.1.1)
railties (= 7.0.7)
rails-dom-testing (2.2.0)
activesupport (>= 5.0.0)
minitest
nokogiri (>= 1.6)
Expand All @@ -453,9 +453,9 @@ GEM
csv (~> 3.2)
i18n-tasks
rails-i18n
railties (7.0.6)
actionpack (= 7.0.6)
activesupport (= 7.0.6)
railties (7.0.7)
actionpack (= 7.0.7)
activesupport (= 7.0.7)
method_source
rake (>= 12.2)
thor (~> 1.0)
Expand All @@ -470,8 +470,8 @@ GEM
http-cookie (>= 1.0.2, < 2.0)
mime-types (>= 1.16, < 4.0)
netrc (~> 0.8)
rexml (3.2.5)
rouge (4.1.2)
rexml (3.2.6)
rouge (4.1.3)
rspec-core (3.12.2)
rspec-support (~> 3.12.0)
rspec-expectations (3.12.3)
Expand All @@ -489,15 +489,15 @@ GEM
rspec-mocks (~> 3.12)
rspec-support (~> 3.12)
rspec-support (3.12.0)
rubocop (1.53.1)
rubocop (1.55.0)
json (~> 2.3)
language_server-protocol (>= 3.17.0)
parallel (~> 1.10)
parser (>= 3.2.2.3)
rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 1.8, < 3.0)
rexml (>= 3.2.5, < 4.0)
rubocop-ast (>= 1.28.0, < 2.0)
rubocop-ast (>= 1.28.1, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 2.4.0, < 3.0)
rubocop-ast (1.29.0)
Expand All @@ -506,8 +506,8 @@ GEM
rubocop (~> 1.41)
rubocop-factory_bot (2.23.1)
rubocop (~> 1.33)
rubocop-govuk (4.11.0)
rubocop (= 1.53.1)
rubocop-govuk (4.12.0)
rubocop (= 1.55.0)
rubocop-ast (= 1.29.0)
rubocop-rails (= 2.20.2)
rubocop-rake (= 0.6.0)
Expand Down Expand Up @@ -569,13 +569,13 @@ GEM
crack (>= 0.3.2)
hashdiff (>= 0.4.0, < 2.0.0)
webrick (1.8.1)
websocket-driver (0.7.5)
websocket-driver (0.7.6)
websocket-extensions (>= 0.1.0)
websocket-extensions (0.1.5)
xpath (3.2.0)
nokogiri (~> 1.8)
yard (0.9.34)
zeitwerk (2.6.8)
zeitwerk (2.6.11)

PLATFORMS
ruby
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@
//= require ./analytics-ga4/ga4-auto-tracker
//= require ./analytics-ga4/ga4-smart-answer-results-tracker
//= require ./analytics-ga4/ga4-scroll-tracker
//= require ./analytics-ga4/ga4-video-tracker
//= require ./analytics-ga4/init-ga4
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,8 @@ window.GOVUK.analyticsGa4 = window.GOVUK.analyticsGa4 || {};

try {
var ga4LinkData = JSON.parse(module.getAttribute('data-ga4-link'))
ga4LinkData.index_total = totalLinks
// use index_total if it already exists, otherwise calculate it and set it
ga4LinkData.index_total = ga4LinkData.index_total || totalLinks
module.setAttribute('data-ga4-link', JSON.stringify(ga4LinkData))
} catch (e) {
// if there's a problem with the config, don't start the tracker
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,13 @@ window.GOVUK.Modules = window.GOVUK.Modules || {};
var labelText = input.label.innerText || input.label.textContent
var inputType = elem.getAttribute('type')
var inputNodename = elem.nodeName
var inputTypes = ['text', 'search', 'email', 'number']

if (inputType === 'checkbox' && elem.checked) {
input.answer = labelText
} else if (inputNodename === 'SELECT' && elem.options[elem.selectedIndex].value) {
input.answer = elem.options[elem.selectedIndex].text
} else if ((inputType === 'text' || inputType === 'search') && elem.value) {
} else if (inputTypes.indexOf(inputType) !== -1 && elem.value) {
if (this.includeTextInputValues) {
var PIIRemover = new window.GOVUK.analyticsGa4.PIIRemover()
input.answer = PIIRemover.stripPIIWithOverride(elem.value, true, true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ window.GOVUK.analyticsGa4.analyticsModules = window.GOVUK.analyticsGa4.analytics
content_id: this.getMetaContent('content-id'),

browse_topic: this.getMetaContent('section'),
navigation_page_type: this.getMetaContent('navigation-page-type'),
navigation_list_type: this.getMetaContent('navigation-list-type'),
step_navs: this.getMetaContent('stepnavs'),
taxonomy_level1: this.getMetaContent('themes'),
taxonomy_main: this.getMetaContent('taxon-slug'),
taxonomy_main_id: this.getMetaContent('taxon-id'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@
link_domain: this.undefined,
link_path_parts: this.undefined,
tool_name: this.undefined,
percent_scrolled: this.undefined
percent_scrolled: this.undefined,
video_current_time: this.undefined,
video_duration: this.undefined,
video_percent: this.undefined
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ window.GOVUK.Modules = window.GOVUK.Modules || {};
window.addEventListener('scroll', this.scrollEvent)
this.resizeEvent = this.onResize.bind(this)
window.addEventListener('resize', this.resizeEvent)
this.resetEvent = this.onReset.bind(this)
window.addEventListener('dynamic-page-update', this.resetEvent)

// check if the page height changes e.g. accordion opened
this.interval = window.setInterval(function () {
Expand Down Expand Up @@ -115,6 +117,7 @@ window.GOVUK.Modules = window.GOVUK.Modules || {};
data.type = node.eventData.type
// following will be undefined if tracking percentages
data.text = node.eventData.text
data.section = node.eventData.text
data.index = node.eventData.index
// following will be undefined if tracking headings
data.percent_scrolled = node.eventData.percent_scrolled
Expand All @@ -131,6 +134,14 @@ window.GOVUK.Modules = window.GOVUK.Modules || {};
return scroll <= top && (scroll + this.windowHeight) >= bottom
}

// if reset, we set all nodes 'alreadySeen' to false
// used when the page content is dynamically updated e.g. search
Ga4ScrollTracker.prototype.onReset = function () {
for (var i = 0; i < this.trackedNodes.length; i++) {
this.trackedNodes[i].alreadySeen = false
}
}

Ga4ScrollTracker.Heading = function (config) {
this.config = config
}
Expand Down
Loading

0 comments on commit beeb017

Please sign in to comment.