simple_abs 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ YzQ4MjgxYWI3ZGQwYWUwMWVjM2YyZGUxNDkyOTYyM2NkNmYxYzEyOA==
5
+ data.tar.gz: !binary |-
6
+ MGUyM2Q2ZGRmY2I2MjBjOWRlNTJjYjQ5NWRhOTEwZGFmOWRmN2JiOA==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ NWFjZDIwOGRjYmQ5M2Y3NmJmMDBjZmY4MzQ4YTUxNzE3ODY1MDE5OGUyYzIw
10
+ NjJhNGNiYjM4MjFkN2Y0ZTU0Y2FhOWVkM2Q4ZWNmYzg1ODU4ODdkOGY3MzMy
11
+ OTlhMzEwZGJhNWRhZjdmZjk1ZjFhNGFhOTNmODIzNGE3NDc2NTY=
12
+ data.tar.gz: !binary |-
13
+ NWEyOWJhNTIxNjE4ODE0MDk1YzE1MGY0OTVhNmM2MjJlZjVjMWVjMjljOTcy
14
+ ZTg0OWI3MzY5NDYzNzgxMWQ4ZDE4MGRlZjM2NzU0YjViMzMzMjEwMTkxNDY0
15
+ ZTQzOWY0ZTM1YzU4YjgzYTYyNDRkMWE1NTliZWQ0YjIzYTliZTM=
data/README.md CHANGED
@@ -1,11 +1,14 @@
1
- # SimpleAbs
1
+ # Rails AB Testing - Simple Abs
2
2
 
