Skip to content

Commit

Permalink
Use 'select_content' event name for buttons which don't trigger a for…
Browse files Browse the repository at this point in the history
…m submission

It doesn't make sense to track a "navigation" event for such buttons, as there is no form submission to trigger a page navigation
  • Loading branch information
ryanb-gds committed Dec 6, 2024
1 parent 6b00ce8 commit 01b40b1
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ window.GOVUK.analyticsGa4.analyticsModules =
const buttons = moduleElement.querySelectorAll('button')
buttons.forEach((button) => {
const event = {
event_name: 'navigation',
event_name:
button.type === 'submit' ? 'navigation' : 'select_content',
type: 'button',
text: button.textContent
}
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"}'
'{"event_name":"select_content","type":"button","text":"Button"}'
)
})

Expand Down

0 comments on commit 01b40b1

Please sign in to comment.