Skip to content

Commit

Permalink
Merge pull request #389 from alphagov/revert-attachment-change
Browse files Browse the repository at this point in the history
Revert "Add GA4 indexes to attachments that render a details component"
  • Loading branch information
AshGDS authored Mar 6, 2025
2 parents 2529272 + 863842f commit 510b875
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 39 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 10.2.0

* Revert 'Add GA4 indexes to attachments that render a details component' ([#389](https://github.com/alphagov/govspeak/pull/389))

## 10.1.0

* Allow acronyms/abbreviations in steps ([#387](https://github.com/alphagov/govspeak/pull/387)).
Expand Down
11 changes: 0 additions & 11 deletions lib/govspeak/post_processor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,6 @@ def self.extension(title, &block)
end

extension("embed attachment HTML") do |document|
# Attachments with details components need indexes set for GA4 tracking purposes
details_attachments = govspeak_document.attachments.select { |attachment| attachment[:alternative_format_contact_email] }
details_attachments_size = details_attachments.size
details_attachment_index = 0

document.css("govspeak-embed-attachment").map do |el|
attachment = govspeak_document.attachments.detect { |a| a[:id] == el["id"] }

Expand All @@ -70,17 +65,11 @@ def self.extension(title, &block)
next
end

if attachment[:alternative_format_contact_email]
details_attachment_index += 1
details_ga4_attributes = { index_section: details_attachment_index, index_section_count: details_attachments_size }
end

attachment_html = GovukPublishingComponents.render(
"govuk_publishing_components/components/attachment",
attachment:,
margin_bottom: 6,
locale: govspeak_document.locale,
details_ga4_attributes:,
)
el.swap(attachment_html)
end
Expand Down
28 changes: 0 additions & 28 deletions test/govspeak_attachment_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,32 +52,4 @@ def render_govspeak(govspeak, attachments = [])
assert html_has_selector?(rendered, "section.gem-c-attachment")
assert_match(/<p>some more text<\/p>/, rendered)
end

test "renders attachments with details elements with the correct GA4 index" do
attachments = []

(1..3).each do |index|
attachments << {
id: "attachment#{index}.ods",
url: "http://example.com/attachment#{index}",
title: "Attachment Title #{index}",
alternative_format_contact_email: "example@gov.uk",
}
end

# Insert an attachment without a details element, to ensure our code to increment the index ignores these
attachments.insert(1, {
id: "attachment.pdf",
url: "http://example.com/attachment.pdf",
title: "Attachment Title",
})

rendered = render_govspeak("[Attachment:attachment1.ods]\n[Attachment:attachment.pdf]\n[Attachment:attachment2.ods]\n[Attachment:attachment3.ods]", attachments)
node = Nokogiri::HTML(rendered)
node.css(".gem-c-details").each_with_index.map do |details, index|
ga4_event = JSON.parse(details.attribute("data-ga4-event"))
assert_equal ga4_event["index_section"], index + 1
assert_equal ga4_event["index_section_count"], 3
end
end
end

0 comments on commit 510b875

Please sign in to comment.