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
|
|
|
},
|
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
|
2020-12-02 12:09:46 +00:00
|
|
|
},
|
|
|
|
jobs_empty_state: {
|
|
|
|
tracking_category: 'Growth::Activation::Experiment::JobsEmptyState'
|
2020-12-02 21:09:44 +00:00
|
|
|
},
|
|
|
|
remove_known_trial_form_fields: {
|
|
|
|
tracking_category: 'Growth::Conversion::Experiment::RemoveKnownTrialFormFields'
|
2020-12-03 15:09:46 +00:00
|
|
|
},
|
|
|
|
trimmed_skip_trial_copy: {
|
|
|
|
tracking_category: 'Growth::Conversion::Experiment::TrimmedSkipTrialCopy'
|
2019-10-01 18:06:28 +00:00
|
|
|
}
|
|
|
|
}.freeze
|
|
|
|
|
|
|
|
class << self
|
2020-12-03 00:09:53 +00:00
|
|
|
def get_experiment(experiment_key)
|
|
|
|
return unless EXPERIMENTS.key?(experiment_key)
|
|
|
|
|
|
|
|
::Gitlab::Experimentation::Experiment.new(experiment_key, **EXPERIMENTS[experiment_key])
|
2019-10-18 21:06:37 +00:00
|
|
|
end
|
|
|
|
|
2020-12-03 00:09:53 +00:00
|
|
|
def active?(experiment_key)
|
|
|
|
experiment = get_experiment(experiment_key)
|
|
|
|
return false unless experiment
|
2019-10-01 18:06:28 +00:00
|
|
|
|
2020-12-03 00:09:53 +00:00
|
|
|
experiment.active?
|
2019-10-23 15:06:29 +00:00
|
|
|
end
|
2019-10-01 18:06:28 +00:00
|
|
|
|
2020-12-03 00:09:53 +00:00
|
|
|
def in_experiment_group?(experiment_key, subject:)
|
|
|
|
return false if subject.blank?
|
|
|
|
return false unless active?(experiment_key)
|
|
|
|
|
|
|
|
experiment = get_experiment(experiment_key)
|
|
|
|
return false unless experiment
|
|
|
|
|
|
|
|
experiment.enabled_for_index?(index_for_subject(experiment, subject))
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def index_for_subject(experiment, subject)
|
|
|
|
index = if experiment.use_backwards_compatible_subject_index
|
|
|
|
Digest::SHA1.hexdigest(subject_id(subject)).hex
|
|
|
|
else
|
|
|
|
Zlib.crc32("#{experiment.key}#{subject_id(subject)}")
|
|
|
|
end
|
|
|
|
|
|
|
|
index % 100
|
2020-09-24 09:09:35 +00:00
|
|
|
end
|
|
|
|
|
2020-12-03 00:09:53 +00:00
|
|
|
def subject_id(subject)
|
|
|
|
if subject.respond_to?(:to_global_id)
|
|
|
|
subject.to_global_id.to_s
|
|
|
|
elsif subject.respond_to?(:to_s)
|
|
|
|
subject.to_s
|
|
|
|
else
|
|
|
|
raise ArgumentError.new('Subject must respond to `to_global_id` or `to_s`')
|
|
|
|
end
|
2019-10-01 18:06:28 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|