How to use Growthbook(GB) AB system
Differences between GB and existing powr ab system​
- There is no ab_logs table. Ab assigns durring execution time on controllers.
- NEW expose table - ab_impressions. This table will be filled out when users have seen particular ab.
- Now we can manage abs settings on GB dashboard - https://app.growthbook.io/ (login [email protected] by google auth)
- All abs running rules on GB now we just send attributes and fetch running conditions from their sdk:
app/controllers/concerns/ab/growthbook.rb
def init_ab_features_flags
growthbook.attributes = {
logged_in: current_user.present?,
user_id: current_user&.id,
unique_id: current_user&.unique_id || cookies[:unique_id],
platform: current_user&.primary_platform || @host || params[:platform] || (session[:shopify_install_id].present? && "shopify"),
url: url_for,
# returns [] if user is free, ['forBuilder_pro_monthly'] if users has eg formbuilder subscription
levels: current_user&.active_subscriptions_as_string
}
end
Introduction​
A very quick overview of GrowthBook -
How to create ab feature.​
How to get feature(ab) on frontend side.​
Change feature depends of group and make expose​
How to add target conditions​
Caveats​
Danger zone. Please think twice when and where exposed should be called.​
it uses Ab::GrowthbookImpressionListener that will write record every tine when expose action controller was called.
app/controllers/concerns/ab/growthbook.rb
def growthbook_exposed(experiment_key)
# Will write record to AbImpression table after calling feature_value]
growthbook.listener = Ab::GrowthbookImpressionListener.new(current_user, cookies)
growthbook.feature_value(experiment_key)
end
Purge GB cache.​
Need to pull up new/updated features and target conditions
Fallback::Cache.delete("growthbook_features")
Apply ab feature.​
Call init_ab_features_flags on your controller action that user should see. This method is available on all controllers, eg:
before_action :init_ab_features_flags, only: :standalone
Get ab groups on frontend​
Call prepare_app_for_front_end on your controller action that user should see. This method is available on all controllers, eg:
app/controllers/users_controller.rb
before_action :prepare_growthbook_frontend_abs, only: :show
Dev/QA tools​
In order to force any abs for test purposes you can apply cookie key gb_forced_abs with groups and variations that you wanna test in your browser, in example bellow:
test_group_1:control|test_group_2:variation_2