Skip to content

Commit

Permalink
Fix bug where analytics tries to init in tests which don't import it
Browse files Browse the repository at this point in the history
  • Loading branch information
AshGDS committed Jan 13, 2023
1 parent fe640df commit 2205bcb
Showing 1 changed file with 8 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@ document.addEventListener('DOMContentLoaded', function () {
window.GOVUK.modules.start()

// if statements ensure these functions don't execute during testing
if (typeof window.GOVUK.analyticsGa4.vars === 'undefined') {
window.GOVUK.loadAnalytics.loadGa4()
}

if (typeof window.GOVUK.analyticsInit === 'undefined') {
window.GOVUK.loadAnalytics.loadUa()
if (typeof window.GOVUK.loadAnalytics !== 'undefined') {
window.GOVUK.analyticsGa4 = window.GOVUK.analyticsGa4 || {}
if (typeof window.GOVUK.analyticsGa4.vars === 'undefined') {
window.GOVUK.loadAnalytics.loadGa4()
}
if (typeof window.GOVUK.analyticsVars === 'undefined') {
window.GOVUK.loadAnalytics.loadUa()
}
}
})

0 comments on commit 2205bcb

Please sign in to comment.