Skip to content

Commit

Permalink
Prepare for Popular Tasks AB test
Browse files Browse the repository at this point in the history
  • Loading branch information
unoduetre committed Aug 19, 2024
1 parent 2685d48 commit 6a4e0b3
Show file tree
Hide file tree
Showing 71 changed files with 3,103 additions and 1 deletion.
2 changes: 2 additions & 0 deletions app/controllers/browse_controller.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
class BrowseController < ApplicationController
include PopularTasksAbTestable

slimmer_template "gem_layout_full_width"

def index
Expand Down
53 changes: 53 additions & 0 deletions app/controllers/concerns/popular_tasks_ab_testable.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
module PopularTasksAbTestable
extend ActiveSupport::Concern

ALLOWED_VARIANTS = %w[A B C Z].freeze

included do
helper_method(
:popular_tasks_variant,
:popular_tasks_page_under_test?,
:popular_tasks_variant_a_page?,
:popular_tasks_variant_b_page?,
:popular_tasks_variant_c_page?,
:popular_tasks_variant_z_page?,
)
after_action :set_popular_tasks_ab_test_response_header
end

def popular_tasks_ab_test
@popular_tasks_ab_test ||= GovukAbTesting::AbTest.new(
"PopularTasks",
allowed_variants: ALLOWED_VARIANTS,
control_variant: "C",
)
end

def popular_tasks_variant
@popular_tasks_variant ||= popular_tasks_ab_test.requested_variant(request.headers)
end

def popular_tasks_page_under_test?
request.path.starts_with?(%r{/browse/business|/browse/benefits})
end

def set_popular_tasks_ab_test_response_header
popular_tasks_variant.configure_response(response) if popular_tasks_page_under_test?
end

def popular_tasks_variant_a_page?
popular_tasks_page_under_test? && popular_tasks_variant.variant?("A")
end

def popular_tasks_variant_b_page?
popular_tasks_page_under_test? && popular_tasks_variant.variant?("B")
end

def popular_tasks_variant_c_page?
popular_tasks_page_under_test? && popular_tasks_variant.variant?("C")
end

def popular_tasks_variant_z_page?
popular_tasks_page_under_test? && popular_tasks_variant.variant?("Z")
end
end
38 changes: 37 additions & 1 deletion app/helpers/browse_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,44 @@ def display_popular_links_for_slug?(slug)
I18n.exists?(slug.to_s, scope: "browse.popular_links")
end

def variant_a_popular_links(slug)
I18n.t(slug.to_s, scope: "browse.popular_links")
end

def variant_b_popular_links(slug)
I18n.t(slug.to_s, scope: "browse.popular_links")
end

def variant_c_popular_links(slug)
I18n.t(slug.to_s, scope: "browse.popular_links")
end

def variant_z_popular_links(slug)
I18n.t(slug.to_s, scope: "browse.popular_links")
end

def no_popular_tasks_ab_test?
!respond_to?(:popular_tasks_variant)
end

def variant_popular_links_for_slug(slug)
default_variant_popular_links = variant_c_popular_links(slug)

if no_popular_tasks_ab_test?
default_variant_popular_links
elsif popular_tasks_variant_a_page?
variant_a_popular_links(slug)
elsif popular_tasks_variant_b_page?
variant_b_popular_links(slug)
elsif popular_tasks_variant_z_page?
variant_z_popular_links(slug)
else
default_variant_popular_links
end
end

def popular_links_for_slug(slug)
links = I18n.t(slug.to_s, scope: "browse.popular_links")
links = variant_popular_links_for_slug(slug)
count = links.length
links.map.with_index(1) do |link, index|
{
Expand Down
1 change: 1 addition & 0 deletions app/views/browse/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
section: page.title.downcase,
}
} %>
<%= popular_tasks_variant.analytics_meta_tag.html_safe if popular_tasks_page_under_test? %>
<% end %>
<% content_for :breadcrumbs do %>
Expand Down
44 changes: 44 additions & 0 deletions config/locales/ar/browse.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,50 @@ ar:
url:
- title:
url:
popular_links_a:
benefits:
- title:
url:
business:
- title:
url:
- title:
url:
- title:
url:
popular_links_b:
benefits:
- title:
url:
business:
- title:
url:
- title:
url:
- title:
url:
popular_links_c:
benefits:
- title:
url:
business:
- title:
url:
- title:
url:
- title:
url:
popular_links_z:
benefits:
- title:
url:
business:
- title:
url:
- title:
url:
- title:
url:
all_categories: جميع الفئات
description:
popular_tasks:
Expand Down
44 changes: 44 additions & 0 deletions config/locales/az/browse.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,50 @@ az:
url:
- title:
url:
popular_links_a:
benefits:
- title:
url:
business:
- title:
url:
- title:
url:
- title:
url:
popular_links_b:
benefits:
- title:
url:
business:
- title:
url:
- title:
url:
- title:
url:
popular_links_c:
benefits:
- title:
url:
business:
- title:
url:
- title:
url:
- title:
url:
popular_links_z:
benefits:
- title:
url:
business:
- title:
url:
- title:
url:
- title:
url:
all_categories: Bütün kateqoriyalar
description:
popular_tasks:
Expand Down
44 changes: 44 additions & 0 deletions config/locales/be/browse.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,50 @@ be:
url:
- title:
url:
popular_links_a:
benefits:
- title:
url:
business:
- title:
url:
- title:
url:
- title:
url:
popular_links_b:
benefits:
- title:
url:
business:
- title:
url:
- title:
url:
- title:
url:
popular_links_c:
benefits:
- title:
url:
business:
- title:
url:
- title:
url:
- title:
url:
popular_links_z:
benefits:
- title:
url:
business:
- title:
url:
- title:
url:
- title:
url:
all_categories: Усе катэгорыі
description:
popular_tasks:
Expand Down
44 changes: 44 additions & 0 deletions config/locales/bg/browse.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,50 @@ bg:
url:
- title:
url:
popular_links_a:
benefits:
- title:
url:
business:
- title:
url:
- title:
url:
- title:
url:
popular_links_b:
benefits:
- title:
url:
business:
- title:
url:
- title:
url:
- title:
url:
popular_links_c:
benefits:
- title:
url:
business:
- title:
url:
- title:
url:
- title:
url:
popular_links_z:
benefits:
- title:
url:
business:
- title:
url:
- title:
url:
- title:
url:
all_categories: Всички категории
description:
popular_tasks:
Expand Down
44 changes: 44 additions & 0 deletions config/locales/bn/browse.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,50 @@ bn:
url:
- title:
url:
popular_links_a:
benefits:
- title:
url:
business:
- title:
url:
- title:
url:
- title:
url:
popular_links_b:
benefits:
- title:
url:
business:
- title:
url:
- title:
url:
- title:
url:
popular_links_c:
benefits:
- title:
url:
business:
- title:
url:
- title:
url:
- title:
url:
popular_links_z:
benefits:
- title:
url:
business:
- title:
url:
- title:
url:
- title:
url:
all_categories: সকল শ্রেণিবিভাগ
description:
popular_tasks:
Expand Down
Loading

0 comments on commit 6a4e0b3

Please sign in to comment.