-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- rewrites the ga4-finder-tracker slightly to use the schema code and specifically use the mergeProperties function of the schema to ensure that all undefined attributes from the schema are included in the data sent to the dataLayer
- Loading branch information
1 parent
dfd1465
commit d9c53d9
Showing
2 changed files
with
36 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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') | ||
|
@@ -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) | ||
}) | ||
|
@@ -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') | ||
|
@@ -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) | ||
|
||
|
@@ -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) | ||
|
@@ -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') | ||
|
@@ -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) | ||
|
@@ -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') | ||
|
@@ -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) | ||
|