Skip to content

Commit

Permalink
Separate UA ecommerce enabler from GA4 ecommerce enabler
Browse files Browse the repository at this point in the history
The UA ecommerce tracking is disabled on three pages, as the object sent to UA exceeds the payload and was causing a JS error. Therefore UA ecommerce tracking was disabled on these pages in #2286. However we would like these pages enabled for GA4 ecommerce tracking while keeping the UA tracking disabled. Therefore, they have been separated out.

PR Change: remove include_ga4_ecommerce_tracking variable
  • Loading branch information
AshGDS committed Oct 3, 2023
1 parent 4d34184 commit cb4b1f7
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 cb4b1f7

Please sign in to comment.