Skip to content

Commit

Permalink
Add AB test to request new Explore supermenu header from Static
Browse files Browse the repository at this point in the history
Static has a new header that the GOV.UK Explore team want to AB test as part of their beta.
  • Loading branch information
chao-xian committed Jul 15, 2021
1 parent 88c422b commit 2bee8b2
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 1 deletion.
14 changes: 13 additions & 1 deletion app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
class ApplicationController < ActionController::Base
include Slimmer::Headers
include Slimmer::Template
include ExploreMenuAbTestable

rescue_from GdsApi::TimedOutException, with: :error_503
rescue_from GdsApi::EndpointNotFound, with: :error_503
Expand All @@ -11,7 +12,10 @@ class ApplicationController < ActionController::Base
rescue_from GdsApi::HTTPForbidden, with: :error_403
rescue_from RecordNotFound, with: :cacheable_404

slimmer_template "gem_layout"
before_action :set_explore_menu_response
before_action :set_slimmer_template

helper_method :explore_menu_variant, :explore_menu_testable?

if ENV["BASIC_AUTH_USERNAME"]
http_basic_authenticate_with(
Expand All @@ -22,6 +26,14 @@ class ApplicationController < ActionController::Base

protected

def set_slimmer_template
if explore_menu_testable?
slimmer_template "gem_layout_explore_header"
else
slimmer_template "gem_layout"
end
end

def error_403
error :forbidden
end
Expand Down
26 changes: 26 additions & 0 deletions app/controllers/concerns/explore_menu_ab_testable.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
module ExploreMenuAbTestable
CUSTOM_DIMENSION = 47

ALLOWED_VARIANTS = %w[A B Z].freeze

def explore_menu_test
@explore_menu_test ||= GovukAbTesting::AbTest.new(
"ExploreMenuAbTestable",
dimension: CUSTOM_DIMENSION,
allowed_variants: ALLOWED_VARIANTS,
control_variant: "Z",
)
end

def explore_menu_variant
explore_menu_test.requested_variant(request.headers)
end

def set_explore_menu_response
explore_menu_variant.configure_response(response) if explore_menu_testable?
end

def explore_menu_testable?
explore_menu_variant.variant?("B")
end
end
1 change: 1 addition & 0 deletions app/views/calendar/bank_holidays.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<% content_for :extra_headers do %>
<%= @requested_variant.analytics_meta_tag.html_safe %>
<%= explore_menu_variant.analytics_meta_tag.html_safe if explore_menu_testable? %>
<% end %>

<%= render :partial => "calendar_head" %>
Expand Down
1 change: 1 addition & 0 deletions app/views/homepage/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<% content_for :extra_headers do %>
<link rel="canonical" href="<%= Frontend.govuk_website_root + root_path %>" />
<meta name="description" content="GOV.UK - The place to find government services and information - Simpler, clearer, faster" />
<%= explore_menu_variant.analytics_meta_tag.html_safe if explore_menu_testable? %>
<% end %>
<% content_for :title, "Welcome to GOV.UK" %>
<% content_for :body_classes, "homepage" %>
Expand Down
11 changes: 11 additions & 0 deletions test/functional/calendar_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,17 @@ class CalendarControllerTest < ActionController::TestCase
stub_content_store_has_item("/when-do-the-clocks-change")
end

context "AB testing of Explore navigational super menu" do
should "request for Explore navigational super menu from slimmer" do
with_variant ExploreMenuAbTestable: "B" do
get :calendar, params: { scope: "bank-holidays" }

assert response.successful?
assert "core_layout_explore_header", assigns[:slimmer_template]
end
end
end

context "HTML request (no format)" do
should "load the calendar and show it" do
get :calendar, params: { scope: "bank-holidays" }
Expand Down

0 comments on commit 2bee8b2

Please sign in to comment.