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 @@ -
+
<%= render "govuk_publishing_components/components/list", { extra_spacing: true, items: actions, diff --git a/app/helpers/admin/editions_helper.rb b/app/helpers/admin/editions_helper.rb index cbb09deef56..a36801997d5 100644 --- a/app/helpers/admin/editions_helper.rb +++ b/app/helpers/admin/editions_helper.rb @@ -93,7 +93,7 @@ def lead_organisation_id_at_index(edition, index) end def standard_edition_form(edition) - form_for form_url_for_edition(edition), as: :edition, html: { class: edition_form_classes(edition), multipart: true }, data: { module: "EditionForm LocaleSwitcher ga4-button-setup ga4-visual-editor-event-handlers", "rtl-locales": Locale.right_to_left.collect(&:to_param) } do |form| + form_for form_url_for_edition(edition), as: :edition, html: { class: edition_form_classes(edition), multipart: true }, data: { module: "EditionForm LocaleSwitcher ga4-visual-editor-event-handlers", "rtl-locales": Locale.right_to_left.collect(&:to_param) } do |form| concat render("standard_fields", form:, edition:) yield(form) concat render("settings_fields", form:, edition:) diff --git a/app/views/admin/attachments/_form.html.erb b/app/views/admin/attachments/_form.html.erb index c2b729eeb88..24265423e8b 100644 --- a/app/views/admin/attachments/_form.html.erb +++ b/app/views/admin/attachments/_form.html.erb @@ -1,4 +1,4 @@ -<%= form_for attachment, url: [:admin, typecast_for_attachable_routing(attachable), attachment.becomes(Attachment)], as: :attachment, html: { :class => "app-view-attachments__form", data: { module: "LocaleSwitcher ga4-button-setup ga4-visual-editor-event-handlers", "rtl-locales": Locale.right_to_left.collect(&:to_param) }}, multipart: true do |form| %> +<%= form_for attachment, url: [:admin, typecast_for_attachable_routing(attachable), attachment.becomes(Attachment)], as: :attachment, html: { :class => "app-view-attachments__form", data: { module: "LocaleSwitcher ga4-visual-editor-event-handlers", "rtl-locales": Locale.right_to_left.collect(&:to_param) }}, multipart: true do |form| %>
<%= render "govuk_publishing_components/components/input", { label: { diff --git a/app/views/admin/new_document/index.html.erb b/app/views/admin/new_document/index.html.erb index 408b712556e..e20fc4a6033 100644 --- a/app/views/admin/new_document/index.html.erb +++ b/app/views/admin/new_document/index.html.erb @@ -3,7 +3,7 @@
<%= form_with url: admin_new_document_options_path, data: { - module: "ga4-form-setup ga4-form-tracker ga4-link-setup ga4-link-tracker", + module: "ga4-form-setup ga4-form-tracker", } do %> <%= render "govuk_publishing_components/components/radio", { heading: "New document", diff --git a/app/views/layouts/design_system.html.erb b/app/views/layouts/design_system.html.erb index da186e223d6..4dd1c68a22f 100644 --- a/app/views/layouts/design_system.html.erb +++ b/app/views/layouts/design_system.html.erb @@ -22,7 +22,7 @@ <%= render partial: "shared/header" %> -
+
<%= render "shared/phase_banner", { show_feedback_banner: t("admin.feedback.show_banner"), } %> diff --git a/app/views/shared/_header.html.erb b/app/views/shared/_header.html.erb index 3d27fec7936..bf67fa8afcf 100644 --- a/app/views/shared/_header.html.erb +++ b/app/views/shared/_header.html.erb @@ -28,7 +28,7 @@ ], } %> -
+
<%= render "components/sub_navigation", { items: [ sub_nav_item("New document", admin_new_document_path), 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 089b68df76a..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","method":"primary_click"}' + '{"event_name":"select_content","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,21 +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"}' - ) - }) - - it('adds ga4 event data to nodes with the button role', function () { - const link = document.createElement('a') - link.textContent = 'Link' - link.role = 'button' - button.replaceWith(link) - - const ga4ButtonSetup = GOVUK.analyticsGa4.analyticsModules.Ga4ButtonSetup - ga4ButtonSetup.init() - - expect(link.dataset.ga4Event).toEqual( - '{"event_name":"navigation","type":"button","text":"Link","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..9146fb628af 100644 --- a/spec/javascripts/admin/analytics-modules/ga4-link-setup.spec.js +++ b/spec/javascripts/admin/analytics-modules/ga4-link-setup.spec.js @@ -16,8 +16,8 @@ describe('GOVUK.analyticsGa4.analyticsModules.Ga4LinkSetup', function () { const Ga4LinkSetup = GOVUK.analyticsGa4.analyticsModules.Ga4LinkSetup Ga4LinkSetup.init() - expect(link.dataset.ga4Event).toEqual( - '{"event_name":"navigation","type":"generic_link","method":"primary_click"}' + expect(link.dataset.ga4Link).toEqual( + '{"event_name":"navigation","type":"generic_link"}' ) }) @@ -27,8 +27,17 @@ describe('GOVUK.analyticsGa4.analyticsModules.Ga4LinkSetup', function () { const Ga4LinkSetup = GOVUK.analyticsGa4.analyticsModules.Ga4LinkSetup Ga4LinkSetup.init() - expect(link.dataset.ga4Event).toEqual( - '{"event_name":"navigation","type":"button","method":"primary_click"}' + expect(link.dataset.ga4Link).toEqual( + '{"event_name":"navigation","type":"button"}' ) }) + + it('excludes links that serve as tab controls', function () { + link.role = 'tab' + + const Ga4LinkSetup = GOVUK.analyticsGa4.analyticsModules.Ga4LinkSetup + Ga4LinkSetup.init() + + expect(link.dataset.ga4Link).toBeUndefined() + }) })