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 Navigation Tracking Metatags shim #1032

Merged
merged 1 commit into from
May 8, 2017
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
2 changes: 2 additions & 0 deletions app/views/govuk_component/analytics_meta_tags.raw.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,5 @@
<% meta_tags.each do |name, content| %>
<meta name="<%= name %>" content="<%= content %>">
<% end %>

<%= yield :analytics_meta_tags %>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<%
number_of_sections ||= 0
number_of_links ||= 0
%>

<% content_for :analytics_meta_tags do %>
<meta name="govuk:navigation-sections" content="<%= number_of_sections %>">
<meta name="govuk:navigation-links" content="<%= number_of_links %>">
<% end %>
10 changes: 10 additions & 0 deletions app/views/govuk_component/docs/analytics_meta_tags_navigation.yml
Original file line number Diff line number Diff line change
@@ -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 <a href="https://github.com/alphagov/static/blob/master/app/assets/javascripts/analytics/static-analytics.js#L76-L96">in static-analytics.js</a>.
fixtures:
default:
number_of_sections: 2
number_of_links: 6
13 changes: 13 additions & 0 deletions test/govuk_component/analytics_meta_tags_navigation_test.rb
Original file line number Diff line number Diff line change
@@ -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
6 changes: 3 additions & 3 deletions test/govuk_component/analytics_meta_tags_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down