Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add AB Test for Explore Super Menu Header #6164

Merged
merged 2 commits into from
Jul 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions app/controllers/ab_tests/explore_menu_ab_testable.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
module AbTests::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
10 changes: 9 additions & 1 deletion app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,17 @@ class ApplicationController < ActionController::Base
include Slimmer::Template
include LocalisedUrlPathHelper
include LegacyUrlHelper
include AbTests::ExploreMenuAbTestable

protect_from_forgery

before_action :set_slimmer_application_name
before_action :set_slimmer_show_organisations_filter
before_action :set_audit_trail_whodunnit
before_action :set_authenticated_user_header
before_action :set_explore_menu_response

helper_method :explore_menu_variant, :explore_menu_testable?

layout "frontend"
after_action :set_slimmer_template
Expand All @@ -30,7 +34,11 @@ def skip_slimmer
end

def set_slimmer_template
slimmer_template "header_footer_only"
if explore_menu_testable?
slimmer_template "header_footer_only_explore_header"
else
slimmer_template "header_footer_only"
end
end

def set_slimmer_application_name
Expand Down
1 change: 1 addition & 0 deletions app/views/layouts/_frontend_base.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
<%= csrf_meta_tags %>
<%= atom_discovery_link_tag %>
<%= tag :base, href: @page_base_href if @page_base_href %>
<%= explore_menu_variant.analytics_meta_tag.html_safe if explore_menu_testable? %>
</head>
<body class="website government<%= " #{local_assigns[:extra_body_class]}" if local_assigns[:extra_body_class] %>">
<% unless local_assigns[:show_breadcrumbs] %><div class="header-context group"><!-- deliberately empty --></div><% end %>
Expand Down
168 changes: 85 additions & 83 deletions app/views/layouts/frontend.html.erb
Original file line number Diff line number Diff line change
@@ -1,87 +1,89 @@
<%= render :layout => 'layouts/frontend_base' do %>
<nav id="proposition-menu" class="no-proposition-name" aria-label="Departments and policy navigation">
<ul id="proposition-links" data-module="gem-track-click">
<li>
<%= main_navigation_link_to "Departments",
organisations_path,
data: {
track_category: "headerClicked",
track_action: "departmentsLink",
track_label: organisations_path,
track_dimension: "Departments",
track_dimension_index: "29",
}
%>
</li>
<li>
<%= main_navigation_link_to "Worldwide",
world_locations_path(locale: :en),
data: {
track_category: "headerClicked",
track_action: "worldwideLink",
track_label: world_locations_path(locale: :en),
track_dimension: "Worldwide",
track_dimension_index: "29",
}
%>
</li>
<li>
<%= main_navigation_link_to "How government works",
how_government_works_path,
data: {
track_category: "headerClicked",
track_action: "governmentactivityLink",
track_label: how_government_works_path,
track_dimension: "How government works",
track_dimension_index: "29",
}
%>
</li>
<li>
<%= main_navigation_link_to "Get involved",
get_involved_path,
data: {
track_category: "headerClicked",
track_action: "governmentactivityLink",
track_label: get_involved_path,
track_dimension: "Get involved",
track_dimension_index: "29",
}
%>
</li>
<% consultations_path = CGI::escapeHTML('/search/policy-papers-and-consultations?content_store_document_type[]=open_consultations&content_store_document_type[]=closed_consultations') %>
<li class="clear-child">
<a href="<%= consultations_path %>"
data-track-category="headerClicked"
data-track-action="governmentactivityLink"
data-track-label="<%= consultations_path %>"
data-track-dimension="Consultations"
data-track-dimension-index="29">
Consultations
</a>
</li>
<li>
<a href="/search/research-and-statistics"
data-track-category="headerClicked"
data-track-action="governmentactivityLink"
data-track-label="/search/research-and-statistics"
data-track-dimension="Statistics"
data-track-dimension-index="29">
Statistics
</a>
</li>
<li>
<a href="/search/news-and-communications"
data-track-category="headerClicked"
data-track-action="governmentactivityLink"
data-track-label="/search/news-and-communications"
data-track-dimension="News and communications"
data-track-dimension-index="29">
News and communications
</a>
</li>
</ul>
</nav>
<% unless explore_menu_testable? %>
<nav id="proposition-menu" class="no-proposition-name" aria-label="Departments and policy navigation">
<ul id="proposition-links" data-module="gem-track-click">
<li>
<%= main_navigation_link_to "Departments",
organisations_path,
data: {
track_category: "headerClicked",
track_action: "departmentsLink",
track_label: organisations_path,
track_dimension: "Departments",
track_dimension_index: "29",
}
%>
</li>
<li>
<%= main_navigation_link_to "Worldwide",
world_locations_path(locale: :en),
data: {
track_category: "headerClicked",
track_action: "worldwideLink",
track_label: world_locations_path(locale: :en),
track_dimension: "Worldwide",
track_dimension_index: "29",
}
%>
</li>
<li>
<%= main_navigation_link_to "How government works",
how_government_works_path,
data: {
track_category: "headerClicked",
track_action: "governmentactivityLink",
track_label: how_government_works_path,
track_dimension: "How government works",
track_dimension_index: "29",
}
%>
</li>
<li>
<%= main_navigation_link_to "Get involved",
get_involved_path,
data: {
track_category: "headerClicked",
track_action: "governmentactivityLink",
track_label: get_involved_path,
track_dimension: "Get involved",
track_dimension_index: "29",
}
%>
</li>
<% consultations_path = CGI::escapeHTML('/search/policy-papers-and-consultations?content_store_document_type[]=open_consultations&content_store_document_type[]=closed_consultations') %>
<li class="clear-child">
<a href="<%= consultations_path %>"
data-track-category="headerClicked"
data-track-action="governmentactivityLink"
data-track-label="<%= consultations_path %>"
data-track-dimension="Consultations"
data-track-dimension-index="29">
Consultations
</a>
</li>
<li>
<a href="/search/research-and-statistics"
data-track-category="headerClicked"
data-track-action="governmentactivityLink"
data-track-label="/search/research-and-statistics"
data-track-dimension="Statistics"
data-track-dimension-index="29">
Statistics
</a>
</li>
<li>
<a href="/search/news-and-communications"
data-track-category="headerClicked"
data-track-action="governmentactivityLink"
data-track-label="/search/news-and-communications"
data-track-dimension="News and communications"
data-track-dimension-index="29">
News and communications
</a>
</li>
</ul>
</nav>
<% end %>
<main id="content" role="main" class="whitehall-content"<%= " lang=#{I18n.locale.to_s}" unless I18n.locale == :en %>>
<div id="page" class="<%= content_for?(:page_class) ? yield(:page_class) : '' %>" >
<%= yield %>
Expand Down