<commit_before># Vanity
[![Build
Status](https://travis-ci.org/assaf/vanity.png?branch=master)](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

[![Dashboard](doc/images/sidebar_test.png)](http://github.com/assaf/vanity)

<!-- toc -->

- [Installation](#installation)
- [Setup](#setup)
  * [Datastore](#datastore)
    + [Redis Setup](#redis-setup)
    + [MongoDB Setup](#mongodb-setup)
    + [SQL Database Setup](#sql-database-setup)
    + [Forking servers and reconnecting](#forking-servers-and-reconnecting)
  * [Initialization](#initialization)
  * [User identification](#user-identification)
    + [Rails](#rails)
    + [Other](#other)
  * [Define a A/B test](#define-a-ab-test)
  * [Present the different options to your users](#present-the-different-options-to-your-users)
  * [Measure conversion](#measure-conversion)
  * [Check the report](#check-the-report)
    + [Rails report dashboard](#rails-report-dashboard)
- [Registering participants with Javascript](#registering-participants-with-javascript)
- [Compatibility](#compatibility)
- [Testing](#testing)
- [Updating documentation](#updating-documentation)
- [Contributing](#contributing)
- [Credits/License](#creditslicense)

<!-- tocstop -->

## Installation

Add to your Gemfile:

```ruby
gem "vanity"
```

(For support for older versions of Rails and Ruby 1.8, please see the [1.9.x
branch](https://github.com/assaf/vanity/tree/1-9-stable).)

## Setup

### Datastore

Choose a datastore that best fits your needs and preferences for storing
experiment results. Choose one of: Redis, MongoDB or an SQL database. While
Redis is usually faster, it may add additional complexity to your stack.
Datastores should be configured using a `config/vanity.yml`.

#### Redis Setup

Add to your Gemfile:

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

By default Vanity is configured to use Redis on localhost port 6379 with
database 0.

A sample `config/vanity.yml` might look like:

```yaml
test:
  collecting: false
production:
  adapter: redis
  url: redis://<%= ENV["REDIS_USER"] %>:<%= ENV["REDIS_PASSWORD"] %>@<%= ENV["REDIS_HOST"] %>:<%= ENV["REDIS_PORT"] %>/0
```

If you want to use your test environment with RSpec you will need to add an
adapter to test:

```yaml
test:
  adapter: redis
  collecting: false
```

To re-use an existing redis connection, you can call `Vanity.connect!` explicitly, for example:

```ruby
Vanity.connect!(
  adapter: :redis,
  redis: $redis
)
```

#### MongoDB Setup

Add to your Gemfile:

```ruby
gem "mongo", "~> 2.0" # For Mongo 1.x support see Vanity versions 2.1 and below.
```

A sample `config/vanity.yml` might look like:

```yaml
development:
  adapter: mongodb
  database: analytics
test:
  collecting: false
production:
  adapter: mongodb
  database: analytics
```

#### SQL Database Setup

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, add to your Gemfile:

```ruby
    gem "active_record"
```

A sample `config/vanity.yml` might look like:

```yaml
development:
  adapter: active_record
  active_record_adapter: sqlite3
  database: db/development.sqlite3
test:
  adapter: active_record
  active_record_adapter: default
  collecting: false
production:
  active_record_adapter: postgresql
  <% uri = URI.parse(ENV['DATABASE_URL']) %>
  host:     <%= uri.host %>
  username: <%= uri.user%>
  password: <%= <PASSWORD> %>
  port:     <%= uri.port %>
  database: <%= uri.path.sub('/', '') %>
```<commit_msg>production should have an adapter, fixes #351<commit_after># Vanity
[![Build
Status](https://travis-ci.org/assaf/vanity.png?branch=master)](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

[![Dashboard](doc/images/sidebar_test.png)](http://github.com/assaf/vanity)

<!-- toc -->

- [Installation](#installation)
- [Setup](#setup)
  * [Datastore](#datastore)
    + [Redis Setup](#redis-setup)
    + [MongoDB Setup](#mongodb-setup)
    + [SQL Database Setup](#sql-database-setup)
    + [Forking servers and reconnecting](#forking-servers-and-reconnecting)
  * [Initialization](#initialization)
  * [User identification](#user-identification)
    + [Rails](#rails)
    + [Other](#other)
  * [Define a A/B test](#define-a-ab-test)
  * [Present the different options to your users](#present-the-different-options-to-your-users)
  * [Measure conversion](#measure-conversion)
  * [Check the report](#check-the-report)
    + [Rails report dashboard](#rails-report-dashboard)
- [Registering participants with Javascript](#registering-participants-with-javascript)
- [Compatibility](#compatibility)
- [Testing](#testing)
- [Updating documentation](#updating-documentation)
- [Contributing](#contributing)
- [Credits/License](#creditslicense)

<!-- tocstop -->

## Installation

Add to your Gemfile:

```ruby
gem "vanity"
```

(For support for older versions of Rails and Ruby 1.8, please see the [1.9.x
branch](https://github.com/assaf/vanity/tree/1-9-stable).)

## Setup

### Datastore

Choose a datastore that best fits your needs and preferences for storing
experiment results. Choose one of: Redis, MongoDB or an SQL database. While
Redis is usually faster, it may add additional complexity to your stack.
Datastores should be configured using a `config/vanity.yml`.

#### Redis Setup

Add to your Gemfile:

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

By default Vanity is configured to use Redis on localhost port 6379 with
database 0.

A sample `config/vanity.yml` might look like:

```yaml
test:
  collecting: false
production:
  adapter: redis
  url: redis://<%= ENV["REDIS_USER"] %>:<%= ENV["REDIS_PASSWORD"] %>@<%= ENV["REDIS_HOST"] %>:<%= ENV["REDIS_PORT"] %>/0
```

If you want to use your test environment with RSpec you will need to add an
adapter to test:

```yaml
test:
  adapter: redis
  collecting: false
```

To re-use an existing redis connection, you can call `Vanity.connect!` explicitly, for example:

```ruby
Vanity.connect!(
  adapter: :redis,
  redis: $redis
)
```

#### MongoDB Setup

Add to your Gemfile:

```ruby
gem "mongo", "~> 2.0" # For Mongo 1.x support see Vanity versions 2.1 and below.
```

A sample `config/vanity.yml` might look like:

```yaml
development:
  adapter: mongodb
  database: analytics
test:
  collecting: false
production:
  adapter: mongodb
  database: analytics
```

#### SQL Database Setup

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, add to your Gemfile:

```ruby
    gem "active_record"
```

A sample `config/vanity.yml` might look like:

```yaml
development:
  adapter: active_record
  active_record_adapter: sqlite3
  database: db/development.sqlite3
test:
  adapter: active_record
  active_record_adapter: default
  collecting: false
production:
  adapter: active_record
  active_record_adapter: postgresql
  <% uri = URI.parse(ENV['DATABASE_URL']) %>
  host:     <%= uri.host %>
  username: <%= uri.user%>
  password: <%= <PASSWORD> %>
  port:     <%= uri.port %>
  database: <%= uri.path.sub('/', '') %>
```
{'fraction_non_alphanumeric': 0.1479761114797611, 'fraction_numerical': 0.006768414067684141, 'mean_word_length': 4.512801755669349, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 35, 'https://': 6, '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': '2287512', 'n_tokens_mistral': 2665, 'n_tokens_neox': 2449, 'n_words': 702}