Skip to content

Commit

Permalink
add ga4 tracking to clear all filters link
Browse files Browse the repository at this point in the history
  • Loading branch information
alexbowen committed Oct 2, 2024
1 parent f492f76 commit 8457c55
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
10 changes: 9 additions & 1 deletion app/views/components/_filter_summary.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,15 @@

<% if clear_all_text.present? && clear_all_href.present? %>
<div>
<%= 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 %>
</div>
<% end %>
<% end %>
Expand Down
18 changes: 17 additions & 1 deletion spec/components/filter_summary_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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

0 comments on commit 8457c55

Please sign in to comment.