Skip to content

Commit

Permalink
Merge pull request #9587 from alphagov/3121-update-parameters-for-but…
Browse files Browse the repository at this point in the history
…ton-tracking

GA4: Remove `section` parameter and `action` parameter from buttons
  • Loading branch information
dnkrj authored Nov 7, 2024
2 parents d0d57f9 + 11556df commit 4f23812
Show file tree
Hide file tree
Showing 8 changed files with 7 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ window.GOVUK.analyticsGa4.analyticsModules =
event_name: 'navigation',
type: 'button',
text: button.textContent,
section: document.title.split(' - ')[0].replace('Error: ', ''),
action: button.textContent,
method: 'primary_click'
}
if (button.dataset.ga4Event) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ window.GOVUK.analyticsGa4.analyticsModules =
)
moduleElement.dataset.ga4Form = JSON.stringify({
event_name: 'form_response',
section: document.title.split(' - ')[0].replace('Error: ', ''),
action: submitButton.textContent.toLowerCase()
})
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ window.GOVUK.analyticsGa4.analyticsModules =
const event = {
event_name: 'navigation',
type: link.role === 'button' ? 'button' : 'generic_link',
section: document.title.split(' - ')[0].replace('Error: ', ''),
method: 'primary_click'
}
if (link.dataset.ga4Event) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ window.GOVUK.analyticsGa4.analyticsModules =
event_name: 'select_content',
type: 'select',
text: selectText,
section: document.title.split(' - ')[0].replace('Error: ', ''),
action: selectText,
tool_name: 'Visual Editor'
}
}
Expand All @@ -22,8 +20,6 @@ window.GOVUK.analyticsGa4.analyticsModules =
text: buttonText,
external: 'false',
method: 'primary click',
section: document.title.split(' - ')[0].replace('Error: ', ''),
action: 'select',
tool_name: 'Visual Editor'
}
}
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","section":"Title","action":"Button","method":"primary_click"}'
'{"event_name":"navigation","type":"button","text":"Button","method":"primary_click"}'
)
})

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","section":"Title","action":"Button","method":"primary_click"}'
'{"event_name":"navigation","type":"button","text":"Button","method":"primary_click"}'
)
})

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","section":"Title","action":"Button","method":"primary_click"}'
'{"event_name":"custom_event_name","type":"button","text":"Button","method":"primary_click"}'
)
})

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

expect(link.dataset.ga4Event).toEqual(
'{"event_name":"navigation","type":"button","text":"Link","section":"Title","action":"Link","method":"primary_click"}'
'{"event_name":"navigation","type":"button","text":"Link","method":"primary_click"}'
)
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ describe('GOVUK.analyticsGa4.analyticsModules.Ga4FormSetup', function () {
Ga4FormSetup.init()

expect(container.dataset.ga4Form).toEqual(
'{"event_name":"form_response","section":"Title","action":"button"}'
'{"event_name":"form_response","action":"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","section":"Title","method":"primary_click"}'
'{"event_name":"navigation","type":"generic_link","method":"primary_click"}'
)
})

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

expect(link.dataset.ga4Event).toEqual(
'{"event_name":"navigation","type":"button","section":"Title","method":"primary_click"}'
'{"event_name":"navigation","type":"button","method":"primary_click"}'
)
})
})
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
describe('GOVUK.analyticsGa4.analyticsModules.Ga4VisualEditorEventHandlers', function () {
it('triggers ga4 tracking on visualEditorSelectChange event', function () {
document.title = 'Title - Text'
const container = document.createElement('div')
const select = document.createElement('select')
container.setAttribute('data-module', 'ga4-visual-editor-event-handlers')
Expand Down Expand Up @@ -28,8 +27,6 @@ describe('GOVUK.analyticsGa4.analyticsModules.Ga4VisualEditorEventHandlers', fun
event_name: 'select_content',
type: 'select',
text: 'DROPDOWN',
section: 'Title',
action: 'DROPDOWN',
tool_name: 'Visual Editor'
}

Expand All @@ -40,7 +37,6 @@ describe('GOVUK.analyticsGa4.analyticsModules.Ga4VisualEditorEventHandlers', fun
})

it('triggers ga4 tracking on visualEditorButtonClick event', function () {
document.title = 'Title - Text'
const container = document.createElement('div')
const button = document.createElement('button')
container.setAttribute('data-module', 'ga4-visual-editor-event-handlers')
Expand Down Expand Up @@ -70,8 +66,6 @@ describe('GOVUK.analyticsGa4.analyticsModules.Ga4VisualEditorEventHandlers', fun
text: 'BUTTON',
external: 'false',
method: 'primary click',
section: 'Title',
action: 'select',
tool_name: 'Visual Editor'
}

Expand Down

0 comments on commit 4f23812

Please sign in to comment.