Rack middleware support for A/B testing
Ruby
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
lib/rack
test
LICENSE
README.md
Rakefile.rb

README.md

Rack::AB

Default settings assign users by id to one of two equally sized buckets, "a" and "b", and pass the bucket name to the app via the env object.

Note: This code contains no logging. We would need to log bucket impressions and subsequent actions to compare performance between buckets.

Basic usage

  1. Set the user id in a cookie called user_id
  2. Add Rack::AB to your code

    use Rack::AB
    # ...
    if 'a' == env['rack.ab.bucket_name']
      body = 'content for bucket a'
    else
      body = 'content for bucket b'
    end
    # ...
    [200, {}, body]
    
  3. Call app

In development, we can force a bucket by setting a cookie named rack_ab to the bucket name.

Configuration

  • set buckets, e.g. 10% "control" and 10% "fancy_bucket"
  • set user id cookie name
  • set override cookie name

Configure like this

use Rack::AB, :buckets => [{'control' => 10}, {'new_feature' => 10}]
# ...

Any and all feedback welcome.