Project

ab_panel

0.01
No commit activity in last 3 years
No release in over 3 years
Run A/B test experiments on your Rails 4+ site using Mixpanel as a backend.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.3
>= 0
>= 0
>= 0

Runtime

>= 4.0
 Project Readme

Build Status

AbPanel

Run A/B test experiments on your Rails 3+ site using Mixpanel as a backend.

Installation

Add this line to your application's Gemfile:

gem 'ab_panel'

And then execute:

$ bundle

Or install it yourself as:

$ gem install ab_panel

Upgrading from 0.2.0 to 0.3.0

In this new version we've added weights to different conditions/scenarios. This is so that you can rollout certain features slowly. We've also removed the original (control scenario) that is added standard.

The only thing you need to do to upgrade is update the ab_panel.yml.

Old:

foo:
  - bar1
  - bar2

New (if you want to keep original or need original):

foo:
  bar1: 2
  bar2: 2
  original: 2

Usage

Create a config file with one or more experiments and conditions.

In config/ab_panel.yml

my_experiment:
  original:    1
  condition_b: 1
  condition_c: 1

Note that this will create 3 conditions:

  1. Original condition
  2. Condition B
  3. Condition C

You can add as many experiments and conditions as you want. Every visitor will be assigned randomly to one condition for each scenario for as long as their session remains active.

To track events in Mixpanel, create a file called config/mixpanel.yml with your api key, api secret, and the token of of your project for every environment you want to run Mixpanel in, like so:

production:
  api_key: 383340bfea74ab839ebb667ab3c59fa3
  api_secret: 3990703d6d73d2b7fd78a1d19de66605
  token: 735cc06a1b1ded4827d7faff385ad6fc

Enable the Mixpanel Middleware by adding it in the necessary environments:

config.middleware.use Mixpanel::Middleware, AbPanel::Mixpanel::Config.token, persist: true

See Mixpanel Gem docs on the Middleware for more info.

In your application controller:

class ApplicationController < ActionController::Base
  before_filter :initialize_ab_panel!
end

Then track any event you want from your controller:

class CoursesController < ApplicationController
  def show
    track_action '[visits] Course', { :course => :id }
  end
end

You can track variables from within your controller actions:

def show
  # A single variable
  track_variable :id, params[:id]

  # Or a hash with variables
  track_variables { id: params[:id], email: current_user.email }
end

Use conditions based on experiments and conditions throughout your code, e.g. in your views:

<% if AbPanel.my_experiment.condition_b? %>
  <p>Hi there, you are in Condition B in my experiment.</p>
<% else %>
  <p>Hi there, you are either in the Original condition or in Condition C in my experiment.</p>

  <% if AbPanel.my_experiment.condition_c? %>
    <p>Ah, you're in C.</p>
  <% end %>
<% end %>

Or in your controller:

case AbPanel.my_experiment.condition
when 'condition_b'
  render 'my_experiment/condition_b'
when 'condition_c'
  render 'my_experiment/condition_c'
else
  render 'index'
end

Make sure to check the Example App

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request