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 custom dimension to segment page views by Brexit audience type #2186

Merged
merged 5 commits into from
Jul 5, 2021
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
## Unreleased

* Update LUX to activate when usage cookies are accepted ([PR #2154](https://github.com/alphagov/govuk_publishing_components/pull/2154)) PATCH
* Add custom dimension to the page view data for pages with the Brexit superbreadcrumb. And remove the CD from superbreadcrumb clicks.

## 24.18.0

Expand Down
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 @@ -39,7 +39,16 @@ def breadcrumbs
tracking_category: "breadcrumbClicked",
tracking_action: tracking_action,
tracking_label: content_item["base_path"],
}.merge(custom_dimension_tracking)
tracking_dimension_enabled: false,
}
end

def brexit_audience
{
PRIORITY_TAXONS[:brexit_business] => "Brexitbusiness",
PRIORITY_TAXONS[:brexit_individuals] => "Brexitcitizen",
PRIORITY_TAXONS[:brexit_taxon] => "Brexitbusinessandcitizen",
}[taxon["content_id"]]
end

private
Expand Down Expand Up @@ -79,38 +88,16 @@ def brexit_child_taxons
[PRIORITY_TAXONS[:brexit_business], PRIORITY_TAXONS[:brexit_individuals]]
end

def brexit_taxons
brexit_child_taxons << PRIORITY_TAXONS[:brexit_taxon]
end

def preferred_priority_taxon
query_parameters["priority-taxon"] if query_parameters
end

def tracking_action
action = %w[superBreadcrumb]
action << page_name_for_tracking
action << brexit_audience
action.compact.join(" ")
end

def custom_dimension_tracking
tracking = { tracking_dimension_enabled: false }
if brexit_taxons.include?(taxon["content_id"])
tracking[:tracking_dimension_enabled] = true
tracking[:tracking_dimension] = page_name_for_tracking
tracking[:tracking_dimension_index] = 111
end
tracking
end

def page_name_for_tracking
{
PRIORITY_TAXONS[:brexit_business] => "Brexitbusiness",
PRIORITY_TAXONS[:brexit_individuals] => "Brexitcitizen",
PRIORITY_TAXONS[:brexit_taxon] => "Brexitbusinessandcitizen",
}[taxon["content_id"]]
end

def tagged_to_both_brexit_child_taxons?
t = priority_taxons.select { |taxon| brexit_child_taxon?(taxon) }
t.uniq.count > 1
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
28 changes: 28 additions & 0 deletions spec/components/meta_tags_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,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
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,9 @@
context "with brexit taxon" do
let(:payload) { [brexit_taxon] }

it "returns the worker taxon" do
it "returns the brexit taxon" do
expect(subject.taxon).to eq(brexit_taxon)
expect(subject.brexit_audience).to eq("Brexitbusinessandcitizen")
end
end

Expand All @@ -109,11 +110,12 @@
end
end

context "with brexit_taxon taxon and brexit_individuals taxon" do
context "with brexit_taxon and brexit_individuals taxon" do
let(:payload) { [brexit_taxon, brexit_individuals_taxon] }

it "returns the brexit_individuals taxon" do
expect(subject.taxon).to eq(brexit_individuals_taxon)
expect(subject.brexit_audience).to eq("Brexitcitizen")
end
end

Expand All @@ -122,6 +124,7 @@

it "returns the brexit_business taxon" do
expect(subject.taxon).to eq(brexit_business_taxon)
expect(subject.brexit_audience).to eq("Brexitbusiness")
end
end

Expand All @@ -130,6 +133,7 @@

it "returns the brexit_taxon taxon" do
expect(subject.taxon).to eq(brexit_taxon)
expect(subject.brexit_audience).to eq("Brexitbusinessandcitizen")
end
end

Expand Down Expand Up @@ -183,21 +187,6 @@
expect(described_class.call(content)).to eq(breadcrumbs)
end
end

context "when page is tagged to a brexit taxon" do
let(:content) { send(tagged_to_taxons, [brexit_individuals_taxon]) }

it "adds custom dimension tracking" do
breadcrumbs = breadcrumb_for(content, brexit_individuals_taxon)

breadcrumbs[:path] = "/guidance/brexit-guidance-for-individuals"
breadcrumbs[:tracking_action] = "superBreadcrumb Brexitcitizen"
breadcrumbs[:tracking_dimension] = "Brexitcitizen"
breadcrumbs[:tracking_dimension_enabled] = true
breadcrumbs[:tracking_dimension_index] = 111
expect(described_class.call(content)).to eq(breadcrumbs)
end
end
end
end
end
Expand Down