diff --git a/app/views/components/_filter_summary.html.erb b/app/views/components/_filter_summary.html.erb
index 6381bfeaf..57624bbf5 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] %>
diff --git a/spec/components/filter_summary_spec.rb b/spec/components/filter_summary_spec.rb
index a428813cb..272d89217 100644
--- a/spec/components/filter_summary_spec.rb
+++ b/spec/components/filter_summary_spec.rb
@@ -75,4 +75,21 @@ def render_component(locals)
assert_select "h4.app-c-filter-summary__heading", count: 1
end
+
+ it "renders ga4 tracking attributes to remove link" do
+ link_event_attributes = {
+ "event-name": "select_content",
+ type: "finder",
+ section: "Filter",
+ action: "remove"
+ }
+
+ render_component(filters:, data: link_event_attributes.to_json)
+
+ # doesnt work
+ # assert_select ".app-c-filter-summary__remove-filter[data-ga4-event='#{link_event_attributes.to_json}']"
+ # false positive as data can be anything and hence i guess is completely ignored
+ # assert_select ".app-c-filter-summary__remove-filter[data-ga4-event]", data: { "ga4-event": link_event_attributes.to_json }
+ # assert_select ".app-c-filter-summary__remove-filter[data-ga4-event]", data: { "ga4-event": "abc" }
+ end
end