diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js
index 06f6bb5bb..b9092959f 100644
--- a/app/assets/javascripts/application.js
+++ b/app/assets/javascripts/application.js
@@ -57,3 +57,20 @@ if ($allContentFinderTaxonomySelect) {
taxonomySelect.update()
})
}
+
+const allContentFinderForm = document.getElementById('all-content-finder-form')
+
+if (allContentFinderForm) {
+ allContentFinderForm.addEventListener('change', (event) => {
+ let ga4ChangeCategory = event.target.closest('[data-ga4-change-category]')
+ if (ga4ChangeCategory) {
+ ga4ChangeCategory = ga4ChangeCategory.getAttribute('data-ga4-change-category')
+
+ const consentCookie = GOVUK.getConsentCookie()
+
+ if (consentCookie && consentCookie.usage) {
+ GOVUK.analyticsGa4.Ga4FinderTracker.trackChangeEvent(event.target, ga4ChangeCategory)
+ }
+ }
+ })
+}
diff --git a/app/views/components/_filter_panel.html.erb b/app/views/components/_filter_panel.html.erb
index fe638a702..4087ee9f6 100644
--- a/app/views/components/_filter_panel.html.erb
+++ b/app/views/components/_filter_panel.html.erb
@@ -7,13 +7,14 @@
panel_content_id = "filter-panel-#{id_suffix}"
button_id = "filter-button-#{id_suffix}"
result_text ||= ""
+ section_count ||= ""
show_reset_link ||= false
raise ArgumentError, "reset_link_href is required" if show_reset_link && !local_assigns[:reset_link_href]
component_helper = GovukPublishingComponents::Presenters::ComponentWrapperHelper.new(local_assigns)
shared_helper = GovukPublishingComponents::Presenters::SharedHelper.new(local_assigns)
- component_helper.add_data_attribute({ module: "filter-panel" })
+ component_helper.add_data_attribute({ module: "filter-panel ga4-event-tracker" })
component_helper.add_class("app-c-filter-panel")
component_helper.add_class(shared_helper.get_margin_bottom) if local_assigns[:margin_bottom]
%>
@@ -23,7 +24,16 @@
<%= tag.button(
id: button_id,
class: "app-c-filter-panel__button govuk-link",
- aria: { expanded: "false", controls: panel_content_id }
+ aria: { expanded: "false", controls: panel_content_id },
+ "data-ga4-expandable": "",
+ "data-ga4-event": {
+ event_name: "select_content",
+ type: "finder",
+ section: button_text,
+ text: button_text,
+ index_section: 0,
+ index_section_count: section_count
+ }.to_json
) { button_text } %>
<% if result_text.present? %>
@@ -41,14 +51,32 @@
) do %>
<%= yield %>
+
- <%= submit_tag "Apply filters", class: "govuk-button app-c-filter-panel__action app-c-filter-panel__action--submit" %>
+ <%= submit_tag "Apply filters",
+ class: "govuk-button app-c-filter-panel__action app-c-filter-panel__action--submit",
+ "data-ga4-event" => {
+ event_name: "select_content",
+ type: "finder",
+ text: button_text,
+ section: button_text,
+ action: "search",
+ index_section: 0,
+ index_section_count: section_count,
+ }.to_json %>
<% if show_reset_link %>
<%=
link_to "Clear all filters",
reset_link_href,
- class: "govuk-link govuk-link--no-visited-state app-c-filter-panel__action app-c-filter-panel__action--reset"
+ class: "govuk-link govuk-link--no-visited-state app-c-filter-panel__action app-c-filter-panel__action--reset",
+ "data-ga4-event" => {
+ event_name: "select_content",
+ type: "finder",
+ text: button_text,
+ section: button_text,
+ action: "remove",
+ }.to_json
%>
<% end %>
diff --git a/app/views/components/_filter_section.html.erb b/app/views/components/_filter_section.html.erb
index f90d39ec5..334b3ac21 100644
--- a/app/views/components/_filter_section.html.erb
+++ b/app/views/components/_filter_section.html.erb
@@ -7,14 +7,29 @@
visually_hidden_heading_prefix ||= ""
heading_level ||= 2
summary_aria_attributes ||= {}
+ index_section ||= 0
+ index_section_count ||= 0
+ change_category ||= nil
component_helper = GovukPublishingComponents::Presenters::ComponentWrapperHelper.new(local_assigns)
+ component_helper.add_data_attribute({ module: "filter-section" })
+ component_helper.add_data_attribute({ "ga4-section": heading_text, "ga4-filter-parent": heading_text })
+ component_helper.add_data_attribute("ga4-change-category": change_category)
component_helper.add_class("app-c-filter-section")
component_helper.set_open(open)
%>
<%= tag.details(**component_helper.all_attributes) do %>
- <%= tag.summary class: "app-c-filter-section__summary", aria: summary_aria_attributes do %>
+ <%= tag.summary class: "app-c-filter-section__summary", aria: summary_aria_attributes,
+ "data-ga4-expandable": "",
+ "data-ga4-event" => {
+ event_name: "select_content",
+ type: "finder",
+ section: heading_text,
+ text: heading_text,
+ index_section: index_section,
+ index_section_count: index_section_count,
+ }.to_json do %>
<%= content_tag("h#{heading_level}", class: "app-c-filter-section__summary-heading") do %>
<% if visually_hidden_heading_prefix.present? %>
<%= visually_hidden_heading_prefix %>
diff --git a/app/views/components/_filter_summary.html.erb b/app/views/components/_filter_summary.html.erb
index 6381bfeaf..6883c0ec5 100644
--- a/app/views/components/_filter_summary.html.erb
+++ b/app/views/components/_filter_summary.html.erb
@@ -11,6 +11,7 @@
component_helper = GovukPublishingComponents::Presenters::ComponentWrapperHelper.new(local_assigns)
component_helper.add_class(shared_helper.get_margin_bottom) if local_assigns[:margin_bottom]
+ component_helper.add_data_attribute({ module: "ga4-event-tracker" })
component_helper.add_class("app-c-filter-summary")
%>
@@ -25,7 +26,14 @@
<% filters.each do |filter| %>
-
- <%= link_to filter[:remove_href], class: "app-c-filter-summary__remove-filter" do %>
+ <%= link_to filter[:remove_href],
+ class: "app-c-filter-summary__remove-filter",
+ "data-ga4-event" => {
+ event_name: "select_content",
+ type: "finder",
+ section: filter[:label],
+ action: "remove"
+ }.to_json do %>
<%= filter[:visually_hidden_prefix] %>
<%= filter[:label] %>: <%= filter[:value] %>
@@ -37,7 +45,15 @@
<% if clear_all_text.present? && clear_all_href.present? %>
- <%= link_to clear_all_text, clear_all_href, class: "app-c-filter-summary__clear-filters govuk-link govuk-link--no-visited-state" %>
+ <%= link_to clear_all_text, clear_all_href,
+ class: "app-c-filter-summary__clear-filters govuk-link govuk-link--no-visited-state",
+ "data-ga4-event" => {
+ event_name: "select_content",
+ type: "finder",
+ text: clear_all_text,
+ section: heading_text,
+ action: "remove"
+ }.to_json %>
<% end %>
<% end %>
diff --git a/app/views/finders/all_content_finder_facets/_date_facet.html.erb b/app/views/finders/all_content_finder_facets/_date_facet.html.erb
index 92ffa9ecd..e4f58af49 100644
--- a/app/views/finders/all_content_finder_facets/_date_facet.html.erb
+++ b/app/views/finders/all_content_finder_facets/_date_facet.html.erb
@@ -6,7 +6,9 @@
index_section: index,
index_section_count: count,
# Note date is the only validated facet, so if there is an error, it'll be here
- open: @search_query.invalid?
+ open: @search_query.invalid?,
+ data_attributes: { "ga4-index": { index_section: index + 1, index_section_count: count } },
+ change_category: "update-filter text",
} do %>
<%= render "govuk_publishing_components/components/input", {
label: {
diff --git a/app/views/finders/all_content_finder_facets/_option_select_facet.html.erb b/app/views/finders/all_content_finder_facets/_option_select_facet.html.erb
index f65a7ab22..13c48d125 100644
--- a/app/views/finders/all_content_finder_facets/_option_select_facet.html.erb
+++ b/app/views/finders/all_content_finder_facets/_option_select_facet.html.erb
@@ -7,6 +7,8 @@
id: "facet_option_select_#{option_select_facet.key}",
index_section: index,
index_section_count: count,
+ data_attributes: { "ga4-index": { index_section: index + 1, index_section_count: count } },
+ change_category: "update-filter checkbox",
} do %>
<%= render "govuk_publishing_components/components/checkboxes", {
name: "#{option_select_facet.key}[]",
diff --git a/app/views/finders/all_content_finder_facets/_sort_facet.html.erb b/app/views/finders/all_content_finder_facets/_sort_facet.html.erb
index 252895b74..81a86f1a9 100644
--- a/app/views/finders/all_content_finder_facets/_sort_facet.html.erb
+++ b/app/views/finders/all_content_finder_facets/_sort_facet.html.erb
@@ -4,6 +4,8 @@
id: "facet_sort",
index_section: index,
index_section_count: count,
+ data_attributes: { "ga4-index": { index_section: index + 1, index_section_count: count } },
+ change_category: "update-filter radio",
} do %>
<%= render "govuk_publishing_components/components/radio", {
heading: "Sort order",
diff --git a/app/views/finders/all_content_finder_facets/_taxon_facet.html.erb b/app/views/finders/all_content_finder_facets/_taxon_facet.html.erb
index 39443bd5f..868f14436 100644
--- a/app/views/finders/all_content_finder_facets/_taxon_facet.html.erb
+++ b/app/views/finders/all_content_finder_facets/_taxon_facet.html.erb
@@ -5,8 +5,10 @@
id: "facet_taxon_#{taxon_facet.key}",
index_section: index,
index_section_count: count,
+ data_attributes: { "ga4-index": { index_section: index + 1, index_section_count: count } },
+ change_category: "update-filter select",
+ classes: "js-all-content-finder-taxonomy-select"
} do %>
-
<%= render "govuk_publishing_components/components/select", {
id: 'level_one_taxon',
label: "Topic",
@@ -22,5 +24,4 @@
options: taxon_facet.sub_topics
} %>
-
<% end %>
diff --git a/app/views/finders/show_all_content_finder.html.erb b/app/views/finders/show_all_content_finder.html.erb
index 71122f569..b92627359 100644
--- a/app/views/finders/show_all_content_finder.html.erb
+++ b/app/views/finders/show_all_content_finder.html.erb
@@ -13,7 +13,7 @@
<% end %>
<% content_for :meta_title, content_item.title %>
-