Skip to content

Instantly share code, notes, and snippets.

@bkeepers
Last active September 14, 2022 13:58
Show Gist options
  • Save bkeepers/1e4e097c578400190508623b7f089502 to your computer and use it in GitHub Desktop.
Save bkeepers/1e4e097c578400190508623b7f089502 to your computer and use it in GitHub Desktop.
Multivariate - A/B - split testing with Flipper
# Register test groups
# https://www.flippercloud.io/docs/features#enablement-group
Flipper.register(:group_a) do |actor, context|
# Algorithm or database lookup to determine if a user is in this group
# e.g. 10% percentage of actors
crc32('group_a' + context.feature_name + actor.flipper_id) % 100 < 10
end
Flipper.register(:group_b) do |actor, context|
# Use data model to determine if user is in group
actor.respond_to?(:in_group?) && user.in_group?(:group_b)
end
# Enable different experiments for different groups
Flipper.enable(:my_experiment_a, :group_a)
Flipper.enable(:my_experiment_b, :group_b)
# Conditional in your app to check if an experiment is enabled for a specific actor
if Flipper.enabled?(:my_experiment_a, current_user)
# experiment A group
elsif Flipper.enabled?(:my_experiment_b, current_user)
# experiment B group
else
# control group
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment