Skip to content

Commit

Permalink
Merge pull request #850 from alphagov/contextual-comms-abc-test
Browse files Browse the repository at this point in the history
Add Contextual comms A/B/C test
  • Loading branch information
emmabeynon authored Mar 29, 2018
2 parents aeb9a68 + 570621a commit 0831526
Show file tree
Hide file tree
Showing 11 changed files with 425 additions and 0 deletions.
43 changes: 43 additions & 0 deletions app/assets/stylesheets/components/_blue-box-campaign.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
.app-c-native-blue-box-campaign__container {
border-top: 1px solid $border-colour;
padding-top: 20px;
}

.app-c-native-blue-box-campaign__link {
@include bold-24;
position: relative;
display: block;
background: $govuk-blue;
width: 100%;
min-height: 280px;
color: $white;
text-decoration: none;
text-align: left;
box-sizing: border-box;
padding: 15px;
}

.app-c-native-blue-box-campaign__title {
display: block;
color: $white;
font-weight: bold;

&:hover {
text-decoration: underline;
}
}

.app-c-native-blue-box-campaign__description {
@include core-19;
display: block;
font-weight: normal;
padding: 10px 10px 10px 0;
color: $white;
position: absolute;
bottom: 10px;
}

.app-c-native-blue-box-campaign__link:focus .app-c-native-blue-box-campaign__title,
.app-c-native-blue-box-campaign__link:focus .app-c-native-blue-box-campaign__description {
color: $black;
}
31 changes: 31 additions & 0 deletions app/assets/stylesheets/components/_native-campaign.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
$dark-grey: #999;

.app-c-native-campaign__container {
border-top: 1px solid $border-colour;
padding-top: 20px;
}

.app-c-native-campaign__header {
@include core-14;
color: $dark-grey;
display: inline-block;
padding: 4px 6px 1px;
border: 1px solid $border-colour;
border-radius: 4px;
}

.app-c-native-campaign__link {
margin-top: 15px;
display: block;
text-decoration: none;
@include bold-19;

&:hover {
text-decoration: underline;
}
}

.app-c-native-campaign__description {
@include core-14;
padding-top: 5px;
}
178 changes: 178 additions & 0 deletions app/controllers/concerns/contextual_comms_ab_testable.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,178 @@
module ContextualCommsAbTestable
GOOGLE_ANALYTICS_CUSTOM_DIMENSION = 70
CAMPAIGN_DATA = {
get_in_go_far: {
title: "Get In Go Far",
description: "Search thousands of apprenticeships from great companies, with more added every day.",
link: "https://www.getingofar.gov.uk/",
},
eating: {
title: "How healthy is your food?",
description: "Find out more about calories, the benefits of eating well and simple ways you can make a change.",
link: "https://www.nhs.uk/oneyou/eating",
},
check_your_pay: {
title: "Check Your Pay",
description: "Are you being underpaid? Find out if your employer is giving you less than the legal minimum.",
link: "https://checkyourpay.campaign.gov.uk",
},
your_pension: {
title: "Get to know your state pension",
description: "Get an online forecast to tell you how much you might get, and the earliest you can claim it.",
link: "https://www.yourpension.gov.uk/",
}
}.freeze

def self.included(base)
base.helper_method(
:campaign_description,
:campaign_link,
:campaign_title,
:contextual_comms_test_variant,
:show_blue_box_campaign?,
:show_contextual_comms_campaign?,
:show_native_campaign?,
:whitelisted_campaign_page?,
)
base.after_action :set_test_response_header
end

def contextual_comms_test
@contextual_comms_test ||= GovukAbTesting::AbTest.new(
"ContextualComms",
dimension: GOOGLE_ANALYTICS_CUSTOM_DIMENSION,
allowed_variants: %w(NoCampaign BlueBoxCampaign NativeCampaign),
control_variant: "NoCampaign"
)
end

