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 21, 2024
1 parent 2685d48 commit 8a9d302
Show file tree
Hide file tree
Showing 73 changed files with 1,380 additions and 533 deletions.
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
43 changes: 43 additions & 0 deletions app/controllers/concerns/popular_tasks_ab_testable.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
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?,
)
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: "Z",
)
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.match?(%r{\A/browse/[^/]+\z})
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
end
44 changes: 42 additions & 2 deletions app/helpers/browse_helper.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,50 @@
module BrowseHelper
def variant_a_popular_links?(slug)
I18n.exists?("#{slug}.variant_a", scope: "browse.popular_links")
end

def variant_a_popular_links(slug)
I18n.t("#{slug}.control", scope: "browse.popular_links")
end

def variant_b_popular_links?(slug)
I18n.exists?("#{slug}.variant_b", scope: "browse.popular_links")
end

def variant_b_popular_links(slug)
I18n.t("#{slug}.control", scope: "browse.popular_links")
end

def control_popular_links?(slug)
I18n.exists?("#{slug}.control", scope: "browse.popular_links")
end

def control_popular_links(slug)
I18n.t("#{slug}.control", scope: "browse.popular_links")
end

def display_popular_links_for_slug?(slug)
I18n.exists?(slug.to_s, scope: "browse.popular_links")
if popular_tasks_variant_a_page?
variant_a_popular_links?(slug)
elsif popular_tasks_variant_b_page?
variant_b_popular_links?(slug)
else
control_popular_links?(slug)
end
end

def variant_popular_links_for_slug(slug)
if popular_tasks_variant_a_page?
variant_a_popular_links(slug)
elsif popular_tasks_variant_b_page?
variant_b_popular_links(slug)
else
control_popular_links(slug)
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
26 changes: 18 additions & 8 deletions config/locales/ar/browse.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,25 @@ ar:
browse:
popular_links:
benefits:
- title:
url:
control:
- title:
url:
variant_a:
- title:
url:
variant_b:
- title:
url:
business:
- title:
url:
- title:
url:
- title:
url:
control:
- title:
url:
variant_a:
- title:
url:
variant_b:
- title:
url:
all_categories: جميع الفئات
description:
popular_tasks:
Expand Down
26 changes: 18 additions & 8 deletions config/locales/az/browse.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,25 @@ az:
browse:
popular_links:
benefits:
- title:
url:
control:
- title:
url:
variant_a:
- title:
url:
variant_b:
- title:
url:
business:
- title:
url:
- title:
url:
- title:
url:
control:
- title:
url:
variant_a:
- title:
url:
variant_b:
- title:
url:
all_categories: Bütün kateqoriyalar
description:
popular_tasks:
Expand Down
26 changes: 18 additions & 8 deletions config/locales/be/browse.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,25 @@ be:
browse:
popular_links:
benefits:
- title:
url:
control:
- title:
url:
variant_a:
- title:
url:
variant_b:
- title:
url:
business:
- title:
url:
- title:
url:
- title:
url:
control:
- title:
url:
variant_a:
- title:
url:
variant_b:
- title:
url:
all_categories: Усе катэгорыі
description:
popular_tasks:
Expand Down
26 changes: 18 additions & 8 deletions config/locales/bg/browse.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,25 @@ bg:
browse:
popular_links:
benefits:
- title:
url:
control:
- title:
url:
variant_a:
- title:
url:
variant_b:
- title:
url:
business:
- title:
url:
- title:
url:
- title:
url:
control:
- title:
url:
variant_a:
- title:
url:
variant_b:
- title:
url:
all_categories: Всички категории
description:
popular_tasks:
Expand Down
26 changes: 18 additions & 8 deletions config/locales/bn/browse.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,25 @@ bn:
browse:
popular_links:
benefits:
- title:
url:
control:
- title:
url:
variant_a:
- title:
url:
variant_b:
- title:
url:
business:
- title:
url:
- title:
url:
- title:
url:
control:
- title:
url:
variant_a:
- title:
url:
variant_b:
- title:
url:
all_categories: সকল শ্রেণিবিভাগ
description:
popular_tasks:
Expand Down
26 changes: 18 additions & 8 deletions config/locales/cs/browse.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,25 @@ cs:
browse:
popular_links:
benefits:
- title:
url:
control:
- title:
url:
variant_a:
- title:
url:
variant_b:
- title:
url:
business:
- title:
url:
- title:
url:
- title:
url:
control:
- title:
url:
variant_a:
- title:
url:
variant_b:
- title:
url:
all_categories: Všechny kategorie
description:
popular_tasks:
Expand Down
26 changes: 18 additions & 8 deletions config/locales/cy/browse.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,25 @@ cy:
browse:
popular_links:
benefits:
- title:
url:
control:
- title:
url:
variant_a:
- title:
url:
variant_b:
- title:
url:
business:
- title:
url:
- title:
url:
- title:
url:
control:
- title:
url:
variant_a:
- title:
url:
variant_b:
- title:
url:
all_categories: Pob categori
description:
popular_tasks:
Expand Down
26 changes: 18 additions & 8 deletions config/locales/da/browse.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,25 @@ da:
browse:
popular_links:
benefits:
- title:
url:
control:
- title:
url:
variant_a:
- title:
url:
variant_b:
- title:
url:
business:
- title:
url:
- title:
url:
- title:
url:
control:
- title:
url:
variant_a:
- title:
url:
variant_b:
- title:
url:
all_categories: Alle kategorier
description:
popular_tasks:
Expand Down
Loading

0 comments on commit 8a9d302

Please sign in to comment.