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 54b224be64e..c04b3a9d01f 100644 --- a/app/assets/javascripts/admin/analytics-modules/ga4-link-setup.js +++ b/app/assets/javascripts/admin/analytics-modules/ga4-link-setup.js @@ -13,7 +13,10 @@ window.GOVUK.analyticsGa4.analyticsModules = 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') { + // It would be preferable to use the role ARIA attribute to do this, but it's not present yet + // when this module is initialised because the tabs component adds the role. + // Component modules are initialised after analytics modules by GOV.UK Publishing components + if (link.classList.contains('govuk-tabs__tab')) { return } const event = { 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 9146fb628af..3a7faeec4e1 100644 --- a/spec/javascripts/admin/analytics-modules/ga4-link-setup.spec.js +++ b/spec/javascripts/admin/analytics-modules/ga4-link-setup.spec.js @@ -33,7 +33,7 @@ describe('GOVUK.analyticsGa4.analyticsModules.Ga4LinkSetup', function () { }) it('excludes links that serve as tab controls', function () { - link.role = 'tab' + link.classList.add('govuk-tabs__tab') const Ga4LinkSetup = GOVUK.analyticsGa4.analyticsModules.Ga4LinkSetup Ga4LinkSetup.init()