Skip to content

Commit

Permalink
Merge pull request #3118 from alphagov/dependabot/bundler/govuk_publi…
Browse files Browse the repository at this point in the history
…shing_components-35.12.0

Bump govuk_publishing_components from 35.11.0 to 35.12.0
  • Loading branch information
andysellick authored Jul 26, 2023
2 parents 6ad2d22 + d9c53d9 commit 2f2df7d
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 36 deletions.
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ GEM
govuk_personalisation (0.14.0)
plek (>= 1.9.0)
rails (>= 6, < 8)
govuk_publishing_components (35.11.0)
govuk_publishing_components (35.12.0)
govuk_app_config
govuk_personalisation (>= 0.7.0)
kramdown
Expand Down
47 changes: 24 additions & 23 deletions app/assets/javascripts/analytics-ga4/ga4-finder-tracker.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,18 @@
return
}

var schema = new GOVUK.analyticsGa4.Schemas().eventSchema()
schema.event = 'event_data'
schema.event_data.type = 'finder'
schema.event_data.event_name = 'select_content'
var data = {}
data.type = 'finder'
data.event_name = 'select_content'

var elementInfo = this.getElementInfo(eventTarget, elementType, section)
var elementValue = elementInfo.elementValue
schema.event_data.text = elementValue

data.text = elementValue
var wasFilterRemoved = elementInfo.wasFilterRemoved
schema = this.setSchemaBasedOnChangeType(schema, elementValue, elementType, wasFilterRemoved, changeType, section)
data = this.setSchemaBasedOnChangeType(data, elementValue, elementType, wasFilterRemoved, changeType, section)

var schemas = new window.GOVUK.analyticsGa4.Schemas()
var schema = schemas.mergeProperties(data, 'event_data')

