easy_ab 0.0.3 → 0.1.0
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +3 -0
- data/README.md +37 -9
- data/lib/easy_ab/experiment.rb +11 -7
- data/lib/easy_ab/version.rb +1 -1
- data/lib/generators/easy_ab/templates/easy_ab.rb +9 -9
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: be25942ed3b823b7bf8b4445eee642f884d6cff2
|
4
|
+
data.tar.gz: dc77331ec7b69a4a4c0f3cca37e3d7cd46b922bc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 780ccb7138c2e6d0671fe6d2b1eda79cd04b68e517c941e22ce4fab91a89b31a937297a0e5f103e947db5c6d3e23fcdd3f33b0262f890039a6d90118d2674920
|
7
|
+
data.tar.gz: 11c2df2ef9ab91699e7c52b05894aff91fcaeb273d82a4adccee60849a943824f8b6cd2e42323501d8ef6f33ff059b61b604da29563b0cfeb0c93b2420403822
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -7,8 +7,7 @@ Easy, flexible A/B testing tool for Rails.
|
|
7
7
|
* Grouping your users to your predefined variants with very easy and flexible way:
|
8
8
|
* Random with equal weightings.
|
9
9
|
* Random with predefined weightings.
|
10
|
-
* Define Proc(s) to setup your rules. Something like "sign up for 1 month to variant A, others to variant B", "user with odd id to variant A, with even id to variant B",
|
11
|
-
Example of using proc to define rules:
|
10
|
+
* Define Proc(s) to setup your rules. Something like "sign up for 1 month to variant A, others to variant B", "user with odd id to variant A, with even id to variant B", ..., etc. Example of using proc to define rules:
|
12
11
|
|
13
12
|
```ruby
|
14
13
|
# Example 1
|
@@ -30,9 +29,10 @@ Easy, flexible A/B testing tool for Rails.
|
|
30
29
|
* check your view for different variants
|
31
30
|
* output all experiments and the corresponding variants for your users. It's very useful when sending data to analytics services like Google Anayltics, Mixpanel, Kissmetrics, ...
|
32
31
|
* No DSL, just setup your rules with pure Ruby (and Rails) :)
|
32
|
+
* Supports Rails 4 and 5
|
33
33
|
|
34
|
-
#
|
35
|
-
|
34
|
+
# Changelog
|
35
|
+
[Click me](https://github.com/icarus4/easy_ab/blob/master/CHANGELOG.md)
|
36
36
|
|
37
37
|
# Installation & Setup
|
38
38
|
|
@@ -69,7 +69,7 @@ EasyAb.experiments do |experiment|
|
|
69
69
|
end
|
70
70
|
```
|
71
71
|
|
72
|
-
Then you will be able to use
|
72
|
+
Then you will be able to use `ab_test` helpers in controller or view:
|
73
73
|
|
74
74
|
```ruby
|
75
75
|
color = ab_test(:button_color)
|
@@ -79,7 +79,7 @@ or pass a block
|
|
79
79
|
|
80
80
|
```erb
|
81
81
|
<% ab_test(:button_color) do |color| %>
|
82
|
-
<
|
82
|
+
<button class="<%= color %>">Click Me!</button>
|
83
83
|
<% end %>
|
84
84
|
```
|
85
85
|
|
@@ -114,13 +114,38 @@ EasyAb.experiments do |experiment|
|
|
114
114
|
end
|
115
115
|
```
|
116
116
|
|
117
|
+
NOTICE: rules are executed in the order you defined in `config/initializers/easy_ab.rb`. If there are intersections among your rules, the former rule will be applied. For example:
|
118
|
+
|
119
|
+
```ruby
|
120
|
+
EasyAb.experiments do |experiment|
|
121
|
+
experiment.define :extra_vip_duration,
|
122
|
+
variants: ['90', '30']
|
123
|
+
rules: [
|
124
|
+
-> { current_user.id <= 20 },
|
125
|
+
-> { current_user.id > 10 }
|
126
|
+
]
|
127
|
+
|
128
|
+
# Users with id between 11 to 20 matches both lambdas, will get variant '90'
|
129
|
+
```
|
130
|
+
|
117
131
|
Keep in mind that `ab_test()` helper always returns String. You have to handle the type conversion by yourself.
|
118
132
|
|
119
|
-
```
|
133
|
+
```ruby
|
120
134
|
# In controller
|
121
135
|
@extra_vip_duration = ab_test(:extra_vip_duration).to_i.days
|
122
136
|
```
|
123
137
|
|
138
|
+
|
139
|
+
When an experiment is finished, you can remove the experiment from `easy_ab.rb`, or specify the winner. `ab_test()` always returns the winner:
|
140
|
+
|
141
|
+
```ruby
|
142
|
+
EasyAb.experiments do |experiment|
|
143
|
+
experiment.define :button_color,
|
144
|
+
variants: ['red', 'blue', 'green'],
|
145
|
+
winner: 'red'
|
146
|
+
end
|
147
|
+
```
|
148
|
+
|
124
149
|
You can dump experiment data of current user to analytics services (Mixpanel, Google Analytics, etc.) by `all_participated_experiments`
|
125
150
|
|
126
151
|
```erb
|
@@ -134,7 +159,7 @@ You can dump experiment data of current user to analytics services (Mixpanel, Go
|
|
134
159
|
</script>
|
135
160
|
```
|
136
161
|
|
137
|
-
The return format of `all_participated_experiments
|
162
|
+
The return format of `all_participated_experiments`:
|
138
163
|
|
139
164
|
```ruby
|
140
165
|
{
|
@@ -189,4 +214,7 @@ ab_test(:button_color).class # => String
|
|
189
214
|
# Todo
|
190
215
|
* Add comparisons with existing A/B testing gems
|
191
216
|
* Convertion rate
|
192
|
-
* Test code
|
217
|
+
* Test code
|
218
|
+
|
219
|
+
# Copyright
|
220
|
+
MIT License © 2017 Gary Chu (icarus4).
|
data/lib/easy_ab/experiment.rb
CHANGED
@@ -1,17 +1,19 @@
|
|
1
1
|
module EasyAb
|
2
2
|
class Experiment
|
3
|
-
attr_reader :name, :variants, :weights, :rules
|
3
|
+
attr_reader :name, :variants, :weights, :rules, :winner
|
4
4
|
|
5
5
|
def initialize(name, options = {})
|
6
|
-
@name
|
7
|
-
@variants = options[:variants]
|
8
|
-
@weights
|
9
|
-
@rules
|
6
|
+
@name = name.to_s
|
7
|
+
@variants = options[:variants].map(&:to_s)
|
8
|
+
@weights = options[:weights]
|
9
|
+
@rules = options[:rules]
|
10
|
+
@winner = options[:winner].nil? ? nil : options[:winner].to_s
|
10
11
|
|
11
12
|
raise ArgumentError, 'Please define variants' if @variants.blank?
|
12
13
|
raise ArgumentError, 'Number of variants and weights should be identical' if @weights.present? && @weights.size != @variants.size
|
13
14
|
raise ArgumentError, 'Number of variants and rules should be identical' if @rules.present? && @rules.size != @variants.size
|
14
15
|
raise ArgumentError, 'All rules should be a Proc' if @rules.present? && @rules.any? { |rule| !rule.is_a?(Proc) }
|
16
|
+
raise ArgumentError, 'winner should be one of variants' if @winner && !@variants.include?(@winner)
|
15
17
|
end
|
16
18
|
|
17
19
|
def self.find_by_name!(experiment_name)
|
@@ -22,10 +24,12 @@ module EasyAb
|
|
22
24
|
end
|
23
25
|
|
24
26
|
def assign_variant(user_recognition, options = {})
|
27
|
+
return winner if winner
|
28
|
+
|
25
29
|
grouping = find_grouping_by_user_recognition(user_recognition) || ::EasyAb::Grouping.new(experiment: name, user_id: user_recognition[:id], cookie: user_recognition[:cookie])
|
26
30
|
|
27
|
-
if options[:variant] && variants.include?(options[:variant])
|
28
|
-
grouping.variant = options[:variant]
|
31
|
+
if options[:variant] && variants.include?(options[:variant].to_s)
|
32
|
+
grouping.variant = options[:variant].to_s
|
29
33
|
else
|
30
34
|
grouping.variant ||= flexible_variant(options[:contexted_rules])
|
31
35
|
end
|
data/lib/easy_ab/version.rb
CHANGED
@@ -11,14 +11,14 @@ EasyAb.configure do |config|
|
|
11
11
|
end
|
12
12
|
|
13
13
|
EasyAb.experiments do |experiment|
|
14
|
-
experiment.define :button_color,
|
15
|
-
|
16
|
-
|
14
|
+
# experiment.define :button_color,
|
15
|
+
# variants: ['red', 'blue', 'yellow'],
|
16
|
+
# weights: [8, 1, 1]
|
17
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
|
-
|
22
|
-
|
23
|
-
]
|
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
|
+
# ]
|
24
24
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: easy_ab
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gary Chu
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-08-
|
11
|
+
date: 2017-08-09 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description:
|
14
14
|
email: icarus4.chu@gmail.com
|