How we do A/B testing in Rails

Configuration

For A/B testing in Rails there is a gem named vanity. At first we have to install the vanity gem by the command=> gem install vanity. After that we have to just configure the test.rb file under the “/environments” folder as follow…

config.after_initialize do
require "vanity"
Vanity.playground.test!
end

Be careful this code must be written at the end of the file. Here we used Vanity.playground.test!  for not accessing the redis for storing data. But if we want to access redis then we have to configure as follows…

Vanity.playground.redis = "::15" # Different DB
Vanity.playground.redis.flushdb # Do this before running tests

Add a new controller for Vanity:

class VanityController < ApplicationController
include Vanity::Rails::Dashboard
end

Lets write a test code  ===>

Now our A/B test file should be under the “experiments/” folder. Lets see a sample code

ab_test "Customer Message without Pricing" do
 description "Testing to see if messages without pricing increases number of signups."
 metrics :trial_activation
end

Here the name of the metric parameter is same as the name of the file where our actual experiment is done under the “experiments/metrics/” directory. The following code is contained in the trial_activation.rb file.

metric "Signup for trial" do
 description "Measures how many people signed up to try our awesome service."
 model Account.in_trial
end
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: