Skip to content

Commit

Permalink
Merge pull request #3555 from alphagov/ga4-bug-fix
Browse files Browse the repository at this point in the history
Use replace() instead of replaceAll() in removeCrossDomainParams()
  • Loading branch information
AshGDS authored Aug 16, 2023
2 parents 57e12bb + 0d67095 commit 537a2fc
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
* Add GA4 tracking to the emergency banner ([PR #3549](https://github.com/alphagov/govuk_publishing_components/pull/3549))
* Ensure file attachments have the GA4 event_name 'file_download' ([PR #3553](https://github.com/alphagov/govuk_publishing_components/pull/3553))
* Add GA4 tracking to the phase banner ([PR #3552](https://github.com/alphagov/govuk_publishing_components/pull/3552))
* Use replace() instead of replaceAll() in removeCrossDomainParams() ([PR #3555](https://github.com/alphagov/govuk_publishing_components/pull/3555))

## 35.13.2

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,10 +169,10 @@ window.GOVUK.analyticsGa4 = window.GOVUK.analyticsGa4 || {};
removeCrossDomainParams: function (href) {
if (href.indexOf('_ga') !== -1 || href.indexOf('_gl') !== -1) {
// _ga & _gl are values needed for cross domain tracking, but we don't want them included in our click tracking.
href = href.replaceAll(/_g[al]=([^&]*)/g, '')
href = href.replace(/_g[al]=([^&]*)/g, '')

// The following code cleans up inconsistencies such as gov.uk/&&, gov.uk/?&hello=world, gov.uk/?, and gov.uk/&.
href = href.replaceAll(/(&&)+/g, '&')
href = href.replace(/(&&)+/g, '&')
href = href.replace('?&', '?')
if (this.stringEndsWith(href, '?') || this.stringEndsWith(href, '&')) {
href = href.substring(0, href.length - 1)
Expand Down

0 comments on commit 537a2fc

Please sign in to comment.