Skip to content

Commit

Permalink
Remove hardcoded primary click method attribute from button and link …
Browse files Browse the repository at this point in the history
…click events

There was a hardcoded "method" attribute which we unset, as we don't know whether it's actually a primary click or not. The link tracker from Publishing components already applies this attribute anyway, so no need for us to repeat it.
  • Loading branch information
ryanb-gds committed Dec 6, 2024
1 parent 19b38f9 commit 1c3a9f1
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ window.GOVUK.analyticsGa4.analyticsModules =
const event = {
event_name: 'navigation',
type: 'button',
text: button.textContent,
method: 'primary_click'
text: button.textContent
}
if (button.dataset.ga4Event) {
Object.assign(event, JSON.parse(button.dataset.ga4Event))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ window.GOVUK.analyticsGa4.analyticsModules =
links.forEach((link) => {
const event = {
event_name: 'navigation',
type: link.role === 'button' ? 'button' : 'generic_link',
method: 'primary_click'
type: link.role === 'button' ? 'button' : 'generic_link'
}
if (link.dataset.ga4Event) {
Object.assign(event, JSON.parse(link.dataset.ga4Event))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ describe('GOVUK.analyticsGa4.analyticsModules', function () {
ga4ButtonSetup.init()

expect(button.dataset.ga4Event).toEqual(
'{"event_name":"navigation","type":"button","text":"Button","method":"primary_click"}'
'{"event_name":"navigation","type":"button","text":"Button"}'
)
})

Expand All @@ -29,7 +29,7 @@ describe('GOVUK.analyticsGa4.analyticsModules', function () {
ga4ButtonSetup.init()

expect(button.dataset.ga4Event).toEqual(
'{"event_name":"navigation","type":"button","text":"Button","method":"primary_click"}'
'{"event_name":"navigation","type":"button","text":"Button"}'
)
})

Expand All @@ -42,7 +42,7 @@ describe('GOVUK.analyticsGa4.analyticsModules', function () {
ga4ButtonSetup.init()

expect(button.dataset.ga4Event).toEqual(
'{"event_name":"custom_event_name","type":"button","text":"Button","method":"primary_click"}'
'{"event_name":"custom_event_name","type":"button","text":"Button"}'
)
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ describe('GOVUK.analyticsGa4.analyticsModules.Ga4LinkSetup', function () {
Ga4LinkSetup.init()

expect(link.dataset.ga4Event).toEqual(
'{"event_name":"navigation","type":"generic_link","method":"primary_click"}'
'{"event_name":"navigation","type":"generic_link"}'
)
})

Expand All @@ -28,7 +28,7 @@ describe('GOVUK.analyticsGa4.analyticsModules.Ga4LinkSetup', function () {
Ga4LinkSetup.init()

expect(link.dataset.ga4Event).toEqual(
'{"event_name":"navigation","type":"button","method":"primary_click"}'
'{"event_name":"navigation","type":"button"}'
)
})
})

0 comments on commit 1c3a9f1

Please sign in to comment.