Wednesday, February 29, 2012

Rails A/B testing with Split on Heroku

I recently decided to start doing some A/B testing on www.checkthesock.com. The last time I tried A/B testing I used Google website optimizer, it worked fairly well but I did not like how difficult it was to setup a test. This time I looked around for A/B testing tools for rails. I ended up finding split and so far I have been very happy with the results. The documentation is fairly good but it did take a little fiddling to get it working on Heroku.

First off add the Redis to Go add-on in Heroku, the Nano plan is free and has been sufficient for my needs so far. Install redis on the dev server. I use a mac so that was as simple as "brew install redis" and then I followed the brew instructions for getting redis to start on login.

To install the split gem add the following to the Gemfile

 gem 'split', '0.3.3', :require => 'split/dashboard'

To set the development environment up in a way that is compatible to how Redis to Go is configured on Heroku add the following to config/environments/development.rb

ENV['REDISTOGO_URL'] = 'redis://localhost:6379'
Then create an initializer for redis in config/initializers/redis.rb and put the following in that file.
uri = URI.parse(ENV['REDISTOGO_URL'])
REDIS = Redis.new(:host => uri.host, :port => uri.port, :password => uri.password, :username => uri.user)
To configure split to use the applications redis configuration create config/initializers/split.rb and add the following.
Split.redis = REDIS

To setup the split dashboard add the following to config/routes.rb

mount Split::Dashboard, :at => 'split'
To add authentication to the dashboard add the following to config/initializers/split.rb
Split::Dashboard.use Rack::Auth::Basic do |username, password|
  username == 'username' && password == 'password'
end

Setting up an A/B test is super easy just follow the instructions in the split README.

Resources:

Note: These instructions are for rails 3.x, the listed resources do have instructions for earlier versions of rails.

10 comments:

Joel Kemp said...

Thanks for this! Very clean and concise.

Nathan Humbert said...

Thanks, always nice to hear when someone thinks one of my posts was useful.

Pascal Lindelauf said...

Nathan, thanks for your helpful post. One quick question, I hope you know the answer to: I noticed the css styling of the Split dashboard page is gone on Heroku. Have you encountered the same problem and if so, have you solved it?

Thanks, Pascal

Pierre Olivier Martel said...

Pascal, I think it has to do with the way Heroku compiles the assets on the Cedar stack. I tried to find a fix but finally resolved to copying the Split assets to the Public folder. Far from ideal but it works...

Phil Whelan said...

Hi Nathan,

Great post! I'm working on building a similar service, so woud be great to get your feedback and pick your brains. More info here http://www.fluidfeatures.com/

Cheers,
Phil

Aadita kumar said...


Inspiring writings and I greatly admired what you have to say , I hope you continue to provide new ideas for us all and greetings success always for you..

Android Training in Chennai

Jeffy said...


Thank you for sharing such a nice and interesting blog with us. Hope it might be much useful for us. keep on updating...!!
seo company in india
digital marketing company in india
seo company in chennai
digital marketing company in chennai

Ven hudson said...

Thanks for sharing the article. I would like to recommend that users should also try A/B testing Tool by MockingFish. It' a good tool and really helpful for all those who are searching for a good tools for there website.

for IT the said...

I have read your blog its very attractive and impressive. I like it your blog.

Digital Marketing Company in Chennai Digital Marketing Agency

SEO Company in India SEO Services in India

Digital Marketing Company in Chennai

Vignesh PV said...

This blog explains the details about changing the ways of doing that business. That is understand well and doing some different process. Provides he best output of others. Thanks for this blog.

Mobile App Development Company in India