Skip to content

Commit

Permalink
Omit links with tab aria role from link tracking
Browse files Browse the repository at this point in the history
Tabs have their own tracking built in to the component from the govuk_publishing_components gem. No need for us to duplicate it.
  • Loading branch information
ryanb-gds committed Dec 6, 2024
1 parent 01b40b1 commit 283d512
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
})
})

0 comments on commit 283d512

Please sign in to comment.