From 8457c55dd1149aa0acd4b84a95f0a9199124e0e4 Mon Sep 17 00:00:00 2001 From: alexbowen Date: Wed, 2 Oct 2024 15:46:10 +0100 Subject: [PATCH] add ga4 tracking to clear all filters link --- app/views/components/_filter_summary.html.erb | 10 +++++++++- spec/components/filter_summary_spec.rb | 18 +++++++++++++++++- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/app/views/components/_filter_summary.html.erb b/app/views/components/_filter_summary.html.erb index 57624bbf5..1185e5115 100644 --- a/app/views/components/_filter_summary.html.erb +++ b/app/views/components/_filter_summary.html.erb @@ -45,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: "Selected filters and sorting", + action: "remove" + }.to_json %>
<% end %> <% end %> diff --git a/spec/components/filter_summary_spec.rb b/spec/components/filter_summary_spec.rb index f996ed2f9..4908d5583 100644 --- a/spec/components/filter_summary_spec.rb +++ b/spec/components/filter_summary_spec.rb @@ -76,7 +76,7 @@ def render_component(locals) assert_select "h4.app-c-filter-summary__heading", count: 1 end - it "renders ga4 tracking attributes to remove link" do + it "renders ga4 tracking attributes to remove links" do link_event_attributes = { event_name: "select_content", type: "finder", @@ -88,4 +88,20 @@ def render_component(locals) assert_select ".app-c-filter-summary__remove-filter[data-ga4-event='#{link_event_attributes.to_json}']" end + + it "renders ga4 tracking attributes to clear all link" do + clear_all_text = "Clear all the things" + clear_all_href = "#" + link_event_attributes = { + event_name: "select_content", + type: "finder", + text: clear_all_text, + section: "Selected filters and sorting", + action: "remove", + } + + render_component(clear_all_text:, clear_all_href:, filters:, data: link_event_attributes.to_json) + + assert_select ".app-c-filter-summary__clear-filters[data-ga4-event='#{link_event_attributes.to_json}']" + end end