Skip to content

Commit

Permalink
Extract ga4_section onto facet subclasses
Browse files Browse the repository at this point in the history
- credit to @floehopper
  • Loading branch information
andysellick committed Nov 29, 2023
1 parent 521a9ea commit aafc003
Show file tree
Hide file tree
Showing 11 changed files with 32 additions and 4 deletions.
4 changes: 4 additions & 0 deletions app/models/date_facet.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ def query_params
{ key => date_values }
end

def ga4_section
name
end

private

def value_fragments
Expand Down
4 changes: 4 additions & 0 deletions app/models/facet.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ def query_params
{}
end

def ga4_section
nil
end

private

def and_word_connectors
Expand Down
4 changes: 4 additions & 0 deletions app/models/option_select_facet.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ def closed_on_load_mobile?
open_on_load?
end

def ga4_section
name
end

private

def value_fragments
Expand Down
4 changes: 4 additions & 0 deletions app/models/radio_facet.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ def query_params
{ key => selected_value["value"] }
end

def ga4_section
""
end

private

def selected_value
Expand Down
4 changes: 4 additions & 0 deletions app/models/radio_facet_for_multiple_filters.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ def allowed_values
@filter_hashes
end

def ga4_section
""
end

private

attr_reader :filter_hashes
Expand Down
4 changes: 4 additions & 0 deletions app/models/taxon_facet.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ def query_params
}
end

def ga4_section
"Topic"
end

private

def value_fragments
Expand Down
4 changes: 4 additions & 0 deletions app/models/topical_facet.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,8 @@ def allowed_values
def to_partial_path
"option_select_facet"
end

def ga4_section
name
end
end
2 changes: 1 addition & 1 deletion app/views/finders/_date_facet.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
aria_controls_id: "js-search-results-info",
date_errors_to: date_facet.error_message_to(@search_query),
date_errors_from: date_facet.error_message_from(@search_query),
data_attributes: { "ga4-filter-parent": date_facet.name }
data_attributes: { "ga4-filter-parent": date_facet.ga4_section }
} %>
</span>
2 changes: 1 addition & 1 deletion app/views/finders/_option_select_facet.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<% add_gem_component_stylesheet("checkboxes") %>
<% cache_if option_select_facet.cacheable?, option_select_facet.cache_key do %>
<%= tag.div(data: { "ga4-change-category": "update-filter checkbox", "ga4-filter-parent": "", "ga4-section": option_select_facet.name }) do %>
<%= tag.div(data: { "ga4-change-category": "update-filter checkbox", "ga4-filter-parent": "", "ga4-section": option_select_facet.ga4_section }) do %>
<%= render partial: 'govuk_publishing_components/components/option_select', locals: {
:key => option_select_facet.key,
:title => option_select_facet.name,
Expand Down
2 changes: 1 addition & 1 deletion app/views/finders/_radio_facet.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<%= tag.div(class: "facet-container", data: { "ga4-change-category": "update-filter radio", "ga4-section": "", "ga4-filter-parent": "" }) do %>
<%= tag.div(class: "facet-container", data: { "ga4-change-category": "update-filter radio", "ga4-section": "", "ga4-filter-parent": radio_facet.ga4_section }) do %>
<%= render "govuk_publishing_components/components/radio", {
name: radio_facet.key,
small: true,
Expand Down
2 changes: 1 addition & 1 deletion app/views/finders/_taxon_facet.html.erb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<% unless i_am_a_topic_page_finder %>
<%= render "components/expander", {
title: "Topic",
data_attributes: { "ga4-filter-parent": "Topic" }
data_attributes: { "ga4-filter-parent": taxon_facet.ga4_section }
} do %>
<div class="js-taxonomy-select" data-ga4-change-category="update-filter select" data-ga4-section="Topic">
<%= render "govuk_publishing_components/components/select", {
Expand Down

0 comments on commit aafc003

Please sign in to comment.