From a15801f454e18046ce2b36ea33c11a015afe1698 Mon Sep 17 00:00:00 2001 From: AshGDS <8880610+AshGDS@users.noreply.github.com> Date: Mon, 18 Mar 2024 15:53:54 +0000 Subject: [PATCH] Add the GA4 link tracker to /world and /government/organisations links --- app/views/organisations/_organisations_list.html.erb | 5 ++++- app/views/world/index.html.erb | 6 +++++- spec/features/content_store_organisations_spec.rb | 10 ++++++++++ spec/features/world_index_spec.rb | 10 ++++++++++ 4 files changed, 29 insertions(+), 2 deletions(-) diff --git a/app/views/organisations/_organisations_list.html.erb b/app/views/organisations/_organisations_list.html.erb index 195e2a9e7..c13c84738 100644 --- a/app/views/organisations/_organisations_list.html.erb +++ b/app/views/organisations/_organisations_list.html.erb @@ -22,7 +22,10 @@
"> -
    +
      "> <% organisations.each do |organisation| %> <%= content_tag :li, { class: "organisations-list__item", diff --git a/app/views/world/index.html.erb b/app/views/world/index.html.erb index 139d491af..9180e2a64 100644 --- a/app/views/world/index.html.erb +++ b/app/views/world/index.html.erb @@ -45,7 +45,11 @@
-
    +
      "> <% @presented_index.grouped_world_locations.each do |letter, locations| %>

      <%= letter %>

      diff --git a/spec/features/content_store_organisations_spec.rb b/spec/features/content_store_organisations_spec.rb index a372f9de2..a58f41331 100644 --- a/spec/features/content_store_organisations_spec.rb +++ b/spec/features/content_store_organisations_spec.rb @@ -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 diff --git a/spec/features/world_index_spec.rb b/spec/features/world_index_spec.rb index 26ed6eae0..da06d5513 100644 --- a/spec/features/world_index_spec.rb +++ b/spec/features/world_index_spec.rb @@ -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