easy_ab 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bb6587e7ae47d2f3743e6dc6e6c053e40f993ac2
4
- data.tar.gz: f74132d722d8dbb9f7dc275748770ecef6e406b1
3
+ metadata.gz: 50e5179b65bec859cfb55ecec25e5fd7698619ff
4
+ data.tar.gz: a938f51b36faa0c46cf31a02d0a831ecef4e8c9e
5
5
  SHA512:
6
- metadata.gz: 7c88e4fd12e3c20de12c8a00cae041ca279080501b0f57869b345f651b7b83cb695d21d02ad6b940ed5f9501993afa92e3eb52eb8dafd2fc52718ddb1ff45456
7
- data.tar.gz: 2e0014482e2275c87bcabeb39cbc90f78012d6338ddf2075e4c22de991c90a7554580c7d4a8f052cc65457724355606c8951c88d7c717c693307cfda92a6184a
6
+ metadata.gz: aa8c33658ef5294a3de560dcffe5fb085c9746382dbd60b00e7b1f9d223f7801fc55c81372032601e7136a25946ccfbeb3428afd45ce2861c053a1b3dc347fcb
7
+ data.tar.gz: 87e59b21a23a6748434bc3fe288edf83aab6e2150d4323915a5286232e78b876252aecf40cf3a2c384b2f987c214e3f62a6ef53ac117e93d6bf3c06f2c94cdec
data/README.md CHANGED
@@ -41,15 +41,12 @@ Easy AB is under development. Currently don't use in your production app.
41
41
  ### Flipper
42
42
  ### ...
43
43
 
44
- # Installation
44
+ # Installation & Setup
45
45
 
46
46
  * Add `gem 'easy_ab'` to your application's Gemfile and run `bundle install`.
47
47
  * Run `bin/rails g easy_ab:install`. Migration file and initializer will copy to your app folder.
48
48
  * Run `bin/rake db:migrate`
49
-
50
- # Setup
51
-
52
- Edit `config/initializers/easy_ab.rb` to setup basic configurations.
49
+ * Edit `config/initializers/easy_ab.rb` to setup basic configurations.
53
50
 
54
51
  ```ruby
55
52
  EasyAb.configure do |config|
@@ -65,30 +62,30 @@ EasyAb.configure do |config|
65
62
  end
66
63
  ```
67
64
 
68
- # Getting Started
65
+ # Usage
69
66
 
70
- Setup your experiments in `config/initializers/easy_ab.rb`
67
+ Define your experiments in `config/initializers/easy_ab.rb`
71
68
 
72
- Say, if you have an experiment named 'button color', with three equal weighted variants: red, blue, green.
69
+ Say, if you have an experiment named 'button_color', with three equal weighted variants: red, blue, green.
73
70
 
74
71
  Define your experiment as follows:
75
72
 
76
73
  ``` ruby
77
74
  EasyAb.experiments do |experiment|
78
- experiment.define :title_color, variants: ['red', 'blue', 'green']
75
+ experiment.define :button_color, variants: ['red', 'blue', 'green']
79
76
  end
80
77
  ```
81
78
 
82
79
  Then you will be able to use the following helpers in controller or view:
83
80
 
84
81
  ```ruby
85
- color = ab_test(:title_color)
82
+ color = ab_test(:button_color)
86
83
  ```
87
84
 
88
85
  or pass a block
89
86
 
90
87
  ```erb
91
- <% ab_test(:title_color) do |color| %>
88
+ <% ab_test(:button_color) do |color| %>
92
89
  <h1 class="<%= color %>">Welcome!</h1>
93
90
  <% end %>
94
91
  ```
@@ -96,5 +93,79 @@ or pass a block
96
93
  For admin, specify a variant with url parameters makes debugging super easy:
97
94
 
98
95
  ```
99
- ?ab_test[title_color]=blue
96
+ ?ab_test[button_color]=blue
97
+ ```
98
+
99
+ You can specify weightings of each variant:
100
+
101
+ ``` ruby
102
+ EasyAb.experiments do |experiment|
103
+ experiment.define :button_color,
104
+ variants: ['red', 'blue', 'green'],
105
+ weights: [8, 1, 1] # Weights of variants can be any positive integers
106
+ end
107
+ ```
108
+
109
+ Then 80% of your users will see red button, and 10% for blue and green respectively.
110
+
111
+ Also, by specifying rules with Proc or lambda, you can split users with more flexible way. For example, for the first 100 signed up users, if you wanna provide extra 90 days of paid features for them whenever they subscribe your service, and other users for extra 30 days:
112
+
113
+ ```ruby
114
+ EasyAb.experiments do |experiment|
115
+ experiment.define :extra_vip_duration,
116
+ variants: ['90', '30'], # Variants are stored as string, you have handle the type conversion by yourself
117
+ rules: [
118
+ -> { current_user.id <= 100 },
119
+ -> { current_user.id > 100 }
120
+ ]
121
+ end
122
+ ```
123
+
124
+ Keep in mind that `ab_test()` helper always returns String. You have to handle the type conversion by yourself.
125
+
126
+ ```erb
127
+ # In controller
128
+ @extra_vip_duration = ab_test(:extra_vip_duration).to_i.days
129
+ ```
130
+
131
+ # Others
132
+ ## Type of experiments
133
+ Both String and Symbol are valid when defining experiment or passing to `ab_test`.
134
+
135
+ ```ruby
136
+ # Define experiment as symbol (recommended)
137
+ EasyAb.experiments do |experiment|
138
+ experiment.define :button_color,
139
+ variants: ['red', 'blue', 'green']
140
+ end
141
+
142
+ # In view/controller
143
+ ab_test(:button_color) # OK (recommended)
144
+ ab_test('button_color') # OK
145
+ ```
146
+
147
+ ```ruby
148
+ # Define experiment as String
149
+ EasyAb.experiments do |experiment|
150
+ experiment.define 'button_color',
151
+ variants: ['red', 'blue', 'green']
152
+ end
153
+
154
+ # In view/controller
155
+ ab_test(:button_color) # OK
156
+ ab_test('button_color') # OK
157
+ ```
158
+
159
+ ## Type of variants
160
+ You can define variants as Symbol, but `ab_test()` always returns String
161
+
162
+ ```ruby
163
+ # Define variants as symbol
164
+ EasyAb.experiments do |experiment|
165
+ experiment.define :button_color,
166
+ variants: [:red, :blue, :green]
167
+ end
168
+
169
+ # In view/controller
170
+ ab_test(:button_color).class # => String
100
171
  ```
@@ -1,3 +1,3 @@
1
1
  module EasyAb
2
- VERSION = '0.0.1'
2
+ VERSION = '0.0.2'
3
3
  end
@@ -12,15 +12,13 @@ end
12
12
 
13
13
  EasyAb.experiments do |experiment|
14
14
  experiment.define :button_color,
15
- variants: ['red', 'blue', 'yellow'],
16
- weights: [10, 3, 1]
17
-
18
- experiment.define :title,
19
- variants: ['hello', 'welcome', 'yo'],
20
- rules: [
21
- -> { (1..100).cover?(current_user.id) },
22
- -> { current_user.id.odd? },
23
- -> { current_user.id.even? },
24
- ]
15
+ variants: ['red', 'blue', 'yellow'],
16
+ weights: [8, 1, 1]
25
17
 
18
+ experiment.define :extra_vip_duration,
19
+ variants: ['90', '30'], # Variants stored as String, you must handle the conversion in your app by yourself
20
+ rules: [
21
+ -> { current_user.id <= 100 },
22
+ -> { current_user.id > 100 }
23
+ ]
26
24
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: easy_ab
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gary Chu