diff --git a/app/assets/javascripts/admin/analytics-modules/ga4-link-setup.js b/app/assets/javascripts/admin/analytics-modules/ga4-link-setup.js index 5c6923c2c24..54b224be64e 100644 --- a/app/assets/javascripts/admin/analytics-modules/ga4-link-setup.js +++ b/app/assets/javascripts/admin/analytics-modules/ga4-link-setup.js @@ -12,6 +12,10 @@ window.GOVUK.analyticsGa4.analyticsModules = moduleElements.forEach(function (moduleElement) { const links = moduleElement.querySelectorAll('a') links.forEach((link) => { + // Exclude links that serve as tab controls as they have their own event tracking + if (link.role === 'tab') { + return + } const event = { event_name: 'navigation', type: link.role === 'button' ? 'button' : 'generic_link' diff --git a/spec/javascripts/admin/analytics-modules/ga4-link-setup.spec.js b/spec/javascripts/admin/analytics-modules/ga4-link-setup.spec.js index 10fd0377777..9146fb628af 100644 --- a/spec/javascripts/admin/analytics-modules/ga4-link-setup.spec.js +++ b/spec/javascripts/admin/analytics-modules/ga4-link-setup.spec.js @@ -31,4 +31,13 @@ describe('GOVUK.analyticsGa4.analyticsModules.Ga4LinkSetup', function () { '{"event_name":"navigation","type":"button"}' ) }) + + it('excludes links that serve as tab controls', function () { + link.role = 'tab' + + const Ga4LinkSetup = GOVUK.analyticsGa4.analyticsModules.Ga4LinkSetup + Ga4LinkSetup.init() + + expect(link.dataset.ga4Link).toBeUndefined() + }) })