Skip to content

Commit

Permalink
Merge pull request #3567 from alphagov/add-ga4-to-filter-links
Browse files Browse the repository at this point in the history
Add the GA4 link tracker to /world and /government/organisations links
  • Loading branch information
AshGDS authored Mar 20, 2024
2 parents 8e51ef4 + a15801f commit 5595445
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 2 deletions.
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

0 comments on commit 5595445

Please sign in to comment.