Skip to content

Commit

Permalink
Don't render any meta tags when no trackable data
Browse files Browse the repository at this point in the history
  • Loading branch information
fofr committed Nov 10, 2015
1 parent e2f314e commit 1a19443
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
8 changes: 4 additions & 4 deletions app/views/govuk_component/analytics_meta_tags.raw.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@
organisations += links_hash[:lead_organisations] || []
organisations += links_hash[:supporting_organisations] || []
organisations += links_hash[:worldwide_organisations] || []
organisations_content = organisations.map{ |link| "<#{link[:analytics_identifier]}>" }.join
meta_tags["govuk:analytics:organisations"] = organisations_content if organisations_content
organisations_content = organisations.map { |link| "<#{link[:analytics_identifier]}>" }.join
meta_tags["govuk:analytics:organisations"] = organisations_content if organisations.any?

world_locations = links_hash[:world_locations] || []
world_locations_content = world_locations.map{ |link| "<#{link[:analytics_identifier]}>" }.join
meta_tags["govuk:analytics:world-locations"] = world_locations_content if world_locations_content
world_locations_content = world_locations.map { |link| "<#{link[:analytics_identifier]}>" }.join
meta_tags["govuk:analytics:world-locations"] = world_locations_content if world_locations.any?
%>
<% meta_tags.each do |name, content| %>
<meta name="<%= name %>" content="<%= content %>">
Expand Down
4 changes: 4 additions & 0 deletions test/govuk_component/analytics_meta_tags_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ def component_name
"analytics_meta_tags"
end

test "no meta tags are rendered when there's no trackable data" do
assert_empty render_component(content_item: {})
end

test "renders format in a meta tag" do
render_component(content_item: { format: "case_study" })
assert_meta_tag('govuk:format', 'case_study')
Expand Down

0 comments on commit 1a19443

Please sign in to comment.