Skip to content

Commit

Permalink
Use replace() instead of replaceAll()
Browse files Browse the repository at this point in the history
replaceAll() is not supported in IE11. Instead you can use replace() as long as you have a global regex pattern, which we already have in this case.
  • Loading branch information
AshGDS committed Aug 16, 2023
1 parent 57e12bb commit 0d67095
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 0d67095

Please sign in to comment.