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 9744227b7..f52340c83 100644 --- a/app/views/govuk_component/analytics_meta_tags.raw.html.erb +++ b/app/views/govuk_component/analytics_meta_tags.raw.html.erb @@ -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| %> diff --git a/test/govuk_component/analytics_meta_tags_test.rb b/test/govuk_component/analytics_meta_tags_test.rb index 62139f2b1..7baf4d5b5 100644 --- a/test/govuk_component/analytics_meta_tags_test.rb +++ b/test/govuk_component/analytics_meta_tags_test.rb @@ -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')