Skip to content

Commit

Permalink
Move temporary AB test code to private method
Browse files Browse the repository at this point in the history
  • Loading branch information
richardTowers committed Oct 18, 2023
1 parent f922de9 commit d272c76
Showing 1 changed file with 28 additions and 25 deletions.
53 changes: 28 additions & 25 deletions app/controllers/content_items_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,31 +24,7 @@ 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
placeholder = "{{ab_test_find_utr_number_video_links}}"
if @content_item.base_path == "/find-utr-number" && @content_item.body.include?(placeholder)
ab_test = GovukAbTesting::AbTest.new(
"find_utr_number_video_links",
dimension: 61, # https://docs.google.com/spreadsheets/d/1h4vGXzIbhOWwUzourPLIc8WM-iU1b6WYOVDOZxmU1Uo/edit#gid=254065189&range=69:69
allowed_variants: %w[A B Z],
control_variant: "Z",
)
@requested_variant = ab_test.requested_variant(request.headers)
@requested_variant.configure_response(response)

replacement = case @requested_variant.variant_name
when "A"
I18n.t("ab_tests.find_utr_number_video_links.A")
when "B"
I18n.t("ab_tests.find_utr_number_video_links.B")
else
I18n.t("ab_tests.find_utr_number_video_links.Z")
end
@content_item.body.sub!(placeholder, replacement)
end
# /TEMPORARY

temporary_ab_test_find_utr_page
set_expiry

if is_service_manual?
Expand Down Expand Up @@ -291,4 +267,31 @@ def csp_connect_src

@content_item.csp_connect_src
end

# TEMPORARY (author: richard.towers, expected end date: February 2024)
# Content specific AB test for the Find your UTR number page
def temporary_ab_test_find_utr_page
placeholder = "{{ab_test_find_utr_number_video_links}}"
if @content_item.base_path == "/find-utr-number" && @content_item.body.include?(placeholder)
ab_test = GovukAbTesting::AbTest.new(
"find_utr_number_video_links",
dimension: 61, # https://docs.google.com/spreadsheets/d/1h4vGXzIbhOWwUzourPLIc8WM-iU1b6WYOVDOZxmU1Uo/edit#gid=254065189&range=69:69
allowed_variants: %w[A B Z],
control_variant: "Z",
)
@requested_variant = ab_test.requested_variant(request.headers)
@requested_variant.configure_response(response)

replacement = case @requested_variant.variant_name
when "A"
I18n.t("ab_tests.find_utr_number_video_links.A")
when "B"
I18n.t("ab_tests.find_utr_number_video_links.B")
else
I18n.t("ab_tests.find_utr_number_video_links.Z")
end
@content_item.body.sub!(placeholder, replacement)
end
end
# /TEMPORARY
end

0 comments on commit d272c76

Please sign in to comment.