-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #983 from alphagov/add-services-ab-2
Setup Content Pages Taxonomy Navigation AB Test (with services)
- Loading branch information
Showing
21 changed files
with
570 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
.taxonomy-navigation { | ||
border-top: 2px solid $govuk-blue; | ||
padding-top: $gutter-half; | ||
} | ||
|
||
.taxonomy-navigation__title-link { | ||
@include bold-24; | ||
display: block; | ||
} | ||
|
||
.taxonomy-navigation__section { | ||
padding: $gutter-one-third 0 $gutter-two-thirds 0; | ||
margin-top: $gutter-half; | ||
border-top: 1px solid $grey-2; | ||
} | ||
|
||
.taxonomy-navigation__section:first-of-type { | ||
border-top: 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
module ContentPagesNavAbTestable | ||
CUSTOM_DIMENSION = 65 | ||
|
||
def self.included(base) | ||
base.helper_method( | ||
:content_pages_nav_test_variant, | ||
:show_new_navigation?, | ||
:page_in_scope? | ||
) | ||
base.after_action :set_test_response_header | ||
end | ||
|
||
def content_pages_nav_test | ||
@content_pages_nav_test ||= GovukAbTesting::AbTest.new( | ||
"ContentPagesNav", | ||
dimension: CUSTOM_DIMENSION, | ||
allowed_variants: %w(A B), | ||
control_variant: "A" | ||
) | ||
end | ||
|
||
def content_pages_nav_test_variant | ||
@content_pages_nav_test_variant ||= content_pages_nav_test.requested_variant(request.headers) | ||
end | ||
|
||
def set_test_response_header | ||
content_pages_nav_test_variant.configure_response(response) if page_in_scope? | ||
end | ||
|
||
def show_new_navigation? | ||
content_pages_nav_test_variant.variant?("B") && page_in_scope? | ||
end | ||
|
||
def page_in_scope? | ||
# Pages are in scope if: | ||
# - They are not an out-of-scope format, e.g: html publications | ||
# - They are tagged to the taxonomy | ||
if @content_item | ||
not_an_html_publication? && has_a_live_taxon? | ||
end | ||
end | ||
|
||
def not_an_html_publication? | ||
!@content_item.document_type.eql?("html_publication") | ||
end | ||
|
||
def has_a_live_taxon? | ||
@content_item.taxons.present? && | ||
@content_item.taxons.detect { |taxon| taxon["phase"] == "live" } | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
module Supergroups | ||
class Services | ||
attr_reader :content | ||
|
||
def initialize(taxon_ids) | ||
@taxon_ids = taxon_ids | ||
end | ||
|
||
def tagged_content | ||
@content = MostPopularContent.fetch(content_ids: @taxon_ids, filter_content_purpose_supergroup: "services") | ||
format_document_data(@content) | ||
end | ||
|
||
private | ||
|
||
def format_document_data(documents) | ||
documents&.map do |document| | ||
data = { | ||
link: { | ||
text: document["title"], | ||
path: document["link"] | ||
} | ||
} | ||
|
||
data | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
require 'gds_api/rummager' | ||
|
||
class MostPopularContent | ||
include RummagerFields | ||
|
||
attr_reader :content_ids, :filter_content_purpose_supergroup, :number_of_links | ||
|
||
def initialize(content_ids:, filter_content_purpose_supergroup:, number_of_links: 5) | ||
@content_ids = content_ids | ||
@filter_content_purpose_supergroup = filter_content_purpose_supergroup | ||
@number_of_links = number_of_links | ||
end | ||
|
||
def self.fetch(content_ids:, filter_content_purpose_supergroup:) | ||
new(content_ids: content_ids, filter_content_purpose_supergroup: filter_content_purpose_supergroup).fetch | ||
end | ||
|
||
def fetch | ||
search_response["results"] | ||
end | ||
|
||
private | ||
|
||
def search_response | ||
params = { | ||
start: 0, | ||
count: number_of_links, | ||
fields: RummagerFields::TAXON_SEARCH_FIELDS, | ||
filter_part_of_taxonomy_tree: content_ids, | ||
order: '-popularity', | ||
} | ||
params[:filter_content_purpose_supergroup] = filter_content_purpose_supergroup if filter_content_purpose_supergroup.present? | ||
|
||
search_result(params) | ||
end | ||
|
||
def search_result(params) | ||
Services.rummager.search(params) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
module RummagerFields | ||
TAXON_SEARCH_FIELDS = %w(title | ||
link | ||
description | ||
content_store_document_type | ||
public_timestamp | ||
organisations).freeze | ||
|
||
FEED_SEARCH_FIELDS = %w(title | ||
link | ||
description | ||
display_type | ||
public_timestamp).freeze | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<% if taxonomy_navigation.values().flatten.any? %> | ||
<div class="taxonomy-navigation"> | ||
<h2>More in | ||
<% tagged_taxons.each do |tagged_taxon| %> | ||
<a class="taxonomy-navigation__title-link" href="<%= tagged_taxon[:taxon_link] %>"><%= tagged_taxon[:taxon_name] %></a> | ||
<% end %> | ||
</h2> | ||
|
||
<% if taxonomy_navigation[:services].any? %> | ||
<div class="taxonomy-navigation__section"> | ||
<%= render "govuk_publishing_components/components/heading", { | ||
text: t('supergroups.services'), | ||
heading_level: 3, | ||
font_size: 24, | ||
margin_bottom: 2 | ||
} %> | ||
|
||
<%= render "govuk_publishing_components/components/highlight_boxes", { | ||
inverse: true, | ||
items: taxonomy_navigation[:services] | ||
} %> | ||
</div> | ||
<% end %> | ||
</div> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.