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 654a2c1c394..50e38fe2cdc 100644 --- a/app/assets/javascripts/admin/analytics-modules/ga4-button-setup.js +++ b/app/assets/javascripts/admin/analytics-modules/ga4-button-setup.js @@ -10,15 +10,13 @@ window.GOVUK.analyticsGa4.analyticsModules = "[data-module~='ga4-button-setup']" ) moduleElements.forEach(function (moduleElement) { - const buttons = moduleElement.querySelectorAll( - 'button, [role="button"]' - ) + 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, - 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..54b224be64e 100644 --- a/app/assets/javascripts/admin/analytics-modules/ga4-link-setup.js +++ b/app/assets/javascripts/admin/analytics-modules/ga4-link-setup.js @@ -12,15 +12,18 @@ window.GOVUK.analyticsGa4.analyticsModules = moduleElements.forEach(function (moduleElement) { const links = moduleElement.querySelectorAll('a') links.forEach((link) => { + // Exclude links that serve as tab controls as they have their own event tracking + if (link.role === 'tab') { + return + } 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)) + if (link.dataset.ga4Link) { + Object.assign(event, JSON.parse(link.dataset.ga4Link)) } - link.dataset.ga4Event = JSON.stringify(event) + link.dataset.ga4Link = JSON.stringify(event) }) }) } diff --git a/app/components/admin/editions/show/sidebar_actions_component.html.erb b/app/components/admin/editions/show/sidebar_actions_component.html.erb index ccd49b2cd15..77e074c1b0d 100644 --- a/app/components/admin/editions/show/sidebar_actions_component.html.erb +++ b/app/components/admin/editions/show/sidebar_actions_component.html.erb @@ -1,4 +1,4 @@ -