-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3032 from alphagov/fix_search_referrer_bug
Fix search referrer bug
- Loading branch information
Showing
6 changed files
with
75 additions
and
34 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
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
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 |
---|---|---|
|
@@ -91,51 +91,51 @@ describe('Google Analytics ecommerce tracking', function () { | |
|
||
describe('on page load', function () { | ||
it('should push a nullified ecommerce object to the dataLayer', function () { | ||
GOVUK.analyticsGa4.Ga4EcommerceTracker.init(true) | ||
GOVUK.analyticsGa4.Ga4EcommerceTracker.init() | ||
|
||
expect(window.dataLayer[0].search_results.ecommerce).toBe(null) | ||
}) | ||
|
||
it('should get the search query', function () { | ||
onPageLoadExpected.search_results.term = 'coronavirus' | ||
searchResultsParentEl.setAttribute('data-search-query', 'coronavirus') | ||
GOVUK.analyticsGa4.Ga4EcommerceTracker.init(true) | ||
GOVUK.analyticsGa4.Ga4EcommerceTracker.init() | ||
|
||
expect(window.dataLayer[1].search_results.term).toBe(onPageLoadExpected.search_results.term) | ||
}) | ||
|
||
it('should remove PII from search query', function () { | ||
onPageLoadExpected.search_results.term = '[email]' | ||
searchResultsParentEl.setAttribute('data-search-query', '[email protected]') | ||
GOVUK.analyticsGa4.Ga4EcommerceTracker.init(true) | ||
GOVUK.analyticsGa4.Ga4EcommerceTracker.init() | ||
|
||
expect(window.dataLayer[1].search_results.term).toBe(onPageLoadExpected.search_results.term) | ||
}) | ||
|
||
it('should get the variant', function () { | ||
onPageLoadExpected.search_results.sort = 'Relevance' | ||
searchResultsParentEl.setAttribute('data-ecommerce-variant', 'Relevance') | ||
GOVUK.analyticsGa4.Ga4EcommerceTracker.init(true) | ||
GOVUK.analyticsGa4.Ga4EcommerceTracker.init() | ||
|
||
expect(window.dataLayer[1].search_results.sort).toBe(onPageLoadExpected.search_results.sort) | ||
}) | ||
|
||
it('should set the variant to undefined when the data-ecommerce-variant does not exist', function () { | ||
onPageLoadExpected.search_results.sort = undefined | ||
searchResultsParentEl.removeAttribute('data-ecommerce-variant') | ||
GOVUK.analyticsGa4.Ga4EcommerceTracker.init(true) | ||
GOVUK.analyticsGa4.Ga4EcommerceTracker.init() | ||
|
||
expect(window.dataLayer[1].search_results.sort).toBe(onPageLoadExpected.search_results.sort) | ||
}) | ||
|
||
it('should get the number of search results i.e. 12345 search results in this test case', function () { | ||
GOVUK.analyticsGa4.Ga4EcommerceTracker.init(true) | ||
GOVUK.analyticsGa4.Ga4EcommerceTracker.init() | ||
|
||
expect(window.dataLayer[1].search_results.results).toBe(onPageLoadExpected.search_results.results) | ||
}) | ||
|
||
it('should get the item id for each search result', function () { | ||
GOVUK.analyticsGa4.Ga4EcommerceTracker.init(true) | ||
GOVUK.analyticsGa4.Ga4EcommerceTracker.init() | ||
|
||
var searchResults = window.dataLayer[1].search_results.ecommerce.items | ||
for (var i = 0; i < searchResults.length; i++) { | ||
|
@@ -144,7 +144,7 @@ describe('Google Analytics ecommerce tracking', function () { | |
}) | ||
|
||
it('should get the item list name for each search result', function () { | ||
GOVUK.analyticsGa4.Ga4EcommerceTracker.init(true) | ||
GOVUK.analyticsGa4.Ga4EcommerceTracker.init() | ||
|
||
var searchResults = window.dataLayer[1].search_results.ecommerce.items | ||
for (var i = 0; i < searchResults.length; i++) { | ||
|
@@ -158,7 +158,7 @@ describe('Google Analytics ecommerce tracking', function () { | |
} | ||
searchResultsParentEl.removeAttribute('data-list-title') | ||
|
||
GOVUK.analyticsGa4.Ga4EcommerceTracker.init(true) | ||
GOVUK.analyticsGa4.Ga4EcommerceTracker.init() | ||
|
||
var searchResults = window.dataLayer[1].search_results.ecommerce.items | ||
for (var j = 0; j < searchResults.length; j++) { | ||
|
@@ -167,7 +167,7 @@ describe('Google Analytics ecommerce tracking', function () { | |
}) | ||
|
||
it('should get the index for each search result using the data-ecommerce-index attribute', function () { | ||
GOVUK.analyticsGa4.Ga4EcommerceTracker.init(true) | ||
GOVUK.analyticsGa4.Ga4EcommerceTracker.init() | ||
|
||
var searchResults = window.dataLayer[1].search_results.ecommerce.items | ||
|
||
|
@@ -182,7 +182,7 @@ describe('Google Analytics ecommerce tracking', function () { | |
ecommerceRows[i].removeAttribute('data-ecommerce-index') | ||
} | ||
|
||
GOVUK.analyticsGa4.Ga4EcommerceTracker.init(true) | ||
GOVUK.analyticsGa4.Ga4EcommerceTracker.init() | ||
|
||
var searchResults = window.dataLayer[1].search_results.ecommerce.items | ||
for (var j = 0; j < searchResults.length; j++) { | ||
|
@@ -193,7 +193,7 @@ describe('Google Analytics ecommerce tracking', function () { | |
|
||
describe('when a new page isn\'t loaded e.g. when the user selects a filter', function () { | ||
it('should push a nullified ecommerce object to the dataLayer', function () { | ||
GOVUK.analyticsGa4.Ga4EcommerceTracker.init(false) | ||
GOVUK.analyticsGa4.Ga4EcommerceTracker.init('test') | ||
|
||
expect(window.dataLayer[1].search_results.ecommerce).toBe(null) | ||
}) | ||
|
@@ -215,7 +215,7 @@ describe('Google Analytics ecommerce tracking', function () { | |
} | ||
} | ||
|
||
GOVUK.analyticsGa4.Ga4EcommerceTracker.init(false) | ||
GOVUK.analyticsGa4.Ga4EcommerceTracker.init('https://gov.uk/') | ||
|
||
expect(window.dataLayer[0].event).toBe(pageViewExpected.event) | ||
expect(window.dataLayer[0].page_view.location).toBe(pageViewExpected.page_view.location) | ||
|
@@ -254,7 +254,7 @@ describe('Google Analytics ecommerce tracking', function () { | |
}) | ||
|
||
it('should push a nullified ecommerce object to the dataLayer', function () { | ||
GOVUK.analyticsGa4.Ga4EcommerceTracker.init(true) | ||
GOVUK.analyticsGa4.Ga4EcommerceTracker.init() | ||
|
||
expect(window.dataLayer[0].search_results.ecommerce).toBe(null) | ||
}) | ||
|
@@ -263,29 +263,29 @@ describe('Google Analytics ecommerce tracking', function () { | |
var tracker = GOVUK.analyticsGa4.Ga4EcommerceTracker | ||
|
||
spyOn(tracker, 'handleClick') | ||
tracker.init(true) | ||
tracker.init() | ||
|
||
resultToBeClicked.click() | ||
expect(tracker.handleClick).toHaveBeenCalled() | ||
}) | ||
|
||
it('should push 1 search result to the dataLayer (i.e. the clicked search result)', function () { | ||
GOVUK.analyticsGa4.Ga4EcommerceTracker.init(true) | ||
GOVUK.analyticsGa4.Ga4EcommerceTracker.init() | ||
|
||
resultToBeClicked.click() | ||
expect(window.dataLayer[3].search_results.ecommerce.items.length).toBe(1) | ||
}) | ||
|
||
it('should add the event_data property to the object and set it appropriately', function () { | ||
GOVUK.analyticsGa4.Ga4EcommerceTracker.init(true) | ||
GOVUK.analyticsGa4.Ga4EcommerceTracker.init() | ||
|
||
resultToBeClicked.click() | ||
expect(window.dataLayer[3].event_data).not.toBe(null) | ||
expect(window.dataLayer[3].event_data.external).toBe(onSearchResultClickExpected.event_data.external) | ||
}) | ||
|
||
it('should set the remaining properties appropriately', function () { | ||
GOVUK.analyticsGa4.Ga4EcommerceTracker.init(true) | ||
GOVUK.analyticsGa4.Ga4EcommerceTracker.init() | ||
|
||
resultToBeClicked.click() | ||
expect(window.dataLayer[3].event).toBe(onSearchResultClickExpected.event) | ||
|
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