Skip to content

Commit

Permalink
WIP - add AB test for /find-utr-number
Browse files Browse the repository at this point in the history
  • Loading branch information
richardTowers committed Oct 5, 2023
1 parent aea97f6 commit 128cde5
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
15 changes: 15 additions & 0 deletions app/controllers/content_items_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,21 @@ class ContentItemsController < ApplicationController
def show
load_content_item

# TEMPORARY (author: richard.towers, expected end date: November 30 2023)
# Content specific AB test for the Find your UTR number page
if @content_item.base_path == "/find-utr-number"
ab_test = GovukAbTesting::AbTest.new(
"find_utr_number_video_links",
dimension: 300, # TODO: which dimension should we use?
allowed_variants: %w[HelpText VideoLink],
control_variant: "HelpText",
)
@requested_variant = ab_test.requested_variant(request.headers)
@requested_variant.configure_response(response)
@content_item = AnswerFindYourUtrPresenter.new(@content_item, @requested_variant.variant_name)
end
# /TEMPORARY

set_expiry

if is_service_manual?
Expand Down
32 changes: 32 additions & 0 deletions app/presenters/answer_find_your_utr_presenter.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# TEMPORARY (author: richard.towers, expected end date: November 30 2023)
# Content specific AB test for the Find your UTR number page
class AnswerFindYourUtrPresenter < AnswerPresenter
def initialize(parent_presenter, ab_test_variant)
super(
parent_presenter.content_item,
parent_presenter.requested_path,
parent_presenter.view_context
)
@ab_test_variant = ab_test_variant
end

def body
result = super
if @ab_test_variant == "VideoLink"
# NOTE: this is a fragile way of doing an AB test on content.
#
# Any change to the base content, or to the way the content is rendered
# could potentially break the B variant of the test, and result in both
# variants being the same.
# We're aware of this risk, and we're going to be careful in this one off
# situation. This is not a sustainable way of doing AB tests in the
# future.
result.sub(
/<li>\s*in\ the\s+<a\ href="[^"]*"><abbr\ title="[^"]+">HMRC<\/abbr>\s+app<\/a>/,
'<li>in the <a href="https://www.gov.uk/guidance/download-the-hmrc-app"><abbr title="HM Revenue and Customs">HMRC</abbr> app</a> - watch a <a href="https://www.youtube.com/watch?v=LXw9ily9rTo">video about finding your UTR number in the app</a>',
)
else
result
end
end
end

0 comments on commit 128cde5

Please sign in to comment.