Skip to content

Commit

Permalink
Add custom dimension 111 to page views
Browse files Browse the repository at this point in the history
Store the brexit audience type in custom dimension 111.
  • Loading branch information
hannako committed Jul 5, 2021
1 parent d5b5c65 commit 8ccbe1d
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
'taxon-ids': { dimension: 59, defaultValue: 'other' },
'content-has-history': { dimension: 39, defaultValue: 'false' },
'publishing-application': { dimension: 89 },
'brexit-audience': { dimension: 111 },
stepnavs: { dimension: 96 },
'relevant-result-shown': { dimension: 83 },
'spelling-suggestion': { dimension: 81 }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ def priority_taxons
return [] unless content_item["links"].is_a?(Hash)

taxons = content_item.dig("links", "taxons")

taxon_tree(taxons).select do |taxon|
priority_taxon?(taxon)
end
Expand Down
24 changes: 23 additions & 1 deletion lib/govuk_publishing_components/presenters/meta_tags.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ def meta_tags
meta_tags = add_organisation_tags(meta_tags)
meta_tags = add_political_tags(meta_tags)
meta_tags = add_taxonomy_tags(meta_tags)
add_step_by_step_tags(meta_tags)
meta_tags = add_step_by_step_tags(meta_tags)
add_brexit_tags(meta_tags)
end

private
Expand Down Expand Up @@ -111,6 +112,27 @@ def add_step_by_step_tags(meta_tags)
meta_tags
end

def add_brexit_tags(meta_tags)
links = content_item[:links]
taxons = links[:taxons] unless links.nil?

return meta_tags if taxons.blank?
return meta_tags unless tagged_to_priority_taxon?

audience = priority_taxon_helper.brexit_audience
meta_tags["govuk:brexit-audience"] = audience if audience.present?

meta_tags
end

def tagged_to_priority_taxon?
priority_taxon_helper.taxon.present?
end

def priority_taxon_helper
@priority_taxon_helper ||= ContentBreadcrumbsBasedOnPriority.new(content_item.deep_stringify_keys, request.query_parameters)
end

def has_content_history?
(content_item[:public_updated_at] && details[:first_public_at] && content_item[:public_updated_at] != details[:first_public_at]) ||
(details[:change_history] && details[:change_history].size > 1)
Expand Down
29 changes: 29 additions & 0 deletions spec/components/meta_tags_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ def example_document_for(schema_name, example_name)
},
}
render_component(content_item: example_document_for("case_study", "case_study").merge(content_item))

assert_meta_tag("govuk:themes", "root-taxon")
end

Expand Down Expand Up @@ -330,6 +331,34 @@ def example_document_for(schema_name, example_name)
assert_select "meta[name='govuk:taxon-ids']", 0
end

it "renders the brexit audience metatag for content items tagged to brexit" do
content_item = {
links: {
taxons: [
{
title: "Brexit: business guidance",
content_id: "634fd193-8039-4a70-a059-919c34ff4bfc",
base_path: "/brexit/business-guidance",
document_type: "detailed_guide",
links: {
parent_taxons: [
{
title: "Brexit",
content_id: "d6c2de5d-ef90-45d1-82d4-5f2438369eea",
base_path: "/brexit",
document_type: "taxon",
},
],
},
},
],
},
}

render_component(content_item: example_document_for("detailed_guide", "detailed_guide").merge(content_item))
assert_meta_tag("govuk:brexit-audience", "Brexitbusiness")
end

it "renders the has-content-history tag as true when the content has history" do
content_item = {
public_updated_at: Time.parse("2017-01-01"),
Expand Down

0 comments on commit 8ccbe1d

Please sign in to comment.