diff --git a/CHANGELOG.md b/CHANGELOG.md index 7839cf12f2..a4722d9064 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ useful summary for people upgrading their application, not a replication of the commit log. +## Unreleased + +* Add /media/ path to GA4 download link tracking ([PR #4491](https://github.com/alphagov/govuk_publishing_components/pull/4491/)) + ## 46.3.0 * Remove min-width from share links flexbox variant list-items ([PR #4488](https://github.com/alphagov/govuk_publishing_components/pull/4488)) diff --git a/app/assets/javascripts/govuk_publishing_components/analytics-ga4/ga4-specialist-link-tracker.js b/app/assets/javascripts/govuk_publishing_components/analytics-ga4/ga4-specialist-link-tracker.js index 468fbeaf67..91af955062 100644 --- a/app/assets/javascripts/govuk_publishing_components/analytics-ga4/ga4-specialist-link-tracker.js +++ b/app/assets/javascripts/govuk_publishing_components/analytics-ga4/ga4-specialist-link-tracker.js @@ -9,7 +9,7 @@ window.GOVUK.analyticsGa4.analyticsModules = window.GOVUK.analyticsGa4.analytics init: function (config) { if (window.dataLayer) { config = config || {} - this.internalDownloadPaths = config.internalDownloadPaths || ['/government/uploads/'] + this.internalDownloadPaths = config.internalDownloadPaths || ['/government/uploads/', '/media/'] this.dedicatedDownloadDomains = config.dedicatedDownloadDomains || ['assets.publishing.service.gov.uk'] window.GOVUK.analyticsGa4.core.trackFunctions.appendDomainsWithoutWWW(this.dedicatedDownloadDomains) this.handleClick = this.handleClick.bind(this) diff --git a/spec/javascripts/govuk_publishing_components/analytics-ga4/ga4-specialist-link-tracker.spec.js b/spec/javascripts/govuk_publishing_components/analytics-ga4/ga4-specialist-link-tracker.spec.js index 9e8865885c..7d49e6dc7f 100644 --- a/spec/javascripts/govuk_publishing_components/analytics-ga4/ga4-specialist-link-tracker.spec.js +++ b/spec/javascripts/govuk_publishing_components/analytics-ga4/ga4-specialist-link-tracker.spec.js @@ -371,10 +371,12 @@ describe('A specialist link tracker', function () { '' + '' body.appendChild(links) @@ -509,7 +511,7 @@ describe('A specialist link tracker', function () { it('detects preview clicks on gov.uk download preview links', function () { var linksToTest = document.querySelectorAll('.preview-download-links a') - + var external = ['true', 'true', 'false'] for (var i = 0; i < linksToTest.length; i++) { window.dataLayer = [] var link = linksToTest[i] @@ -518,7 +520,7 @@ describe('A specialist link tracker', function () { expected.event_data.url = link.getAttribute('href') expected.event_data.type = 'preview' expected.event_data.text = link.innerText.trim() - expected.event_data.external = 'true' + expected.event_data.external = external[i] expect(window.dataLayer[0]).toEqual(expected) } @@ -526,7 +528,7 @@ describe('A specialist link tracker', function () { it('detects files with preview in their filename as download links instead of preview links', function () { var linksToTest = document.querySelectorAll('.not-a-preview-link a') - + var external = ['true', 'true', 'false'] for (var i = 0; i < linksToTest.length; i++) { window.dataLayer = [] var link = linksToTest[i] @@ -535,7 +537,7 @@ describe('A specialist link tracker', function () { expected.event_data.url = link.getAttribute('href') expected.event_data.type = 'generic download' expected.event_data.text = link.innerText.trim() - expected.event_data.external = 'true' + expected.event_data.external = external[i] expect(window.dataLayer[0]).toEqual(expected) }