def contextual_comms_test_variant
@contextual_comms_test_variant ||= contextual_comms_test.requested_variant(request.headers)
end

def set_test_response_header
contextual_comms_test_variant.configure_response(response) if whitelisted_campaign_page?
end

def show_contextual_comms_campaign?
!contextual_comms_test_variant.variant?("NoCampaign") && whitelisted_campaign_page?
end

def show_blue_box_campaign?
contextual_comms_test_variant.variant?("BlueBoxCampaign")
end

def show_native_campaign?
contextual_comms_test_variant.variant?("NativeCampaign")
end

def whitelisted_campaign_page?
campaign_name.present?
end

def campaign_name
@campaign_name ||=
if GET_IN_GO_FAR_PAGES.include?(content_item_path)
:get_in_go_far
elsif EATING_PAGES.include?(content_item_path)
:eating
elsif CHECK_YOUR_PAY_PAGES.include?(content_item_path)
:check_your_pay
elsif YOUR_PENSION_PAGES.include?(content_item_path)
:your_pension
end
end

def campaign_link
CAMPAIGN_DATA[campaign_name][:link] +
"?utm_source=#{content_item_path}" +
"&utm_content=#{contextual_comms_test_variant.variant_name}" +
"&utm_campaign=ukgov-promo&utm_medium=referral"
end

def campaign_title
CAMPAIGN_DATA[campaign_name][:title]
end

def campaign_description
CAMPAIGN_DATA[campaign_name][:description]
end

GET_IN_GO_FAR_PAGES = %w(
/career-skills-and-training
/mature-student-university-funding
/higher-education-courses-find-and-apply
/what-different-qualification-levels-mean
/what-different-qualification-levels-mean/list-of-qualification-levels
/what-different-qualification-levels-mean/compare-different-qualification-levels
/further-education-courses
/improve-english-maths-it-skills
/further-education-courses
/further-education-courses/financial-help
/further-education-courses/find-a-course
/looking-for-work-if-disabled
/exoffenders-and-employment
).freeze

EATING_PAGES = %w(
/free-school-transport
/healthy-start
/healthy-start/eligibility
/healthy-start/how-to-claim
/healthy-start/what-youll-get
/help-with-childcare-costs
/help-with-childcare-costs/childcare-vouchers
/help-with-childcare-costs/free-childcare-2-year-olds
/help-with-childcare-costs/free-childcare-2-year-olds-benefits
/help-with-childcare-costs/free-childcare-and-education-for-2-to-4-year-olds
/help-with-childcare-costs/support-while-you-study
/help-with-childcare-costs/tax-credits
/help-with-childcare-costs/tax-free-childcare
/help-with-childcare-costs/universal-credit
/school-uniform
).freeze

CHECK_YOUR_PAY_PAGES = %w(
/pay-and-work-rights
/payslips
/report-cash-in-hand-pay
/student-jobs-paying-tax
/tips-at-work
/tips-at-work/tips-and-tax
/understanding-your-pay/deductions-from-your-pay
/understanding-your-pay/pay-calculations-if-you-work-shifts-or-get-bonuses
/understanding-your-pay/working-out-your-pay
/employment-contracts-and-conditions
/employment-contracts-and-conditions/collective-agreements
/employment-contracts-and-conditions/contract-terms
/employment-contracts-and-conditions/written-statement-of-employment-particulars
/employment-status
/employment-status/employee
/employment-status/worker
/flexible-working
/flexible-working/types-of-flexible-working
/maximum-weekly-working-hours
/maximum-weekly-working-hours/calculating-your-working-hours
/maximum-weekly-working-hours/weekly-maximum-working-hours-and-opting-out
/night-working-hours
/overtime-your-rights
/rest-breaks-work
/rest-breaks-work/compensatory-rest
/rest-breaks-work/exceptions
/rest-breaks-work/taking-breaks
/rest-breaks-work/young-workers
).freeze

