diff --git a/app/controllers/content_items_controller.rb b/app/controllers/content_items_controller.rb index aecc60843..6fe6d0837 100644 --- a/app/controllers/content_items_controller.rb +++ b/app/controllers/content_items_controller.rb @@ -92,23 +92,42 @@ def load_taxonomy_navigation .map { |document_collection| document_collection.values_at('base_path', 'title') } # Fetch link attributes of parent step by steps required to render the top navigation banner - @banner_items = @content_item + step_by_step_links = @content_item .content_item .dig('links', 'part_of_step_navs') .yield_self { |part_of_step_navs| part_of_step_navs || [] } .sort_by { |step_by_step_nav| step_by_step_nav['title'] } .map { |step_by_step_nav| step_by_step_nav.values_at('title', 'base_path') } + @banner_items = format_banner_links(step_by_step_links, "Step by Step") # Append link attributes of parent taxons to our collections of items for the top navigation banner if the - # content item is tagged to more than one taxon. If their is only one taxon a breadcrumb will be used instead. + # content item is tagged to more than one taxon. If there is only one taxon a breadcrumb will be used instead. if taxons.many? - @banner_items += taxons + taxon_links = taxons .sort_by { |taxon| taxon[:taxon_name] } .map { |taxon| taxon.values_at('title', 'base_path') } + @banner_items += format_banner_links(taxon_links, "Taxon") end end end + def format_banner_links(links, type) + links.each.with_index(1).map do |(title, base_path), index| + view_context.link_to( + title, + base_path, + data: { + "track-category": "relatedTaxonomyLinkClicked", + "track-action": "1.#{index} #{type}", + "track-label": base_path, + "track-options": { + dimension29: title + } + } + ) + end + end + def content_item_template @content_item.schema_name end diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 6206c6b8e..d193c1649 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -60,23 +60,24 @@ <% end %> <% if @banner_items.present? %> - <% banner_links = @banner_items.map { |title, path| link_to title, path } %> -
+
<% if @banner_items.size <= 2 %> -

This page is part of <%= banner_links.take(2).to_sentence.html_safe %>

+

This page is part of <%= @banner_items.take(2).to_sentence.html_safe %>

<% else %> - <% featured_banner_link, *other_banner_links = banner_links %> -

- This page is part of <%= featured_banner_link %> - and <%= pluralize(other_banner_links.size, 'other') %> - + show all -

-

- <%= other_banner_links.to_sentence.html_safe %> -

+ <% featured_banner_link, *other_banner_links = @banner_items %> +
+

+ This page is part of <%= featured_banner_link %> + and <%= pluralize(other_banner_links.size, 'other') %> + + show all +

+

+ <%= other_banner_links.to_sentence.html_safe %> +

+
<% end %>
<% end %> diff --git a/app/views/shared/_taxonomy_navigation.html.erb b/app/views/shared/_taxonomy_navigation.html.erb index b2002267a..7c02b6eb1 100644 --- a/app/views/shared/_taxonomy_navigation.html.erb +++ b/app/views/shared/_taxonomy_navigation.html.erb @@ -3,13 +3,25 @@
<%= render "govuk_publishing_components/components/heading", - text: t('supergroups.topics'), - heading_level: 2, - font_size: 19 %> + text: t('supergroups.topics'), + heading_level: 2, + font_size: 19 + %>
    - <% tagged_taxons.each do |tagged_taxon| %> + <% tagged_taxons.each_with_index do |tagged_taxon, index| %>
  • - <%= link_to tagged_taxon[:taxon_name], tagged_taxon[:taxon_link] %> + <%= link_to( + tagged_taxon[:taxon_name], + tagged_taxon[:taxon_link], + data: { + "track-category": "relatedTaxonomyLinkClicked", + "track-action": "1.#{index} Topics", + "track-label": tagged_taxon[:taxon_link], + "track-options": { + dimension29: tagged_taxon[:taxon_name] + } + } + ) %>
  • <% end %>
@@ -22,9 +34,20 @@ heading_level: 2, font_size: 19 %>
    - <% related_collections.each do |base_path, title| %> + <% related_collections.each_with_index do |collection, index| %>
  • - <%= link_to title, base_path %> + <%= link_to( + collection[1], + collection[0], + data: { + "track-category": "relatedTaxonomyLinkClicked", + "track-action": "2.#{index} Collections", + "track-label": collection[0], + "track-options": { + dimension29: collection[1] + } + } + ) %>
  • <% end %>
