Skip to content

Commit

Permalink
Merge pull request #3174 from alphagov/ga4-ecommerce-missing-path
Browse files Browse the repository at this point in the history
Separate UA ecommerce tracking enabler from GA4 ecommerce tracking enabler
  • Loading branch information
AshGDS authored Oct 3, 2023
2 parents 1df4213 + cb4b1f7 commit e1b5b23
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
14 changes: 10 additions & 4 deletions app/presenters/search_result_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def document_list_component_data
text: title,
path: link,
description: sanitize(summary_text),
data_attributes: ecommerce_data(link, title),
data_attributes: ga4_ecommerce_data(link).merge(ecommerce_data(link, title)),
},
metadata: structure_metadata,
metadata_raw: metadata,
Expand Down Expand Up @@ -80,23 +80,29 @@ def structure_parts
GovukError.notify(MalformedPartError.new, extra: { part:, link: })
next
end
path = "#{link}/#{part[:slug]}"
{
link: {
text: part[:title],
path: "#{link}/#{part[:slug]}",
path:,
description: part[:body],
data_attributes: ecommerce_data("#{link}/#{part[:slug]}", part[:title], part_index: index),
data_attributes: ga4_ecommerce_data(path).merge(ecommerce_data(path, part[:title], part_index: index)),
},
}
end
structured_parts.compact
end

def ga4_ecommerce_data(path)
{
ga4_ecommerce_path: path,
}
end

def ecommerce_data(link, title, part_index: nil)
return {} unless @include_ecommerce

{
ga4_ecommerce_path: link,
ecommerce_path: link,
ecommerce_row: 1,
ecommerce_index: document.index,
Expand Down
8 changes: 5 additions & 3 deletions spec/presenters/result_set_presenter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@
end
end

context "with ecommerce disabled" do
context "with universal analytics ecommerce disabled" do
let(:enable_ecommerce) { false }
let(:results) do
[FactoryBot.build(
Expand All @@ -195,13 +195,15 @@
)]
end

it "doesn't include ecommerce attributes" do
it "doesn't include UA ecommerce attributes" do
expected_hash = {
link: {
text: "document_title",
path: "/path/to/doc",
description: "document_description",
data_attributes: {},
data_attributes: {
ga4_ecommerce_path: "/path/to/doc",
},
},
metadata: {
"Organisations" => "Organisations: Department for Work and Pensions",
Expand Down

0 comments on commit e1b5b23

Please sign in to comment.