Skip to content

Commit

Permalink
Merge pull request #1032 from alphagov/add-tracking-shim
Browse files Browse the repository at this point in the history
Add Navigation Tracking Metatags shim
  • Loading branch information
carvil authored May 8, 2017
2 parents 66901f3 + 0c30d9c commit 576465c
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 3 deletions.
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

0 comments on commit 576465c

Please sign in to comment.