From 1c3a9f1683cbcf603f984ce9127ff98cfbad2d7c Mon Sep 17 00:00:00 2001 From: Ryan Brown Date: Mon, 25 Nov 2024 16:20:18 +0000 Subject: [PATCH] Remove hardcoded primary click method attribute from button and link 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. --- .../javascripts/admin/analytics-modules/ga4-button-setup.js | 3 +-- .../javascripts/admin/analytics-modules/ga4-link-setup.js | 3 +-- .../admin/analytics-modules/ga4-button-setup.spec.js | 6 +++--- .../admin/analytics-modules/ga4-link-setup.spec.js | 4 ++-- 4 files changed, 7 insertions(+), 9 deletions(-) diff --git a/app/assets/javascripts/admin/analytics-modules/ga4-button-setup.js b/app/assets/javascripts/admin/analytics-modules/ga4-button-setup.js index 6369d25ea42..6e33a2baefc 100644 --- a/app/assets/javascripts/admin/analytics-modules/ga4-button-setup.js +++ b/app/assets/javascripts/admin/analytics-modules/ga4-button-setup.js @@ -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)) diff --git a/app/assets/javascripts/admin/analytics-modules/ga4-link-setup.js b/app/assets/javascripts/admin/analytics-modules/ga4-link-setup.js index 34f59ea044c..aa663904dd5 100644 --- a/app/assets/javascripts/admin/analytics-modules/ga4-link-setup.js +++ b/app/assets/javascripts/admin/analytics-modules/ga4-link-setup.js @@ -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)) diff --git a/spec/javascripts/admin/analytics-modules/ga4-button-setup.spec.js b/spec/javascripts/admin/analytics-modules/ga4-button-setup.spec.js index a3891991730..4fa0cac69ae 100644 --- a/spec/javascripts/admin/analytics-modules/ga4-button-setup.spec.js +++ b/spec/javascripts/admin/analytics-modules/ga4-button-setup.spec.js @@ -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"}' ) }) @@ -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"}' ) }) @@ -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"}' ) }) }) diff --git a/spec/javascripts/admin/analytics-modules/ga4-link-setup.spec.js b/spec/javascripts/admin/analytics-modules/ga4-link-setup.spec.js index 5980855374e..0b393661625 100644 --- a/spec/javascripts/admin/analytics-modules/ga4-link-setup.spec.js +++ b/spec/javascripts/admin/analytics-modules/ga4-link-setup.spec.js @@ -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"}' ) }) @@ -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"}' ) }) })