From 6b6602d84a8dbffcc9aa87ea14c02bd76dd0513b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C2=A8Oscar=20Wyatt=C2=A8?= <¨mail@oscarwyatt.co.uk¨> Date: Tue, 13 Jul 2021 13:08:26 +0100 Subject: [PATCH] Adds Start A Business A/B intervention --- Gemfile.lock | 2 +- app/assets/javascripts/application.js | 1 + app/assets/stylesheets/application.scss | 1 + .../ab_tests/sab_pages_testable.rb | 41 ++++++++++++ app/controllers/content_items_controller.rb | 1 + .../_body_with_related_links.html.erb | 5 +- .../document_collection.html.erb | 2 + app/views/content_items/guide.html.erb | 2 + app/views/layouts/application.html.erb | 1 + test/controllers/sab_ab_test.rb | 64 +++++++++++++++++++ 10 files changed, 117 insertions(+), 3 deletions(-) create mode 100644 app/controllers/ab_tests/sab_pages_testable.rb create mode 100644 test/controllers/sab_ab_test.rb diff --git a/Gemfile.lock b/Gemfile.lock index 9400d53d5..4eff9e20c 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -137,7 +137,7 @@ GEM unicorn (>= 5.4, < 5.9) govuk_personalisation (0.5.0) rails (~> 6) - govuk_publishing_components (24.21.1) + govuk_publishing_components (25.0.0) govuk_app_config kramdown plek diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index 1809774ad..9cf647db4 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -4,6 +4,7 @@ //= require govuk_publishing_components/components/error-summary //= require govuk_publishing_components/components/feedback //= require govuk_publishing_components/components/govspeak +//= require govuk_publishing_components/components/intervention //= require govuk_publishing_components/components/print-link //= require govuk_publishing_components/components/radio //= require govuk_publishing_components/components/step-by-step-nav diff --git a/app/assets/stylesheets/application.scss b/app/assets/stylesheets/application.scss index 037fdc4df..82301e493 100644 --- a/app/assets/stylesheets/application.scss +++ b/app/assets/stylesheets/application.scss @@ -24,6 +24,7 @@ $govuk-new-link-styles: true; @import 'govuk_publishing_components/components/heading'; @import 'govuk_publishing_components/components/hint'; @import 'govuk_publishing_components/components/input'; +@import 'govuk_publishing_components/components/intervention'; @import 'govuk_publishing_components/components/inverse-header'; @import 'govuk_publishing_components/components/label'; @import 'govuk_publishing_components/components/lead-paragraph'; diff --git a/app/controllers/ab_tests/sab_pages_testable.rb b/app/controllers/ab_tests/sab_pages_testable.rb new file mode 100644 index 000000000..f4b1a5f19 --- /dev/null +++ b/app/controllers/ab_tests/sab_pages_testable.rb @@ -0,0 +1,41 @@ +module AbTests::SabPagesTestable + CUSTOM_DIMENSION = 48 + + def self.included(base) + base.helper_method( + :sab_page_variant, + :is_testable_sab_page?, + :should_show_sab_intervention?, + ) + base.after_action :set_test_response_header + end + + def sab_page_variant + @sab_page_variant ||= sab_page_test.requested_variant(request.headers) + end + + def is_testable_sab_page? + @is_testable_sab_page ||= request.headers["HTTP_GOVUK_ABTEST_ISSTARTABUSINESSPAGE"] == "true" + end + + def should_show_sab_intervention? + sab_page_variant.variant?("B") && is_testable_sab_page? + end + +private + + def sab_page_test + @sab_page_test ||= GovukAbTesting::AbTest.new( + "StartABusinessSegment", + dimension: CUSTOM_DIMENSION, + allowed_variants: %w[A B C], + control_variant: "A", + ) + end + + def set_test_response_header + if is_testable_sab_page? + sab_page_variant.configure_response(response) + end + end +end diff --git a/app/controllers/content_items_controller.rb b/app/controllers/content_items_controller.rb index 136d11237..f51d98aec 100644 --- a/app/controllers/content_items_controller.rb +++ b/app/controllers/content_items_controller.rb @@ -2,6 +2,7 @@ class ContentItemsController < ApplicationController include GovukPersonalisation::AccountConcern include Slimmer::Template include AbTests::ExploreMenuAbTestable + include AbTests::SabPagesTestable rescue_from GdsApi::HTTPForbidden, with: :error_403 rescue_from GdsApi::HTTPNotFound, with: :error_notfound diff --git a/app/views/content_items/_body_with_related_links.html.erb b/app/views/content_items/_body_with_related_links.html.erb index d9049a898..b4ed7b956 100644 --- a/app/views/content_items/_body_with_related_links.html.erb +++ b/app/views/content_items/_body_with_related_links.html.erb @@ -3,13 +3,14 @@