Skip to content

Rack::AB module for A/B testing #35

Closed
wants to merge 14 commits into from

2 participants

@erikeldridge

Default settings assign users to one of two buckets, "a" and "b", and store the bucket name in a cookie called "rack_ab". If a bucket has not yet been assigned for a user, one is randomly chosen. The bucket name is made available to the app via the env object.

Basic usage looks like this:

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

Configuration options allow:

  • custom cookie name, e.g., "bucket_name" instead of "rack_ab"
  • custom bucket names, e.g. "control" and "fancy_bucket" instead of "a" and "b"
  • custom cookie parameters such as path, domain, and expires.

Custom configuration looks like this:

use Rack::AB, :bucket_names => ['control', 'new_feature']
# ...

Any and all feedback welcome.

erikeldridge added some commits Apr 5, 2011
@erikeldridge erikeldridge Create AB testing middleware for Rack
Define basic functionality and initial spec tests
7890851
@erikeldridge erikeldridge Simplify args passed to Rack::AB 54560f5
@erikeldridge erikeldridge Correct assertion logic
Since Rack::AB can return 'a' or 'b' randomly, verify that
an array of correct response values includes the value we receive.
4a0c3c6
@erikeldridge erikeldridge Write test to verify no cookie set if one exists
Rack::AB should only set a cookie if one has not been set before
3110683
@erikeldridge erikeldridge Create test for custom cookie name ecab8e1
@erikeldridge erikeldridge Update initialize to accept params hash
Simplify arg syntax for initializer by accepting a hash instead
of ordered args
d520de4
@erikeldridge erikeldridge Create test for custom possible values
Developers should be able to define custom values to
use in the cookie. Create a test to verify
6c9be20
@erikeldridge erikeldridge Write test to verify cookie expiration setting 200765f
@erikeldridge erikeldridge Rename possible_values to bucket_names
bucket_names is more self-descriptive.
2551bbe
@erikeldridge erikeldridge Add Rack::AB to autoload 48afa95
@erikeldridge erikeldridge Add bucket name to env obj, and comment code 009acc1
@erikeldridge erikeldridge Add test for splitting traffic 8117831
@erikeldridge erikeldridge Remove .gitignore from repo ad9e0b4
@erikeldridge erikeldridge Add Rack::AB to readme ceb20d9
@josh
josh commented Apr 12, 2011

Sorry, but we aren't accepting any new middleware.

I'd suggest staring your own rack-ab project on github.

@josh josh closed this Apr 12, 2011
@erikeldridge

Thanks for the quick response.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.