Skip to content

Instantly share code, notes, and snippets.

Last active September 14, 2022 13:58
What would you like to do?
Multivariate - A/B - split testing with Flipper
# Register test groups
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
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)
# 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
# control group
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment