Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Track all links and buttons in Whitehall as per agreed event schema #9651

Merged
merged 6 commits into from
Dec 6, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix to link tracking setup
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
ryanb-gds committed Dec 6, 2024
commit 70d4c99a017fa4fbb33c35e851e27577638a6aeb
Original file line number Diff line number Diff line change
@@ -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) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Object.assign(event, JSON.parse(link.dataset.ga4Link))
}
link.dataset.ga4Event = JSON.stringify(event)
link.dataset.ga4Link = JSON.stringify(event)
})
})
}
Original file line number Diff line number Diff line change
@@ -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"}'
)
})
@@ -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"}'
)
})