window.GOVUK.analyticsGa4.core.sendData(schema)
},
Expand Down Expand Up @@ -112,36 +113,36 @@
switch (changeType) {
case 'update-filter':
if (section) {
schema.event_data.section = section.getAttribute('data-ga4-section')
schema.section = section.getAttribute('data-ga4-section')
}

if (wasFilterRemoved) {
schema.event_data.action = 'remove'
schema.event_data.text = elementType === 'text' ? undefined : elementValue
schema.action = 'remove'
schema.text = elementType === 'text' ? undefined : elementValue
} else {
schema.event_data.action = elementType === 'text' ? 'search' : 'select'
schema.event_data.index = this.getSectionIndex(section)
schema.action = elementType === 'text' ? 'search' : 'select'
schema.index = this.getSectionIndex(section)
}
break

case 'update-keyword':
schema.event_data.event_name = 'search'
schema.event_data.url = window.location.pathname
schema.event_data.section = 'Search'
schema.event_data.action = 'search'
schema.event_data.text = PIIRemover.stripPIIWithOverride(schema.event_data.text, true, true)
schema.event_data.text = GOVUK.analyticsGa4.core.trackFunctions.removeLinesAndExtraSpaces(schema.event_data.text)
schema.event_data.text = schema.event_data.text.toLowerCase()
schema.event_name = 'search'
schema.url = window.location.pathname
schema.section = 'Search'
schema.action = 'search'
schema.text = PIIRemover.stripPIIWithOverride(schema.text, true, true)
schema.text = GOVUK.analyticsGa4.core.trackFunctions.removeLinesAndExtraSpaces(schema.text)
schema.text = schema.text.toLowerCase()
break

case 'clear-all-filters':
schema.event_data.action = 'remove'
schema.event_data.text = 'Clear all filters'
schema.action = 'remove'
schema.text = 'Clear all filters'
break

case 'update-sort':
schema.event_data.action = 'sort'
schema.event_data.section = 'Sort by'
schema.action = 'sort'
schema.section = 'Sort by'
break
}
return schema
Expand Down
24 changes: 12 additions & 12 deletions spec/javascripts/analytics-ga4/ga4-finder-tracker.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ describe('GA4 finder change tracker', function () {
inputParent = document.createElement('div')
inputParent.setAttribute('data-ga4-change-category', 'update-filter checkbox')
inputParent.setAttribute('data-ga4-section', 'Your favourite chocolate')
var index = { index_section: 1, index_section_count: 1, index_link: undefined }
var index = { index_section: 1, index_section_count: 1 }
inputParent.setAttribute('data-ga4-index', JSON.stringify(index))

input = document.createElement('input')
Expand All @@ -119,15 +119,15 @@ describe('GA4 finder change tracker', function () {
expected.event_data.section = 'Your favourite chocolate'
expected.event_data.text = 'All types of chocolate'
expected.event_data.action = 'select'
expected.event_data.index = index
expected.event_data.index = { index_section: 1, index_section_count: 1, index_link: undefined }

expect(window.dataLayer[0]).toEqual(expected)

input.checked = false
window.GOVUK.triggerEvent(input, 'change')

expected.event_data.action = 'remove'
expected.event_data.index = undefined
expected.event_data.index = { index_section: undefined, index_section_count: undefined, index_link: undefined }

expect(window.dataLayer[1]).toEqual(expected)
})
Expand All @@ -136,7 +136,7 @@ describe('GA4 finder change tracker', function () {
inputParent = document.createElement('div')
inputParent.setAttribute('data-ga4-change-category', 'update-filter radio')
inputParent.setAttribute('data-ga4-section', 'Your favourite chocolate')
var index = { index_section: 1, index_section_count: 1, index_link: undefined }
var index = { index_section: 1, index_section_count: 1 }
inputParent.setAttribute('data-ga4-index', JSON.stringify(index))

option1 = document.createElement('input')
Expand Down Expand Up @@ -170,7 +170,7 @@ describe('GA4 finder change tracker', function () {
expected.event_data.section = 'Your favourite chocolate'
expected.event_data.text = 'Belgian chocolate'
expected.event_data.action = 'select'
expected.event_data.index = index
expected.event_data.index = { index_section: 1, index_section_count: 1, index_link: undefined }

expect(window.dataLayer[0]).toEqual(expected)

Expand All @@ -179,7 +179,7 @@ describe('GA4 finder change tracker', function () {
window.GOVUK.triggerEvent(option1, 'change')

expected.event_data.action = 'remove'
expected.event_data.index = undefined
expected.event_data.index = { index_section: undefined, index_section_count: undefined, index_link: undefined }
expected.event_data.text = 'All types of chocolate (default)'

expect(window.dataLayer[1]).toEqual(expected)
Expand All @@ -189,7 +189,7 @@ describe('GA4 finder change tracker', function () {
inputParent = document.createElement('div')
inputParent.setAttribute('data-ga4-change-category', 'update-filter select')
inputParent.setAttribute('data-ga4-section', 'Your favourite chocolate')
var index = { index_section: 5, index_section_count: 15, index_link: undefined }
var index = { index_section: 5, index_section_count: 15 }
inputParent.setAttribute('data-ga4-index', JSON.stringify(index))

input = document.createElement('select')
Expand Down Expand Up @@ -218,15 +218,15 @@ describe('GA4 finder change tracker', function () {
expected.event_data.section = 'Your favourite chocolate'
expected.event_data.text = 'Belgian chocolate'
expected.event_data.action = 'select'
expected.event_data.index = index
expected.event_data.index = { index_section: 5, index_section_count: 15, index_link: undefined }

expect(window.dataLayer[0]).toEqual(expected)

input.value = 'all-types'
window.GOVUK.triggerEvent(input, 'change')

expected.event_data.action = 'remove'
expected.event_data.index = undefined
expected.event_data.index = { index_link: undefined, index_section: undefined, index_section_count: undefined }
expected.event_data.text = 'All types of chocolate (default)'

expect(window.dataLayer[1]).toEqual(expected)
Expand All @@ -236,7 +236,7 @@ describe('GA4 finder change tracker', function () {
inputParent = document.createElement('div')
inputParent.setAttribute('data-ga4-change-category', 'update-filter text')
inputParent.setAttribute('data-ga4-section', 'Your favourite chocolate')
var index = { index_section: 2, index_section_count: 2, index_link: undefined }
var index = { index_section: 2, index_section_count: 2 }
inputParent.setAttribute('data-ga4-index', JSON.stringify(index))

input = document.createElement('input')
Expand All @@ -252,15 +252,15 @@ describe('GA4 finder change tracker', function () {
expected.event_data.section = 'Your favourite chocolate'
expected.event_data.text = 'Here is an email that should not get redacted [email protected]'
expected.event_data.action = 'search'
expected.event_data.index = index
expected.event_data.index = { index_section: 2, index_section_count: 2, index_link: undefined }

expect(window.dataLayer[0]).toEqual(expected)

input.value = ''
window.GOVUK.triggerEvent(input, 'change')

expected.event_data.action = 'remove'
expected.event_data.index = undefined
expected.event_data.index = { index_section: undefined, index_section_count: undefined, index_link: undefined }
expected.event_data.text = undefined

expect(window.dataLayer[1]).toEqual(expected)
Expand Down

0 comments on commit 2f2df7d

Please sign in to comment.