From 0c30d9cd2ae13b476e93f410824577e620c7ac5d Mon Sep 17 00:00:00 2001 From: Alec Gibson Date: Mon, 8 May 2017 14:53:19 +0100 Subject: [PATCH] Add Navigation Tracking Metatags shim In order to remove the navigation analytics meta tags, we need to do two stages: 1. Remove all references to the meta tags (ie in taxonomy sidebar and related items) 2. Remove the component itself This is because Static/Slimmer will have a cached set of sidebar components that will continue trying to use the old meta tags. Hence we need to leave the meta tags in place, and then remove them after the cache has cleared. --- .../analytics_meta_tags.raw.html.erb | 2 ++ .../analytics_meta_tags_navigation.raw.html.erb | 9 +++++++++ .../docs/analytics_meta_tags_navigation.yml | 10 ++++++++++ .../analytics_meta_tags_navigation_test.rb | 13 +++++++++++++ test/govuk_component/analytics_meta_tags_test.rb | 6 +++--- 5 files changed, 37 insertions(+), 3 deletions(-) create mode 100644 app/views/govuk_component/analytics_meta_tags_navigation.raw.html.erb create mode 100644 app/views/govuk_component/docs/analytics_meta_tags_navigation.yml create mode 100644 test/govuk_component/analytics_meta_tags_navigation_test.rb diff --git a/app/views/govuk_component/analytics_meta_tags.raw.html.erb b/app/views/govuk_component/analytics_meta_tags.raw.html.erb index 07eb51490..784c726b5 100644 --- a/app/views/govuk_component/analytics_meta_tags.raw.html.erb +++ b/app/views/govuk_component/analytics_meta_tags.raw.html.erb @@ -81,3 +81,5 @@ <% meta_tags.each do |name, content| %> <% end %> + +<%= yield :analytics_meta_tags %> diff --git a/app/views/govuk_component/analytics_meta_tags_navigation.raw.html.erb b/app/views/govuk_component/analytics_meta_tags_navigation.raw.html.erb new file mode 100644 index 000000000..0579a8031 --- /dev/null +++ b/app/views/govuk_component/analytics_meta_tags_navigation.raw.html.erb @@ -0,0 +1,9 @@ +<% + number_of_sections ||= 0 + number_of_links ||= 0 +%> + +<% content_for :analytics_meta_tags do %> + + +<% end %> diff --git a/app/views/govuk_component/docs/analytics_meta_tags_navigation.yml b/app/views/govuk_component/docs/analytics_meta_tags_navigation.yml new file mode 100644 index 000000000..b4f884335 --- /dev/null +++ b/app/views/govuk_component/docs/analytics_meta_tags_navigation.yml @@ -0,0 +1,10 @@ +name: Analytics Meta Tags +description: Meta tags to provide analytics information about the current page +body: | + A component that appends counts for navigation elements to the analytics_meta_tags component. + + The code which reads the meta tags can be found in static-analytics.js. +fixtures: + default: + number_of_sections: 2 + number_of_links: 6 diff --git a/test/govuk_component/analytics_meta_tags_navigation_test.rb b/test/govuk_component/analytics_meta_tags_navigation_test.rb new file mode 100644 index 000000000..fb1c42189 --- /dev/null +++ b/test/govuk_component/analytics_meta_tags_navigation_test.rb @@ -0,0 +1,13 @@ +require 'govuk_component_test_helper' + +class AnalyticsMetaTagsNavigationTestCase < ComponentTestCase + def component_name + "analytics_meta_tags_navigation" + end + + test "no error if no parameters passed in" do + assert_nothing_raised do + render_component({}) + end + end +end diff --git a/test/govuk_component/analytics_meta_tags_test.rb b/test/govuk_component/analytics_meta_tags_test.rb index 6b5da7aa2..81be9bbe5 100644 --- a/test/govuk_component/analytics_meta_tags_test.rb +++ b/test/govuk_component/analytics_meta_tags_test.rb @@ -19,7 +19,7 @@ def example_document_for(format, example_name) end test "no meta tags are rendered when there's no trackable data" do - assert_empty render_component(content_item: {}) + assert_empty render_component(content_item: {}).strip end test "renders format in a meta tag" do @@ -85,8 +85,8 @@ def example_document_for(format, example_name) end test "does not render publishing government or political status when political or government is missing" do - assert_empty render_component(content_item: { details: { government: { current: true, slug: 'government' } } }) - assert_empty render_component(content_item: { details: { political: true } }) + assert_empty render_component(content_item: { details: { government: { current: true, slug: 'government' } } }).strip + assert_empty render_component(content_item: { details: { political: true } }).strip end test "renders user journey stage when user journey supertype is included" do