Skip to content

Commit

Permalink
Fix to link tracking setup
Browse files Browse the repository at this point in the history
Link tracking should use the ga4-link data attribute instead of the ga4-event data attribute.
This will allow us to mix the attributes in to the GA4 link tracking module events provided by GOV.UK Publishing Components
  • Loading branch information
ryanb-gds committed Nov 26, 2024
1 parent 9cacb45 commit 41241bb
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ window.GOVUK.analyticsGa4.analyticsModules =
event_name: 'navigation',
type: link.role === 'button' ? 'button' : 'generic_link'
}
if (link.dataset.ga4Event) {
Object.assign(event, JSON.parse(link.dataset.ga4Event))
if (link.dataset.ga4Link) {
Object.assign(event, JSON.parse(link.dataset.ga4Link))
}
link.dataset.ga4Event = JSON.stringify(event)
link.dataset.ga4Link = JSON.stringify(event)
})
})
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ describe('GOVUK.analyticsGa4.analyticsModules.Ga4LinkSetup', function () {
const Ga4LinkSetup = GOVUK.analyticsGa4.analyticsModules.Ga4LinkSetup
Ga4LinkSetup.init()

expect(link.dataset.ga4Event).toEqual(
expect(link.dataset.ga4Link).toEqual(
'{"event_name":"navigation","type":"generic_link"}'
)
})
Expand All @@ -27,7 +27,7 @@ describe('GOVUK.analyticsGa4.analyticsModules.Ga4LinkSetup', function () {
const Ga4LinkSetup = GOVUK.analyticsGa4.analyticsModules.Ga4LinkSetup
Ga4LinkSetup.init()

expect(link.dataset.ga4Event).toEqual(
expect(link.dataset.ga4Link).toEqual(
'{"event_name":"navigation","type":"button"}'
)
})
Expand Down

0 comments on commit 41241bb

Please sign in to comment.