Skip to content

Commit

Permalink
Add GA4 accordion tracking to manual section
Browse files Browse the repository at this point in the history
  • Loading branch information
gclssvglx committed Aug 16, 2022
1 parent d4ee83c commit 3f631ae
Showing 1 changed file with 28 additions and 3 deletions.
31 changes: 28 additions & 3 deletions app/views/content_items/manual_section.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -49,20 +49,45 @@
</div>
<% end %>
<% else %>
<%= render "govuk_publishing_components/components/accordion", {
anchor_navigation: true,
items: @content_item.main.map do |item|
<%
items = @content_item.main.each.with_index(1).map do |item, index|
rendered_content = render "govuk_publishing_components/components/govspeak", {} do
raw(item[:content])
end

{
data_attributes: {
module: "gtm-track-click",
ga4: {
event_name: "select_content",
type: "accordion",
text: item[:heading],
index: index,
index_total: @content_item.main.length,
}
},
heading: item[:heading],
content: {
html: rendered_content,
},
}
end
%>

<%
ga4_attributes = {
event_name: "select_content",
type: "accordion",
index: 0,
index_total: @content_item.main.length,
}
%>
<%= render "govuk_publishing_components/components/accordion", {
data_attributes_show_all: {
"ga4": ga4_attributes.to_json
},
anchor_navigation: true,
items: items,
} %>
<% end %>
<% end %>
Expand Down

0 comments on commit 3f631ae

Please sign in to comment.