ab_tests 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/.rspec +2 -0
- data/Gemfile +16 -0
- data/LICENSE +22 -0
- data/README.md +57 -0
- data/Rakefile +2 -0
- data/ab_tests.gemspec +16 -0
- data/config.ru +7 -0
- data/lib/ab_tests/railtie.rb +8 -0
- data/lib/ab_tests/variation.rb +3 -0
- data/lib/ab_tests/version.rb +3 -0
- data/lib/ab_tests/view_helpers.rb +24 -0
- data/lib/ab_tests.rb +26 -0
- data/lib/generators/ab_tests/install/install_generator.rb +31 -0
- data/lib/generators/ab_tests/install/templates/ab_tests.rb.erb +8 -0
- data/lib/generators/ab_tests/install/templates/create_variations.rb.erb +13 -0
- data/spec/ab_test_spec.rb +23 -0
- data/spec/internal/config/database.yml +3 -0
- data/spec/internal/config/routes.rb +3 -0
- data/spec/internal/db/combustion_test.sqlite +0 -0
- data/spec/internal/db/schema.rb +10 -0
- data/spec/internal/log/.gitignore +1 -0
- data/spec/internal/public/favicon.ico +0 -0
- data/spec/spec_helper.rb +35 -0
- metadata +78 -0
data/.gitignore
ADDED
data/.rspec
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
|
3
|
+
# Specify your gem's dependencies in ab_tests.gemspec
|
4
|
+
gemspec
|
5
|
+
|
6
|
+
group :test do
|
7
|
+
gem 'debugger'
|
8
|
+
gem 'activerecord'
|
9
|
+
gem 'actionpack' # action_controller, action_view
|
10
|
+
gem 'combustion', '~> 0.5.0'
|
11
|
+
gem 'rspec'
|
12
|
+
gem 'rspec-rails'
|
13
|
+
gem 'sprockets'
|
14
|
+
gem 'sqlite3-ruby', :require => 'sqlite3'
|
15
|
+
end
|
16
|
+
|
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Scott Schulthess
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
# AbTests
|
2
|
+
|
3
|
+
AbTests is a simple gem for creating and deploying new a/b tests with only a simple addition of some ruby code in a view.
|
4
|
+
|
5
|
+
For serious applications, I would recommend reading the source code of this gem and rolling your own version for easy customization.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
gem 'ab_tests'
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
$ bundle exec rails g ab_tests:install
|
17
|
+
$ bundle exec rake db:migrate
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install ab_tests
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
To create an a/b test merely define the following.
|
26
|
+
|
27
|
+
<%= ab_test "example test", ["variation one", "variation two"], nil do |variation| %>
|
28
|
+
<% if variation == "variation one" %>
|
29
|
+
<p>
|
30
|
+
Variation one
|
31
|
+
</p>
|
32
|
+
<% end %>
|
33
|
+
<% if variation == "variation one" %>
|
34
|
+
<p>
|
35
|
+
Variation two
|
36
|
+
</p>
|
37
|
+
<% end %>
|
38
|
+
<% end %>
|
39
|
+
|
40
|
+
|
41
|
+
The ab_test helper takes the following arguements: test_name, an array of variation names, and a unique user idenitfier (optional).
|
42
|
+
|
43
|
+
The results of the tests are stored in the variations table.
|
44
|
+
|
45
|
+
|
46
|
+
Currently, AbTests does not support variation percentages. To date I've only had to run 50/50s and other evenly proportioned tests and I merely removed the variations when I have picked a winner.
|
47
|
+
|
48
|
+
|
49
|
+
|
50
|
+
|
51
|
+
## Contributing
|
52
|
+
|
53
|
+
1. Fork it
|
54
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
55
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
56
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
57
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
data/ab_tests.gemspec
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/ab_tests/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Scott Schulthess"]
|
6
|
+
gem.email = ["scottschulthess@gmail.com"]
|
7
|
+
gem.description = %q{A small rails gem for creating and recording A/B Tests}
|
8
|
+
gem.summary = %q{This gem creates a table called variations and then provides a view helper to define a/b tests and record them on the fly}
|
9
|
+
gem.homepage = ""
|
10
|
+
gem.files = `git ls-files`.split($\)
|
11
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
12
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
13
|
+
gem.name = "ab_tests"
|
14
|
+
gem.require_paths = ["lib"]
|
15
|
+
gem.version = AbTests::VERSION
|
16
|
+
end
|
data/config.ru
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'ab_tests/variation'
|
2
|
+
|
3
|
+
module AbTests
|
4
|
+
module ViewHelpers
|
5
|
+
def ab_test(test_name, variation_names, unique_identifier, &block)
|
6
|
+
unique_id_field = AbTests.configuration.unique_identifier
|
7
|
+
if previous_variation = AbTests::Variation.where(unique_id_field => unique_identifier, test_name: test_name).first and unique_identifier
|
8
|
+
unless Rails.env.test? # a block in a rails view
|
9
|
+
return capture(previous_variation.chosen_variation, &block)
|
10
|
+
else
|
11
|
+
yield(previous_variation.chosen_variation)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
chosen_variation = variation_names.sample
|
15
|
+
AbTests::Variation.create(test_name: test_name, chosen_variation: chosen_variation, unique_id_field => unique_identifier)
|
16
|
+
unless Rails.env.test? # a block in a rails view
|
17
|
+
return capture(chosen_variation, &block)
|
18
|
+
else
|
19
|
+
yield(chosen_variation)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
data/lib/ab_tests.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
require "ab_tests/version"
|
2
|
+
require 'ab_tests/railtie' if defined?(Rails)
|
3
|
+
|
4
|
+
module AbTests
|
5
|
+
|
6
|
+
class << self
|
7
|
+
def configuration
|
8
|
+
@configuration ||= Configuration.new
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
|
13
|
+
def self.configure
|
14
|
+
self.configuration ||= Configuration.new
|
15
|
+
yield(configuration)
|
16
|
+
end
|
17
|
+
|
18
|
+
class Configuration
|
19
|
+
attr_accessor :unique_identifier
|
20
|
+
|
21
|
+
def initialize
|
22
|
+
@unique_identifier = :unique_identifier
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'rails/generators/migration'
|
2
|
+
|
3
|
+
module AbTests
|
4
|
+
module Generators
|
5
|
+
class InstallGenerator < ::Rails::Generators::Base
|
6
|
+
include Rails::Generators::Migration
|
7
|
+
source_root File.expand_path('../templates', __FILE__)
|
8
|
+
argument :unique_identifier, :type => :string, :default => "unique_identifier", desc: "The user identifier for recording who saw which variation"
|
9
|
+
desc "Generate an initializer for configuration, and a migration for recording the test results. Take one argument, USER_ID, which is merely the foreign key for tracking which users saw what."
|
10
|
+
|
11
|
+
|
12
|
+
def self.next_migration_number(path)
|
13
|
+
unless @prev_migration_nr
|
14
|
+
@prev_migration_nr = Time.now.utc.strftime("%Y%m%d%H%M%S").to_i
|
15
|
+
else
|
16
|
+
@prev_migration_nr += 1
|
17
|
+
end
|
18
|
+
@prev_migration_nr.to_s
|
19
|
+
end
|
20
|
+
|
21
|
+
def copy_migrations
|
22
|
+
migration_template "create_variations.rb.erb", "db/migrate/create_variations.rb"
|
23
|
+
end
|
24
|
+
|
25
|
+
def copy_initializer
|
26
|
+
template '../templates/ab_tests.rb.erb', 'config/initializers/ab_tests.rb'
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
class CreateVariations < ActiveRecord::Migration
|
2
|
+
def change
|
3
|
+
create_table :variations do |t|
|
4
|
+
t.string "test_name"
|
5
|
+
t.string "chosen_variation"
|
6
|
+
t.integer "<%=unique_identifier%>"
|
7
|
+
|
8
|
+
t.timestamps
|
9
|
+
end
|
10
|
+
add_index :variations, [:test_name, "<%=unique_identifier%>" ]
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'ab_tests/view_helpers'
|
3
|
+
include AbTests::ViewHelpers
|
4
|
+
describe AbTests::ViewHelpers do
|
5
|
+
|
6
|
+
it "succeeds" do
|
7
|
+
lambda { ab_test('xyz', ['1', '2', '3'], 1) { |chosen_variation| 'test'} }.should_not raise_error
|
8
|
+
end
|
9
|
+
|
10
|
+
it "chooses a variation" do
|
11
|
+
result = ab_test('xyz', ['1', '2', '3'], 1) do |chosen_variation|
|
12
|
+
raise "no chosen variation" unless chosen_variation
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
it "returns a result" do
|
17
|
+
result = ab_test('xyz', ['1', '2', '3'], 1) do |chosen_variation|
|
18
|
+
'test'
|
19
|
+
end
|
20
|
+
result.should eql 'test'
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
Binary file
|
@@ -0,0 +1,10 @@
|
|
1
|
+
ActiveRecord::Schema.define do
|
2
|
+
|
3
|
+
create_table "variations", :force => true do |t|
|
4
|
+
t.string "test_name"
|
5
|
+
t.string "chosen_variation"
|
6
|
+
t.integer "unique_identifier"
|
7
|
+
t.datetime "created_at", :null => false
|
8
|
+
t.datetime "updated_at", :null => false
|
9
|
+
end
|
10
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
*.log
|
File without changes
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
# This file was generated by the `rspec --init` command. Conventionally, all
|
2
|
+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
3
|
+
# Require this file using `require "spec_helper"` to ensure that it is only
|
4
|
+
# loaded once.
|
5
|
+
#
|
6
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
7
|
+
#
|
8
|
+
#
|
9
|
+
require 'ab_tests'
|
10
|
+
RSpec.configure do |config|
|
11
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
12
|
+
config.run_all_when_everything_filtered = true
|
13
|
+
config.filter_run :focus
|
14
|
+
|
15
|
+
# Run specs in random order to surface order dependencies. If you find an
|
16
|
+
# order dependency and want to debug it, you can fix the order by providing
|
17
|
+
# the seed, which is printed after each run.
|
18
|
+
# --seed 1234
|
19
|
+
config.order = 'random'
|
20
|
+
end
|
21
|
+
|
22
|
+
|
23
|
+
require 'rubygems'
|
24
|
+
require 'bundler/setup'
|
25
|
+
|
26
|
+
require 'combustion'
|
27
|
+
|
28
|
+
Combustion.initialize! :active_record, :action_controller,
|
29
|
+
:action_view, :sprockets
|
30
|
+
|
31
|
+
require 'rspec/rails'
|
32
|
+
|
33
|
+
RSpec.configure do |config|
|
34
|
+
config.use_transactional_fixtures = true
|
35
|
+
end
|
metadata
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ab_tests
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Scott Schulthess
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-05-30 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: A small rails gem for creating and recording A/B Tests
|
15
|
+
email:
|
16
|
+
- scottschulthess@gmail.com
|
17
|
+
executables: []
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- .gitignore
|
22
|
+
- .rspec
|
23
|
+
- Gemfile
|
24
|
+
- LICENSE
|
25
|
+
- README.md
|
26
|
+
- Rakefile
|
27
|
+
- ab_tests.gemspec
|
28
|
+
- config.ru
|
29
|
+
- lib/ab_tests.rb
|
30
|
+
- lib/ab_tests/railtie.rb
|
31
|
+
- lib/ab_tests/variation.rb
|
32
|
+
- lib/ab_tests/version.rb
|
33
|
+
- lib/ab_tests/view_helpers.rb
|
34
|
+
- lib/generators/ab_tests/install/install_generator.rb
|
35
|
+
- lib/generators/ab_tests/install/templates/ab_tests.rb.erb
|
36
|
+
- lib/generators/ab_tests/install/templates/create_variations.rb.erb
|
37
|
+
- spec/ab_test_spec.rb
|
38
|
+
- spec/internal/config/database.yml
|
39
|
+
- spec/internal/config/routes.rb
|
40
|
+
- spec/internal/db/combustion_test.sqlite
|
41
|
+
- spec/internal/db/schema.rb
|
42
|
+
- spec/internal/log/.gitignore
|
43
|
+
- spec/internal/public/favicon.ico
|
44
|
+
- spec/spec_helper.rb
|
45
|
+
homepage: ''
|
46
|
+
licenses: []
|
47
|
+
post_install_message:
|
48
|
+
rdoc_options: []
|
49
|
+
require_paths:
|
50
|
+
- lib
|
51
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
52
|
+
none: false
|
53
|
+
requirements:
|
54
|
+
- - ! '>='
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: '0'
|
57
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
58
|
+
none: false
|
59
|
+
requirements:
|
60
|
+
- - ! '>='
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0'
|
63
|
+
requirements: []
|
64
|
+
rubyforge_project:
|
65
|
+
rubygems_version: 1.8.10
|
66
|
+
signing_key:
|
67
|
+
specification_version: 3
|
68
|
+
summary: This gem creates a table called variations and then provides a view helper
|
69
|
+
to define a/b tests and record them on the fly
|
70
|
+
test_files:
|
71
|
+
- spec/ab_test_spec.rb
|
72
|
+
- spec/internal/config/database.yml
|
73
|
+
- spec/internal/config/routes.rb
|
74
|
+
- spec/internal/db/combustion_test.sqlite
|
75
|
+
- spec/internal/db/schema.rb
|
76
|
+
- spec/internal/log/.gitignore
|
77
|
+
- spec/internal/public/favicon.ico
|
78
|
+
- spec/spec_helper.rb
|