From 01b40b13c80d15757acf156bca40d04cf8cf51b6 Mon Sep 17 00:00:00 2001 From: Ryan Brown Date: Fri, 6 Dec 2024 13:33:16 +0000 Subject: [PATCH] Use 'select_content' event name for buttons which don't trigger a form 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 --- .../javascripts/admin/analytics-modules/ga4-button-setup.js | 3 ++- .../admin/analytics-modules/ga4-button-setup.spec.js | 2 +- 2 files changed, 3 insertions(+), 2 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 6e33a2baefc..50e38fe2cdc 100644 --- a/app/assets/javascripts/admin/analytics-modules/ga4-button-setup.js +++ b/app/assets/javascripts/admin/analytics-modules/ga4-button-setup.js @@ -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 } 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 4fa0cac69ae..69ba26e4eb3 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"}' + '{"event_name":"select_content","type":"button","text":"Button"}' ) })