diff --git a/test/integration/content_pages_navigation_test.rb b/test/integration/content_pages_navigation_test.rb index bdf4bb4b2..5e65ae77d 100644 --- a/test/integration/content_pages_navigation_test.rb +++ b/test/integration/content_pages_navigation_test.rb @@ -337,7 +337,20 @@ def setup end end - test "ContentPagesNav variant B shows home breadcrumb when a page belongs to a two topics and a step by step" do + test "ContentPagesNav variant B has tracking on banner links for single topic and a step by step" do + stub_rummager + setup_variant_b + + setup_and_visit_content_item_with_taxons('guide-with-step-navs', SINGLE_TAXON) + + within('.taxonomy-navigation__banner') do + assert page.has_css?('a[data-track-category="relatedTaxonomyLinkClicked"]', text: 'Learn to drive a car: step by step') + assert page.has_css?('a[data-track-action="1.1 Step by Step"]', text: 'Learn to drive a car: step by step') + assert page.has_css?('a[data-track-label="/learn-to-drive-a-car"]') + end + end + + test "ContentPagesNav variant B shows home breadcrumb when a page belongs to two topics and a step by step" do stub_rummager setup_variant_b @@ -365,6 +378,23 @@ def setup end end + test "ContentPagesNav variant B has tracking on banner links for two topics and a step by step" do + stub_rummager + setup_variant_b + + setup_and_visit_content_item_with_taxons('guide-with-step-navs', TWO_TAXONS) + + within('.taxonomy-navigation__banner') do + assert page.has_css?('a[data-track-category="relatedTaxonomyLinkClicked"]', text: 'Learn to drive a car: step by step') + assert page.has_css?('a[data-track-action="1.1 Step by Step"]', text: 'Learn to drive a car: step by step') + assert page.has_css?('a[data-track-label="/learn-to-drive-a-car"]') + + assert page.has_css?('a[data-track-category="relatedTaxonomyLinkClicked"]', text: 'Becoming an apprentice') + assert page.has_css?('a[data-track-action="1.1 Taxon"]', text: 'Becoming an apprentice') + assert page.has_css?('a[data-track-label="/education/becoming-an-apprentice"]') + end + end + test "ContentPagesNav variant B shows home breadcrumb when a page belongs to more than two topics and a step by step" do stub_rummager setup_variant_b diff --git a/test/integration/content_pages_related_navigation_test.rb b/test/integration/content_pages_related_navigation_test.rb index 3591b9fb8..4d9b063bf 100644 --- a/test/integration/content_pages_related_navigation_test.rb +++ b/test/integration/content_pages_related_navigation_test.rb @@ -16,6 +16,21 @@ def setup assert page.has_css?('.gem-c-related-navigation__sub-heading', text: 'Collection') end + test "ContentPagesNav variant B shows tagged taxons in the taxonomy navigation" do + stub_rummager + setup_variant_b + + setup_and_visit_content_item_with_taxons('case_study', SINGLE_TAXON) + + within '.taxonomy-navigation' do + assert page.has_css?('.gem-c-heading', text: 'Topics') + assert page.has_css?('.taxonomy-navigation__list-item a', text: 'Becoming an apprentice') + assert page.has_css?('.taxonomy-navigation__list-item a[data-track-category="relatedTaxonomyLinkClicked"]', text: 'Becoming an apprentice') + assert page.has_css?('.taxonomy-navigation__list-item a[data-track-action="1.0 Topics"]', text: 'Becoming an apprentice') + assert page.has_css?('.taxonomy-navigation__list-item a[data-track-label="/education/becoming-an-apprentice"]') + end + end + test "ContentPagesNav variant B shows related collections in the taxonomy navigation" do stub_rummager setup_variant_b @@ -24,6 +39,10 @@ def setup within '.taxonomy-navigation' do assert page.has_css?('.gem-c-heading', text: 'Collections') + assert page.has_css?('.taxonomy-navigation__list-item a', text: 'Work Programme real life stories') + assert page.has_css?('.taxonomy-navigation__list-item a[data-track-category="relatedTaxonomyLinkClicked"]', text: 'Work Programme real life stories') + assert page.has_css?('.taxonomy-navigation__list-item a[data-track-action="2.0 Collections"]', text: 'Work Programme real life stories') + assert page.has_css?('.taxonomy-navigation__list-item a[data-track-label="/government/collections/work-programme-real-life-stories"]') end end