simple_abs 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +60 -0
- data/Rakefile +1 -0
- data/lib/generators/simple_abs/simple_abs_generator.rb +23 -0
- data/lib/generators/simple_abs/templates/migration.rb +19 -0
- data/lib/simple_abs/version.rb +3 -0
- data/lib/simple_abs.rb +63 -0
- data/simple_abs.gemspec +23 -0
- metadata +88 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 nate
|
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,60 @@
|
|
1
|
+
# SimpleAbs
|
2
|
+
|
3
|
+
A super super simple way to do AB tests in Rails.
|
4
|
+
|
5
|
+
I made this because everything else seemed overly complicated. You don't need to install Redis or anything like that.
|
6
|
+
|
7
|
+
Definitely inspired by other AB testing libraris like AB Bingo from patio11.
|
8
|
+
|
9
|
+
|
10
|
+
## Installation
|
11
|
+
|
12
|
+
Add this line to your application's Gemfile:
|
13
|
+
|
14
|
+
gem 'simple_abs'
|
15
|
+
|
16
|
+
And then execute:
|
17
|
+
|
18
|
+
$ bundle
|
19
|
+
|
20
|
+
Or install it yourself as:
|
21
|
+
|
22
|
+
$ gem install simple_abs
|
23
|
+
|
24
|
+
Create the migration to install the Alternatives table:
|
25
|
+
|
26
|
+
rails g simple_abs
|
27
|
+
|
28
|
+
Run the migrations:
|
29
|
+
|
30
|
+
rake db:migrate
|
31
|
+
|
32
|
+
|
33
|
+
## Usage
|
34
|
+
|
35
|
+
You can use simple_abs to figure out an "alternative" to show your users. You can get ahold of an alternative from a View or from a Controller.
|
36
|
+
|
37
|
+
Here's an example where I might have a short and long version of a buy page. simple_abs will randomly pick which version this user should see.
|
38
|
+
|
39
|
+
def buy
|
40
|
+
@buy_page = ab_test("buy_page", ["short", "long"])
|
41
|
+
|
42
|
+
render template: 'site/buy', layout: 'write'
|
43
|
+
end
|
44
|
+
|
45
|
+
If they've already seen one of the alternatives, simple_abs figures that out from the permanent cookies of the user.
|
46
|
+
|
47
|
+
Once your user converts you can call:
|
48
|
+
|
49
|
+
converted!("buy_page")
|
50
|
+
|
51
|
+
|
52
|
+
|
53
|
+
|
54
|
+
## Contributing
|
55
|
+
|
56
|
+
1. Fork it
|
57
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
58
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
59
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
60
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'rails/generators'
|
2
|
+
require 'rails/generators/migration'
|
3
|
+
|
4
|
+
class SimpleAbsGenerator < Rails::Generators::Base
|
5
|
+
include Rails::Generators::Migration
|
6
|
+
|
7
|
+
def self.source_root
|
8
|
+
@source_root ||= File.join(File.dirname(__FILE__), 'templates')
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.next_migration_number(dirname)
|
12
|
+
if ActiveRecord::Base.timestamped_migrations
|
13
|
+
Time.new.utc.strftime("%Y%m%d%H%M%S")
|
14
|
+
else
|
15
|
+
"%.3d" % (current_migration_number(dirname) + 1)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def create_migration_file
|
20
|
+
migration_template 'migration.rb', 'db/migrate/create_alternatives_table.rb'
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
class CreateAlternativesTable < ActiveRecord::Migration
|
2
|
+
def self.up
|
3
|
+
create_table :alternatives, :force => true do |t|
|
4
|
+
t.string "which"
|
5
|
+
t.integer "participants", :default => 0
|
6
|
+
t.integer "conversions", :default => 0
|
7
|
+
t.text "experiment"
|
8
|
+
|
9
|
+
t.timestamps
|
10
|
+
end
|
11
|
+
|
12
|
+
add_index :alternatives, :which
|
13
|
+
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.down
|
17
|
+
drop_table :alternatives
|
18
|
+
end
|
19
|
+
end
|
data/lib/simple_abs.rb
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
require "simple_abs/version"
|
2
|
+
|
3
|
+
module SimpleAbs
|
4
|
+
|
5
|
+
def is_bot?
|
6
|
+
agent = request.env["HTTP_USER_AGENT"]
|
7
|
+
matches = nil
|
8
|
+
matches = agent.match(/(facebook|postrank|voyager|twitterbot|googlebot|slurp|butterfly|pycurl|tweetmemebot|metauri|evrinid|reddit|digg)/mi) if agent
|
9
|
+
if (agent.nil? or matches)
|
10
|
+
return true
|
11
|
+
else
|
12
|
+
return false
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def ab_test(name, tests)
|
17
|
+
|
18
|
+
if is_bot?
|
19
|
+
test_value = tests[rand(tests.size)]
|
20
|
+
return test_value
|
21
|
+
end
|
22
|
+
|
23
|
+
if params[:test_value]
|
24
|
+
return params[:test_value]
|
25
|
+
end
|
26
|
+
|
27
|
+
test_value = cookies[name]
|
28
|
+
|
29
|
+
if test_value.blank? || !tests.include?(test_value)
|
30
|
+
test_value = tests[rand(tests.size)]
|
31
|
+
cookies.permanent[name] = test_value
|
32
|
+
|
33
|
+
Alternative.find_or_create_by_experiment_and_which(name, test_value).increment!(:participants)
|
34
|
+
end
|
35
|
+
|
36
|
+
return test_value
|
37
|
+
end
|
38
|
+
|
39
|
+
def converted!(name)
|
40
|
+
|
41
|
+
if !is_bot?
|
42
|
+
test_value = cookies[name]
|
43
|
+
if test_value && cookies[name.to_s + "_converted"].blank?
|
44
|
+
Alternative.find_or_create_by_experiment_and_which(name, test_value).increment!(:conversions)
|
45
|
+
cookies.permanent[name.to_s + "_converted"] = true
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
|
51
|
+
class Railtie < Rails::Railtie
|
52
|
+
initializer "simple_abs.initialize" do
|
53
|
+
ActionView::Base.send :include, SimpleAbs
|
54
|
+
ActionController::Base.send :include, SimpleAbs
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
class Alternative < ActiveRecord::Base
|
59
|
+
|
60
|
+
end
|
61
|
+
|
62
|
+
|
63
|
+
end
|
data/simple_abs.gemspec
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'simple_abs/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "simple_abs"
|
8
|
+
spec.version = SimpleAbs::VERSION
|
9
|
+
spec.authors = ["nate"]
|
10
|
+
spec.email = ["nate@cityposh.com"]
|
11
|
+
spec.description = %q{Really simple way to do AB tests in Rails}
|
12
|
+
spec.summary = %q{Really simple way to do AB tests in Rails}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
end
|
metadata
ADDED
@@ -0,0 +1,88 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: simple_abs
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- nate
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-04-16 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: bundler
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '1.3'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '1.3'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rake
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
description: Really simple way to do AB tests in Rails
|
47
|
+
email:
|
48
|
+
- nate@cityposh.com
|
49
|
+
executables: []
|
50
|
+
extensions: []
|
51
|
+
extra_rdoc_files: []
|
52
|
+
files:
|
53
|
+
- .gitignore
|
54
|
+
- Gemfile
|
55
|
+
- LICENSE.txt
|
56
|
+
- README.md
|
57
|
+
- Rakefile
|
58
|
+
- lib/generators/simple_abs/simple_abs_generator.rb
|
59
|
+
- lib/generators/simple_abs/templates/migration.rb
|
60
|
+
- lib/simple_abs.rb
|
61
|
+
- lib/simple_abs/version.rb
|
62
|
+
- simple_abs.gemspec
|
63
|
+
homepage: ''
|
64
|
+
licenses:
|
65
|
+
- MIT
|
66
|
+
post_install_message:
|
67
|
+
rdoc_options: []
|
68
|
+
require_paths:
|
69
|
+
- lib
|
70
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
71
|
+
none: false
|
72
|
+
requirements:
|
73
|
+
- - ! '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
77
|
+
none: false
|
78
|
+
requirements:
|
79
|
+
- - ! '>='
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '0'
|
82
|
+
requirements: []
|
83
|
+
rubyforge_project:
|
84
|
+
rubygems_version: 1.8.24
|
85
|
+
signing_key:
|
86
|
+
specification_version: 3
|
87
|
+
summary: Really simple way to do AB tests in Rails
|
88
|
+
test_files: []
|