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. See https://github.com/alphagov/govuk_publishing_components/blob/2bf9077e3e091a2151feab56a715035e1883c689/app/assets/javascripts/govuk_publishing_components/analytics-ga4/ga4-link-tracker.js#L9

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 Dec 6, 2024
1 parent 1c3a9f1 commit 70d4c99
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 70d4c99

Please sign in to comment.