3
- A super super simple way to do AB tests in Rails.
3
+ I recently turned on paid subscriptions to [Draft, the writing software](https://draftin.com) I've created. And I wanted a really simple way to test a few alternatives of the payment page in Rails without needing to use a separate service.
4
+
5
+ But the solutions out there get too complicated. Even the "simplest" ones require things like Redis. They do that because somewhere the AB testing library needs to remember what variation of a test a user has already seen, so it knows what to show them on subsequent visits.
4
6
 
5
- I made this because everything else seemed overly complicated. You don't need to install Redis or anything like that.
7
+ But I don't want to install Redis just to have my AB tests be performant. That's still an extra network call to Redis for this simple operation, not to mention the added complexity of adding Redis to my software stack when I don't need it right now.
6
8
 
7
- Definitely inspired by other AB testing libraris like AB Bingo from patio11.
9
+ Why can't the AB testing library just store what variation a user has already seen in the user's cookies?
8
10
 
11
+ That's what SimpleAbs does.
9
12
 
10
13
  ## Installation
11
14
 
@@ -32,29 +35,77 @@ Run the migrations:
32
35
 
33
36
  ## Usage
34
37
 
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.
38
+ Use simple_abs to figure out an "alternative" to show your users. You can get ahold of an alternative from either a Rails View or a Controller.
36
39
 
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.
40
+ ```ruby
41
+ ab_test(experiment name, [variation name 1, variation name 2, etc.])
42
+ ```
38
43
 
39
- def buy
40
- @buy_page = ab_test("buy_page", ["short", "long"])
44
+ Here's an example where I might have three different versions of a buy page. simple_abs will randomly pick which version this user should see.
41
45
 
42
- render template: 'site/buy', layout: 'write'
43
- end
46
+ ```ruby
47
+ def buy
48
+ @buy_page = ab_test("buy_page", ["short", "medium", "long"])
44
49
 
45
- If they've already seen one of the alternatives, simple_abs figures that out from the permanent cookies of the user.
50
+ render action: 'buy'
51
+ end
52
+ ```
46
53
 
47
- Once your user converts you can call:
54
+ Then, in your template, you can use an if statement to show them that version of the @buy_page:
48
55
 
49
- converted!("buy_page")
56
+ ```erb
57
+ <% if @buy_page == "long" %>
58
+ Lots of extra information
59
+ <% end %>
60
+ ```
50
61
 
62
+ If they've already seen one of the alternatives, simple_abs figures that out from the permanent cookies of the user. In other words, if on the first visit, this method:
51
63
 
64
+ ```ruby
65
+ ab_test("buy_page", ["short", "long"])
66
+ ```
52
67
 
68
+ Returns "short". On subsequent visits to the page from this same user, you will also get the value "short" from the ab_test method.
53
69
 
54
- ## Contributing
70
+ Once your user converts you can call "converted!(experiment name)" from a View or Controller:
55
71
 
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
72
+ ```ruby
73
+ converted!("buy_page")
74
+ ```
75
+
76
+ You can also force someone to a specific alternative of your page by using the query paramater "test_value" in your url:
77
+
78
+ http://draftin.com/buy_things?test_value=long
79
+
80
+ When you get some data you can look at it from a Rails console.
81
+
82
+ ```ruby
83
+ irb(main):011:0> pp SimpleAbs::Alternative.where("experiment = 'buy_page'").all
84
+ SimpleAbs::Alternative Load (55.1ms) SELECT "alternatives".* FROM "alternatives" WHERE (experiment = 'buy_page')
85
+ [#<SimpleAbs::Alternative id: 2, which: "short", participants: 16, conversions: 1, experiment: "buy_page", created_at: "2013-04-16 05:14:13", updated_at: "2013-04-16 13:39:14">,
86
+ #<SimpleAbs::Alternative id: 1, which: "long", participants: 20, conversions: 1, experiment: "buy_page", created_at: "2013-04-16 05:11:12", updated_at: "2013-04-16 14:30:01">]
87
+ ```
88
+
89
+ And then you can plug the participants and conversions into a calculator like that found here:
90
+
91
+ [http://tools.seobook.com/ppc-tools/calculators/split-test.html](http://tools.seobook.com/ppc-tools/calculators/split-test.html)
92
+
93
+ Trials = simple_abs' participants
94
+ Successes = simple_abs' conversions
95
+
96
+
97
+
98
+ Feedback
99
+ --------
100
+ [Source code available on Github](https://github.com/n8/simple_abs). Feedback and pull requests are greatly appreciated.
101
+
102
+ Credit
103
+ --------
104
+ This library is very much inspired by the other AB testing libraries out there. Not the least of which is A/Bingo from [Patrick McKenzie](https://twitter.com/patio11).
105
+
106
+
107
+
108
+ <hr/>
109
+
110
+ **P.S. [It would be awesome to meet you on Twitter](http://twitter.com/natekontny).**
111
+ <br/>
@@ -1,3 +1,3 @@
1
1
  module SimpleAbs
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
data/lib/simple_abs.rb CHANGED
@@ -30,7 +30,7 @@ module SimpleAbs
30
30
  test_value = tests[rand(tests.size)]
31
31
  cookies.permanent[name] = test_value
32
32
 
33
- Alternative.find_or_create_by_experiment_and_which(name, test_value).increment!(:participants)
33
+ find_or_create_by_experiment_and_which_method(name, test_value).increment!(:participants)
34
34
  end
35
35
 
36
36
  return test_value
@@ -41,12 +41,26 @@ module SimpleAbs
41
41
  if !is_bot?
42
42
  test_value = cookies[name]
43
43
  if test_value && cookies[name.to_s + "_converted"].blank?
44
- Alternative.find_or_create_by_experiment_and_which(name, test_value).increment!(:conversions)
44
+ find_or_create_by_experiment_and_which_method(name, test_value).increment!(:conversions)
45
45
  cookies.permanent[name.to_s + "_converted"] = true
46
46
  end
47
47
  end
48
48
  end
49
49
 
50
+ def find_or_create_by_experiment_and_which_method(experiment, which)
51
+ alternative = Alternative.where(experiment: experiment, which: which).first
52
+
53
+ if alternative.nil?
54
+ alternative = Alternative.new
55
+ alternative.experiment = experiment
56
+ alternative.which = which
57
+ alternative.save
58
+ end
59
+
60
+ return alternative
61
+
62
+ end
63
+
50
64
 
51
65
  class Railtie < Rails::Railtie
52
66
  initializer "simple_abs.initialize" do
@@ -57,6 +71,16 @@ module SimpleAbs
57
71
 
58
72
  class Alternative < ActiveRecord::Base
59
73
 
74
+ def conversion
75
+ if participants.present? && conversions.present?
76
+ (participants.to_f/conversions.to_f).round(2)
77
+ end
78
+ end
79
+
80
+ # 90 percent error
81
+ def error
82
+
83
+ end
60
84
  end
61
85
 
62
86
 
metadata CHANGED
@@ -1,20 +1,18 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simple_abs
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
5
- prerelease:
4
+ version: 0.0.2
6
5
  platform: ruby
7
6
  authors:
8
7
  - nate
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-04-16 00:00:00.000000000 Z
11
+ date: 2014-04-18 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: bundler
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
17
  - - ~>
20
18
  - !ruby/object:Gem::Version
@@ -22,7 +20,6 @@ dependencies:
22
20
  type: :development
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
24
  - - ~>
28
25
  - !ruby/object:Gem::Version
@@ -30,7 +27,6 @@ dependencies:
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: rake
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
31
  - - ! '>='
36
32
  - !ruby/object:Gem::Version
@@ -38,7 +34,6 @@ dependencies:
38
34
  type: :development
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
38
  - - ! '>='
44
39
  - !ruby/object:Gem::Version
@@ -63,26 +58,25 @@ files:
63
58
  homepage: ''
64
59
  licenses:
65
60
  - MIT
61
+ metadata: {}
66
62
  post_install_message:
67
63
  rdoc_options: []
68
64
  require_paths:
69
65
  - lib
70
66
  required_ruby_version: !ruby/object:Gem::Requirement
71
- none: false
72
67
  requirements:
73
68
  - - ! '>='
74
69
  - !ruby/object:Gem::Version
75
70
  version: '0'
76
71
  required_rubygems_version: !ruby/object:Gem::Requirement
77
- none: false
78
72
  requirements:
79
73
  - - ! '>='
80
74
  - !ruby/object:Gem::Version
81
75
  version: '0'
82
76
  requirements: []
83
77
  rubyforge_project:
84
- rubygems_version: 1.8.24
78
+ rubygems_version: 2.2.2
85
79
  signing_key:
86
- specification_version: 3
80
+ specification_version: 4
87
81
  summary: Really simple way to do AB tests in Rails
88
82
  test_files: []