YOUR_PENSION_PAGES = %w(
/armed-forces-pension-calculator
/personal-pensions-your-rights
/transferring-your-pension
/pension-types
/workplace-pensions
/employers-workplace-pensions-rules
/carers-credit
/national-insurance-credits
/voluntary-national-insurance-contributions
/plan-retirement-income
).freeze
end
2 changes: 2 additions & 0 deletions app/controllers/content_items_controller.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
class ContentItemsController < ApplicationController
include ContextualCommsAbTestable

rescue_from GdsApi::HTTPForbidden, with: :error_403
rescue_from GdsApi::HTTPNotFound, with: :error_notfound
rescue_from GdsApi::HTTPGone, with: :error_410
Expand Down
6 changes: 6 additions & 0 deletions app/views/components/_blue-box-campaign.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<div class="app-c-native-blue-box-campaign__container">
<a class="app-c-native-blue-box-campaign__link" href="<%= href %>">
<h2 class="app-c-native-blue-box-campaign__title"><%= title %></h2>
<span class="app-c-native-blue-box-campaign__description"><%= description %></span>
</a>
</div>
5 changes: 5 additions & 0 deletions app/views/components/_native-campaign.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<div class="app-c-native-campaign__container">
<span class="app-c-native-campaign__header">Campaign</span>
<a class="app-c-native-campaign__link" href="<%= href %>"><%= title %></a>
<p class="app-c-native-campaign__description"><%= description %></p>
</div>
1 change: 1 addition & 0 deletions app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
<meta name="description" content="<%= strip_tags(@content_item.description) %>" />
<% end %>
<meta name="govuk:content-id" content="<%= @content_item.content_id %>" />
<%= contextual_comms_test_variant.analytics_meta_tag.html_safe if whitelisted_campaign_page? %>
<%= yield :extra_head_content %>
</head>
<body>
Expand Down
9 changes: 9 additions & 0 deletions app/views/shared/_sidebar_navigation.html.erb
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
<div class="column-one-third">
<%= render 'govuk_publishing_components/components/contextual_sidebar', content_item: @content_item.content_item.parsed_content %>
<!-- Rendering the contextual communications campaign test -->
<% if show_contextual_comms_campaign? %>
<% if show_blue_box_campaign? %>
<%= render 'components/blue-box-campaign', title: campaign_title, description: campaign_description, href: campaign_link %>
<% end %>
<% if show_native_campaign? %>
<%= render 'components/native-campaign', title: campaign_title, description: campaign_description, href: campaign_link %>
<% end %>
<% end %>
</div>
20 changes: 20 additions & 0 deletions test/components/blue_box_campaign_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
require 'component_test_helper'

class BlueBoxCampaignTest < ComponentTestCase
def component_name
"blue-box-campaign"
end

test "fails to render a blue box campaign link when no parameters given" do
assert_raise do
render_component({})
end
end

test "renders a blue box campaign link when required params are given" do
render_component(title: "Campaign about things", description: "Look at this campaign about things", href: "https://www.gov.uk/things")
assert_select "h2", "Campaign about things"
assert_select "a", href: /https:\/\/www.gov.uk\/things/
assert_select "span", "Look at this campaign about things"
end
end
20 changes: 20 additions & 0 deletions test/components/native_campaign_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
require 'component_test_helper'

class NativeCampaignTest < ComponentTestCase
def component_name
"native-campaign"
end

test "fails to render a native campaign link when no parameters given" do
assert_raise do
render_component({})
end
end

test "renders a native campaign link when required params are given" do
render_component(title: "Campaign about things", description: "Look at this campaign about things", href: "https://www.gov.uk/things")
assert_select "a", "Campaign about things"
assert_select "a", href: /https:\/\/www.gov.uk\/things/
assert_select "p", "Look at this campaign about things"
end
end
Loading

0 comments on commit 0831526

Please sign in to comment.