Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the GA4 link tracker to /world and /government/organisations links #3567

Merged
merged 1 commit into from
Mar 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion app/views/organisations/_organisations_list.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@
</div>

<div class="govuk-grid-column-two-thirds <%= "organisations-list__without-number" if @presented_organisations.executive_office?(organisation_type) %>">
<ol>
<ol
data-module="ga4-link-tracker"
data-ga4-track-links-only
data-ga4-link="<%= { event_name: "navigation", type: "filter" }.to_json %>">
<% organisations.each do |organisation| %>
<%= content_tag :li, {
class: "organisations-list__item",
Expand Down
6 changes: 5 additions & 1 deletion app/views/world/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,11 @@
</div>

<div class="govuk-grid-column-two-thirds">
<ol class="world-locations-groups">
<ol
class="world-locations-groups"
data-module="ga4-link-tracker"
data-ga4-track-links-only
data-ga4-link="<%= { event_name: "navigation", type: "filter" }.to_json %>">
<% @presented_index.grouped_world_locations.each do |letter, locations| %>
<div class="world-locations-group" data-filter="inner-block">
<h3 class="world-locations-group__letter"><%= letter %></h3>
Expand Down
10 changes: 10 additions & 0 deletions spec/features/content_store_organisations_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,16 @@
expect(page.has_css?("#toggle_attorney-general-s-office a[href='/government/organisations/hm-crown-prosecution-service-inspectorate']", text: "HM Crown Prosecution Service Inspectorate", visible: false)).to be(true)
end

scenario "renders links with GA4 tracking" do
ga4_module = "ol[data-module=ga4-link-tracker]"
expect(page).to have_css(ga4_module)
expect(page).to have_css("ol[data-ga4-track-links-only]")

ga4_link_data = JSON.parse(page.first(ga4_module)["data-ga4-link"])
expect(ga4_link_data["event_name"]).to eq "navigation"
expect(ga4_link_data["type"]).to eq "filter"
end

private

def organisations_content_hash
Expand Down
10 changes: 10 additions & 0 deletions spec/features/world_index_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,14 @@
expect(page).to have_link("The UK Permanent Delegation to the OECD (Organisation for Economic Co-operation and Development)", href: "/world/the-uk-permanent-delegation-to-the-oecd-organisation-for-economic-co-operation-and-development")
end
end

scenario "renders links with GA4 tracking" do
ga4_module = "ol[data-module=ga4-link-tracker]"
expect(page).to have_css(ga4_module)
expect(page).to have_css("ol[data-ga4-track-links-only]")

ga4_link_data = JSON.parse(page.first(ga4_module)["data-ga4-link"])
expect(ga4_link_data["event_name"]).to eq "navigation"
expect(ga4_link_data["type"]).to eq "filter"
end
end
Loading