<commit_before>= Vanity
{<img src="https://travis-ci.org/assaf/vanity.png?branch=master" alt="Build Status" />}[https://travis-ci.org/assaf/vanity]

Vanity is an A/B testing framework for Rails that is datastore agnostic.

* All about Vanity: http://vanity.labnotes.org
* On Github: http://github.com/assaf/vanity

http://farm3.static.flickr.com/2540/4099665871_497f274f68_o.jpg


== A/B Testing With Rails (In 5 Easy Steps)

=== <b>Step 1:</b> Start using Vanity in your Rails application

==== Step 1.1

===== Rails 2.x installation

  Rails::Initializer.run do |config|
    gem.config "vanity"

    config.after_initialize do
      require "vanity"
    end
  end

===== Rails 3 & Rails 4 installation

Add to your Gemfile:

  gem "vanity"

==== Step 1.2

Choose a method to store experiment results.

For Redis:

  gem "redis", ">= 2.1"
  gem "redis-namespace", ">= 1.1.0"

For Mongo:

  gem "bson_ext"
  gem "mongo"

Vanity supports multiple SQL stores (like MySQL, MariaDB, Postgres, Sqlite, etc.) using ActiveRecord, which is built into Rails. If you're using DataMapper, Sequel or another persistence framework:

   gem "active_record"

Fun the generator and migrations to create the database schema:

  $ rails generate vanity
  $ rake db:migrate

==== Step 1.3

Turn Vanity on, and pass a reference to a method that identifies a user. For example:

  class ApplicationController < ActionController::Base
    use_vanity :current_user
  end

=== <b>Step 2:</b> Define your first A/B test

This experiment goes in the file <code>experiments/price_options.rb</code>:

  ab_test "Price options" do
    description "Mirror, mirror on the wall, who's the better price of all?"
    alternatives 19, 25, 29
    metrics :signups
  end

NOTE: If using a metric as above ("signups"), there needs to be a corresponding ruby file for that metric. Inside the "experiments" directory create a "metrics" directory with a file called "signups.rb". The contents of the file can describe the signup metric, refer to the "Metrics" Vanity documentation page for an example.

=== <b>Step 3:</b> Present the different options to your users

  <h2>Get started for only $<%= ab_test :price_options %> a month!</h2>

=== <b>Step 4:</b> Measure conversion

Conversions are created via the <code>track!</code> method. For example:

  class SignupController < ApplicationController
    def signup
      @account = Account.new(params[:account])
      if @account.save
        track! :signups
        redirect_to @acccount
      else
        render action: :offer
      end
    end
  end

=== <b>Step 5:</b> Check the report:

  vanity report --output vanity.html

To view metrics and experiment results with the dashboard in Rails 3 & Rails 4:

  rails generate controller Vanity

In <code>config/routes.rb</code>, add:

  match '/vanity(/:action(/:id(.:format)))', :controller => :vanity, :via => :get

Where the controller should looks like:

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

NOTE: By default, Vanity turns collection off in development mode. To turn it on, in <code>config/environments/development.rb</code> add:

  Vanity.playground.collecting = true<commit_msg>Allow posts in recommended route in README<commit_after>= Vanity
{<img src="https://travis-ci.org/assaf/vanity.png?branch=master" alt="Build Status" />}[https://travis-ci.org/assaf/vanity]

Vanity is an A/B testing framework for Rails that is datastore agnostic.

* All about Vanity: http://vanity.labnotes.org
* On Github: http://github.com/assaf/vanity

http://farm3.static.flickr.com/2540/4099665871_497f274f68_o.jpg


== A/B Testing With Rails (In 5 Easy Steps)

=== <b>Step 1:</b> Start using Vanity in your Rails application

==== Step 1.1

===== Rails 2.x installation

  Rails::Initializer.run do |config|
    gem.config "vanity"

    config.after_initialize do
      require "vanity"
    end
  end

===== Rails 3 & Rails 4 installation

Add to your Gemfile:

  gem "vanity"

==== Step 1.2

Choose a method to store experiment results.

For Redis:

  gem "redis", ">= 2.1"
  gem "redis-namespace", ">= 1.1.0"

For Mongo:

  gem "bson_ext"
  gem "mongo"

Vanity supports multiple SQL stores (like MySQL, MariaDB, Postgres, Sqlite, etc.) using ActiveRecord, which is built into Rails. If you're using DataMapper, Sequel or another persistence framework:

   gem "active_record"

Fun the generator and migrations to create the database schema:

  $ rails generate vanity
  $ rake db:migrate

==== Step 1.3

Turn Vanity on, and pass a reference to a method that identifies a user. For example:

  class ApplicationController < ActionController::Base
    use_vanity :current_user
  end

=== <b>Step 2:</b> Define your first A/B test

This experiment goes in the file <code>experiments/price_options.rb</code>:

  ab_test "Price options" do
    description "Mirror, mirror on the wall, who's the better price of all?"
    alternatives 19, 25, 29
    metrics :signups
  end

NOTE: If using a metric as above ("signups"), there needs to be a corresponding ruby file for that metric. Inside the "experiments" directory create a "metrics" directory with a file called "signups.rb". The contents of the file can describe the signup metric, refer to the "Metrics" Vanity documentation page for an example.

=== <b>Step 3:</b> Present the different options to your users

  <h2>Get started for only $<%= ab_test :price_options %> a month!</h2>

=== <b>Step 4:</b> Measure conversion

Conversions are created via the <code>track!</code> method. For example:

  class SignupController < ApplicationController
    def signup
      @account = Account.new(params[:account])
      if @account.save
        track! :signups
        redirect_to @acccount
      else
        render action: :offer
      end
    end
  end

=== <b>Step 5:</b> Check the report:

  vanity report --output vanity.html

To view metrics and experiment results with the dashboard in Rails 3 & Rails 4:

  rails generate controller Vanity

In <code>config/routes.rb</code>, add:

  match '/vanity(/:action(/:id(.:format)))', :controller => :vanity, :via => [:get, :post]

Where the controller should looks like:

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

NOTE: By default, Vanity turns collection off in development mode. To turn it on, in <code>config/environments/development.rb</code> add:

  Vanity.playground.collecting = true
{'fraction_non_alphanumeric': 0.10580204778156997, 'fraction_numerical': 0.016444306546695625, 'mean_word_length': 3.818385650224215, 'pattern_counts': {'":': 0, '<': 53, '<?xml version=': 0, '>': 55, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6381115', 'n_tokens_mistral': 2109, 'n_tokens_neox': 1942, 'n_words': 742}