Skip to content

Commit

Permalink
Add ga4 link tracking to topic lists on services and information pages
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesCGDS committed Jun 30, 2023
1 parent 4425df6 commit 4382bf2
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 3 deletions.
2 changes: 1 addition & 1 deletion app/views/services_and_information/_grouped_links.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<%
list_item_count = group.see_more_link ? group.examples.count + 1 : group.examples.count
tracking_attributes = topic_list_tracking_attributes(list_item_count, group_index, 'navServicesInformationLinkClicked')
topic_list_component_params = topic_list_params(group.examples, tracking_attributes: tracking_attributes)
topic_list_component_params = topic_list_params(group.examples, list_index: group_index, tracking_attributes: tracking_attributes, list_count: grouped_links.count, list_title: group.title)

if group.see_more_link
link = group.see_more_link.clone
Expand Down
2 changes: 1 addition & 1 deletion app/views/services_and_information/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@
} %>
</header>

<div class="browse-container full-width" data-module="gem-track-click">
<div class="browse-container full-width" data-module="gem-track-click ga4-link-tracker">
<%= render partial: 'grouped_links', locals: { grouped_links: grouped_links } %>
</div>
34 changes: 33 additions & 1 deletion spec/features/services_and_information_browsing_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
scenario "includes tracking attributes on all links" do
visit "/government/organisations/hm-revenue-customs/services-information"

expect(page).to have_selector('.browse-container[data-module="gem-track-click"]')
expect(page).to have_selector('.browse-container[data-module="gem-track-click ga4-link-tracker"]')

within ".govuk-grid-row:first-child .app-c-topic-list" do
content_item_link = page.first("li a")
Expand Down Expand Up @@ -70,4 +70,36 @@
expect(data_options["dimension29"]).to eq(content_item_link.text)
end
end

scenario "includes GA4 tracking attributes on all links" do
visit "/government/organisations/hm-revenue-customs/services-information"

expect(page).to have_selector('.browse-container[data-module="gem-track-click ga4-link-tracker"]')

within ".govuk-grid-row:first-child .app-c-topic-list" do
content_item_link = page.first("li a")
ga4_data = JSON.parse(content_item_link["data-ga4-link"])

expect(ga4_data["event_name"]).to eq "navigation"
expect(ga4_data["type"]).to eq "document list"
expect(ga4_data["index"]["index_link"]).to eq 1
expect(ga4_data["index"]["index_section"]).to eq 1
expect(ga4_data["index"]["index_section_count"]).to eq 2
expect(ga4_data["index_total"]).to eq 5
expect(ga4_data["section"]).to eq "Environmental permits"
end

within ".govuk-grid-row:nth-child(2) .app-c-topic-list" do
content_item_link = page.first("li a")
ga4_data = JSON.parse(content_item_link["data-ga4-link"])

expect(ga4_data["event_name"]).to eq "navigation"
expect(ga4_data["type"]).to eq "document list"
expect(ga4_data["index"]["index_link"]).to eq 1
expect(ga4_data["index"]["index_section"]).to eq 2
expect(ga4_data["index"]["index_section_count"]).to eq 2
expect(ga4_data["index_total"]).to eq 5
expect(ga4_data["section"]).to eq "Waste"
end
end
end

0 comments on commit 4382bf2

Please sign in to comment.