2019-10-01 18:06:28 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
# == Experimentation
|
|
|
|
#
|
2020-04-21 15:21:10 +00:00
|
|
|
# Utility module for A/B testing experimental features. Define your experiments in the `EXPERIMENTS` constant.
|
|
|
|
# Experiment options:
|
|
|
|
# - tracking_category (optional, used to set the category when tracking an experiment event)
|
2020-10-28 06:08:59 +00:00
|
|
|
# - use_backwards_compatible_subject_index (optional, set this to true if you need backwards compatibility)
|
2020-04-21 15:21:10 +00:00
|
|
|
#
|
|
|
|
# The experiment is controlled by a Feature Flag (https://docs.gitlab.com/ee/development/feature_flags/controls.html),
|
2020-05-14 18:08:06 +00:00
|
|
|
# which is named "#{experiment_key}_experiment_percentage" and *must* be set with a percentage and not be used for other purposes.
|
2020-04-21 15:21:10 +00:00
|
|
|
#
|
2020-05-14 18:08:06 +00:00
|
|
|
# To enable the experiment for 10% of the users:
|
|
|
|
#
|
2020-06-05 15:08:23 +00:00
|
|
|
# chatops: `/chatops run feature set experiment_key_experiment_percentage 10`
|
|
|
|
# console: `Feature.enable_percentage_of_time(:experiment_key_experiment_percentage, 10)`
|
2020-04-21 15:21:10 +00:00
|
|
|
#
|
|
|
|
# To disable the experiment:
|
|
|
|
#
|
2020-05-14 18:08:06 +00:00
|
|
|
# chatops: `/chatops run feature delete experiment_key_experiment_percentage`
|
2020-06-02 12:08:33 +00:00
|
|
|
# console: `Feature.remove(:experiment_key_experiment_percentage)`
|
2020-05-14 18:08:06 +00:00
|
|
|
#
|
|
|
|
# To check the current rollout percentage:
|
|
|
|
#
|
|
|
|
# chatops: `/chatops run feature get experiment_key_experiment_percentage`
|
|
|
|
# console: `Feature.get(:experiment_key_experiment_percentage).percentage_of_time_value`
|
2019-10-01 18:06:28 +00:00
|
|
|
#
|
2020-06-02 12:08:33 +00:00
|
|
|
|
2020-06-05 15:08:23 +00:00
|
|
|
# TODO: see https://gitlab.com/gitlab-org/gitlab/-/issues/217490
|
2019-10-01 18:06:28 +00:00
|
|
|
module Gitlab
|
|
|
|
module Experimentation
|
|
|
|
EXPERIMENTS = {
|
2020-05-14 18:08:06 +00:00
|
|
|
onboarding_issues: {
|
2020-10-28 06:08:59 +00:00
|
|
|
tracking_category: 'Growth::Conversion::Experiment::OnboardingIssues',
|
|
|
|
use_backwards_compatible_subject_index: true
|
2020-05-14 18:08:06 +00:00
|
|
|
},
|
2020-03-24 12:09:42 +00:00
|
|
|
ci_notification_dot: {
|
2020-10-28 06:08:59 +00:00
|
|
|
tracking_category: 'Growth::Expansion::Experiment::CiNotificationDot',
|
|
|
|
use_backwards_compatible_subject_index: true
|
2020-03-26 06:08:40 +00:00
|
|
|
},
|
2020-05-15 12:08:28 +00:00
|
|
|
upgrade_link_in_user_menu_a: {
|
2020-10-28 06:08:59 +00:00
|
|
|
tracking_category: 'Growth::Expansion::Experiment::UpgradeLinkInUserMenuA',
|
|
|
|
use_backwards_compatible_subject_index: true
|
2020-06-05 12:08:24 +00:00
|
|
|
},
|
|
|
|
invite_members_version_a: {
|
2020-10-28 06:08:59 +00:00
|
|
|
tracking_category: 'Growth::Expansion::Experiment::InviteMembersVersionA',
|
|
|
|
use_backwards_compatible_subject_index: true
|
2020-06-08 21:09:17 +00:00
|
|
|
},
|
2020-10-14 18:08:47 +00:00
|
|
|
invite_members_version_b: {
|
2020-10-28 06:08:59 +00:00
|
|
|
tracking_category: 'Growth::Expansion::Experiment::InviteMembersVersionB',
|
|
|
|
use_backwards_compatible_subject_index: true
|
2020-10-14 18:08:47 +00:00
|
|
|
},
|
2020-10-26 15:08:40 +00:00
|
|
|
invite_members_empty_group_version_a: {
|
2020-10-28 06:08:59 +00:00
|
|
|
tracking_category: 'Growth::Expansion::Experiment::InviteMembersEmptyGroupVersionA',
|
|
|
|
use_backwards_compatible_subject_index: true
|
2020-10-26 15:08:40 +00:00
|
|
|
},
|
2020-08-07 15:10:17 +00:00
|
|
|
contact_sales_btn_in_app: {
|
2020-10-28 06:08:59 +00:00
|
|
|
tracking_category: 'Growth::Conversion::Experiment::ContactSalesInApp',
|
|
|
|
use_backwards_compatible_subject_index: true
|
2020-08-18 21:09:57 +00:00
|
|
|
},
|
|
|
|
customize_homepage: {
|
2020-10-28 06:08:59 +00:00
|
|
|
tracking_category: 'Growth::Expansion::Experiment::CustomizeHomepage',
|
|
|
|
use_backwards_compatible_subject_index: true
|
2020-08-25 18:10:49 +00:00
|
|
|
},
|
|
|
|
invite_email: {
|
2020-10-28 06:08:59 +00:00
|
|
|
tracking_category: 'Growth::Acquisition::Experiment::InviteEmail',
|
|
|
|
use_backwards_compatible_subject_index: true
|
2020-09-24 09:09:35 +00:00
|
|
|
},
|
|
|
|
invitation_reminders: {
|
2020-10-28 06:08:59 +00:00
|
|
|
tracking_category: 'Growth::Acquisition::Experiment::InvitationReminders',
|
|
|
|
use_backwards_compatible_subject_index: true
|
2020-09-30 15:09:46 +00:00
|
|
|
},
|
|
|
|
group_only_trials: {
|
2020-10-28 06:08:59 +00:00
|
|
|
tracking_category: 'Growth::Conversion::Experiment::GroupOnlyTrials',
|
|
|
|
use_backwards_compatible_subject_index: true
|
2020-10-15 00:08:42 +00:00
|
|
|
},
|
|
|
|
default_to_issues_board: {
|
2020-10-28 06:08:59 +00:00
|
|
|
tracking_category: 'Growth::Conversion::Experiment::DefaultToIssuesBoard',
|
|
|
|
use_backwards_compatible_subject_index: true
|
2019-10-01 18:06:28 +00:00
|
|
|
}
|
|
|
|
}.freeze
|
|
|
|
|
|
|
|
class << self
|
2019-10-18 21:06:37 +00:00
|
|
|
def experiment(key)
|
2020-11-23 09:09:13 +00:00
|
|
|
Gitlab::Experimentation::Experiment.new(key, **EXPERIMENTS[key])
|
2019-10-18 21:06:37 +00:00
|
|
|
end
|
|
|
|
|
2019-10-23 15:06:29 +00:00
|
|
|
def enabled?(experiment_key)
|
2019-10-01 18:06:28 +00:00
|
|
|
return false unless EXPERIMENTS.key?(experiment_key)
|
|
|
|
|
2020-11-23 09:09:13 +00:00
|
|
|
experiment(experiment_key).enabled?
|
2019-10-23 15:06:29 +00:00
|
|
|
end
|
2019-10-01 18:06:28 +00:00
|
|
|
|
2020-09-24 09:09:35 +00:00
|
|
|
def enabled_for_attribute?(experiment_key, attribute)
|
|
|
|
index = Digest::SHA1.hexdigest(attribute).hex % 100
|
|
|
|
enabled_for_value?(experiment_key, index)
|
|
|
|
end
|
|
|
|
|
2020-10-28 06:08:59 +00:00
|
|
|
def enabled_for_value?(experiment_key, value)
|
|
|
|
enabled?(experiment_key) && experiment(experiment_key).enabled_for_index?(value)
|
2019-10-01 18:06:28 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|