split 3.2.0 → 4.0.5

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.
Files changed (87) hide show
  1. checksums.yaml +5 -5
  2. data/.eslintrc +1 -1
  3. data/.github/FUNDING.yml +1 -0
  4. data/.github/ISSUE_TEMPLATE/bug_report.md +24 -0
  5. data/.github/dependabot.yml +7 -0
  6. data/.github/workflows/ci.yml +63 -0
  7. data/.rspec +1 -0
  8. data/.rubocop.yml +67 -1043
  9. data/CHANGELOG.md +174 -0
  10. data/CODE_OF_CONDUCT.md +3 -3
  11. data/CONTRIBUTING.md +1 -1
  12. data/Gemfile +6 -1
  13. data/README.md +79 -33
  14. data/Rakefile +6 -5
  15. data/lib/split/algorithms/block_randomization.rb +7 -6
  16. data/lib/split/algorithms/weighted_sample.rb +2 -1
  17. data/lib/split/algorithms/whiplash.rb +17 -18
  18. data/lib/split/algorithms.rb +14 -0
  19. data/lib/split/alternative.rb +25 -25
  20. data/lib/split/cache.rb +27 -0
  21. data/lib/split/combined_experiments_helper.rb +6 -5
  22. data/lib/split/configuration.rb +94 -91
  23. data/lib/split/dashboard/helpers.rb +9 -9
  24. data/lib/split/dashboard/pagination_helpers.rb +86 -0
  25. data/lib/split/dashboard/paginator.rb +17 -0
  26. data/lib/split/dashboard/public/dashboard.js +10 -0
  27. data/lib/split/dashboard/public/style.css +19 -2
  28. data/lib/split/dashboard/views/_controls.erb +13 -0
  29. data/lib/split/dashboard/views/_experiment.erb +2 -1
  30. data/lib/split/dashboard/views/index.erb +24 -5
  31. data/lib/split/dashboard/views/layout.erb +1 -1
  32. data/lib/split/dashboard.rb +47 -20
  33. data/lib/split/encapsulated_helper.rb +15 -8
  34. data/lib/split/engine.rb +7 -4
  35. data/lib/split/exceptions.rb +1 -0
  36. data/lib/split/experiment.rb +160 -122
  37. data/lib/split/experiment_catalog.rb +7 -8
  38. data/lib/split/extensions/string.rb +2 -1
  39. data/lib/split/goals_collection.rb +10 -10
  40. data/lib/split/helper.rb +56 -24
  41. data/lib/split/metric.rb +6 -6
  42. data/lib/split/persistence/cookie_adapter.rb +52 -15
  43. data/lib/split/persistence/dual_adapter.rb +53 -12
  44. data/lib/split/persistence/redis_adapter.rb +8 -4
  45. data/lib/split/persistence/session_adapter.rb +1 -2
  46. data/lib/split/persistence.rb +8 -6
  47. data/lib/split/redis_interface.rb +16 -31
  48. data/lib/split/trial.rb +48 -41
  49. data/lib/split/user.rb +30 -15
  50. data/lib/split/version.rb +2 -4
  51. data/lib/split/zscore.rb +2 -3
  52. data/lib/split.rb +39 -25
  53. data/spec/algorithms/block_randomization_spec.rb +6 -5
  54. data/spec/algorithms/weighted_sample_spec.rb +6 -5
  55. data/spec/algorithms/whiplash_spec.rb +4 -5
  56. data/spec/alternative_spec.rb +35 -36
  57. data/spec/cache_spec.rb +84 -0
  58. data/spec/combined_experiments_helper_spec.rb +18 -17
  59. data/spec/configuration_spec.rb +41 -45
  60. data/spec/dashboard/pagination_helpers_spec.rb +202 -0
  61. data/spec/dashboard/paginator_spec.rb +38 -0
  62. data/spec/dashboard_helpers_spec.rb +19 -18
  63. data/spec/dashboard_spec.rb +153 -48
  64. data/spec/encapsulated_helper_spec.rb +47 -23
  65. data/spec/experiment_catalog_spec.rb +14 -13
  66. data/spec/experiment_spec.rb +224 -111
  67. data/spec/goals_collection_spec.rb +18 -16
  68. data/spec/helper_spec.rb +539 -419
  69. data/spec/metric_spec.rb +14 -14
  70. data/spec/persistence/cookie_adapter_spec.rb +105 -27
  71. data/spec/persistence/dual_adapter_spec.rb +158 -66
  72. data/spec/persistence/redis_adapter_spec.rb +35 -27
  73. data/spec/persistence/session_adapter_spec.rb +2 -3
  74. data/spec/persistence_spec.rb +1 -2
  75. data/spec/redis_interface_spec.rb +25 -82
  76. data/spec/spec_helper.rb +38 -24
  77. data/spec/split_spec.rb +18 -18
  78. data/spec/support/cookies_mock.rb +1 -2
  79. data/spec/trial_spec.rb +117 -70
  80. data/spec/user_spec.rb +69 -27
  81. data/split.gemspec +26 -22
  82. metadata +85 -37
  83. data/.travis.yml +0 -41
  84. data/Appraisals +0 -13
  85. data/gemfiles/4.2.gemfile +0 -9
  86. data/gemfiles/5.0.gemfile +0 -10
  87. data/gemfiles/5.1.gemfile +0 -10
data/CHANGELOG.md CHANGED
@@ -1,3 +1,177 @@
1
+ # 4.0.5 (Aug 3rd, 2025)
2
+
3
+ Bugfixes:
4
+ - Handle when Rails is partially loaded as a Gem. (@bjacobs09, #727)
5
+ - Fix Rack compatibility with versions > 3 (@andrehjr, #729)
6
+
7
+ Misc:
8
+ - Add funding_uri to gemspec (@andrew, #726)
9
+ - Drop Rails 5.x Support (@andrehjr, #728)
10
+ - Drop Rails 6.0 and Ruby < 2.6 (@andrehjr, #729)
11
+ - Add support for Ruby 3.5+ (@andrehjr, #737)
12
+
13
+ # 4.0.4 (March 3rd, 2024)
14
+
15
+ Bugfixes:
16
+ - Better integration for EncapsulatedHelper when needing params/request info (@henrique-ft, #721 and #723)
17
+
18
+ Misc:
19
+ - Make specs compatible with newer Rack versions (@andrehjr, #722)
20
+
21
+ # 4.0.3 (November 15th, 2023)
22
+
23
+ Bugfixes:
24
+ - Do not throw error if alternativas have data that can lead to negative numbers for probability calculation (@andrehjr, #703)
25
+ - Do not persist invalid extra_info on ab_record_extra_info. (@trostli @andrehjr, #717)
26
+ - CROSSSLOT keys issue fix when using redis cluster (@naveen-chidhambaram, #710)
27
+ - Convert value to string before saving it in RedisAdapter (@Jealrock, #714)
28
+ - Fix deprecation warning with Redis 4.8.0 (@martingregoire, #701)
29
+
30
+ Misc:
31
+ - Add matrix as a default dependency (@andrehjr, #705)
32
+ - Add Ruby 3.2 to Github Actions (@andrehjr, #702)
33
+ - Update documentation regarding finding users outside a web session (@andrehjr, #716)
34
+ - Update actions/checkout to v4 (@andrehjr, #718)
35
+
36
+ # 4.0.2 (December 2nd, 2022)
37
+
38
+ Bugfixes:
39
+ - Stop crashing on non-hash json (@knarewski, #697)
40
+ - Handle when Rails is partially loaded as a Gem (@TSMMark, #687)
41
+
42
+ Features:
43
+ - Add support for redis-client, which does not automatically cast types to strings (@knarewski, #696)
44
+ - Add ability to initialize experiments (@robin-phung, #673)
45
+
46
+ Misc:
47
+ - Fix default branch name and gem metadata indentation (@ursm, #693)
48
+ - Update actions/checkout to v3 (@andrehjr, #683)
49
+ - Enforce double quotes (@andrehjr, #682)
50
+ - Fix Rubocop Style/* Offenses (@andrehjr, #681)
51
+ - Enable rubocop on Github Actions (@andrehjr, #680)
52
+ - Fix all Layout issues on the project (@andrehjr, #679)
53
+ - Fix Style/HashSyntax offenses (@andrehjr, #678)
54
+ - Remove usage of deprecated implicit block expectation from specs (@andrehjr, #677)
55
+ - Remove appraisals configuration (@andrehjr, #676)
56
+ - Add Ruby 3.1 (@andrehjr, #675)
57
+ - Encapsulate Split::Algorithms at our own module to avoid explicit calling rubystats everywhere (@andrehjr, #674)
58
+
59
+ ## 4.0.1 (December 30th, 2021)
60
+
61
+ Bugfixes:
62
+ - ab_test must return metadata on error or if split is disabled/excluded user (@andrehjr, #622)
63
+ - Fix versioned experiments when used with allow_multiple_experiments=control (@andrehjr, #613)
64
+ - Only block Pinterest bot (@huoxito, #606)
65
+ - Respect experiment defaults when loading experiments in initializer. (@mattwd7, #599)
66
+ - Removes metadata key when it updated to nil (@andrehjr, #633)
67
+ - Force experiment does not count for metrics (@andrehjr, #637)
68
+ - Fix cleanup_old_versions! misbehaviour (@serggl, #661)
69
+
70
+ Features:
71
+ - Make goals accessible via on_trial_complete callbacks (@robin-phung, #625)
72
+ - Replace usage of SimpleRandom with RubyStats(Used for Beta Distribution RNG) (@andrehjr, #616)
73
+ - Introduce enable/disable experiment cohorting (@robin-phung, #615)
74
+ - Add on_experiment_winner_choose callback (@GenaMinenkov, #574)
75
+ - Add Split::Cache to reduce load on Redis (@rdh, #648)
76
+ - Caching based optimization in the experiment#save path (@amangup, #652)
77
+ - Adds config option for cookie domain (@joedelia, #664)
78
+
79
+ Misc:
80
+ - Drop support for Ruby < 2.5 (@andrehjr, #627)
81
+ - Drop support for Rails < 5 (@andrehjr, #607)
82
+ - Bump minimum required redis to 4.2 (@andrehjr, #628)
83
+ - Removed repeated loading from config (@robin-phung, #619)
84
+ - Simplify RedisInterface usage when persisting Experiment alternatives (@andrehjr, #632)
85
+ - Remove redis_url impl. Deprecated on version 2.2 (@andrehjr, #631)
86
+ - Remove thread_safe config as redis-rb is thread_safe by default (@andrehjr, #630)
87
+ - Fix typo of in `Split::Trial` class variable (TomasBarry, #644)
88
+ - Single HSET to update values, instead of multiple ones (@andrehjr, #640)
89
+ - Use Redis#hmset to keep compatibility with Redis < 4.0 (@andrehjr, #659)
90
+ - Remove 'set' parsing for alternatives. Sets were used as storage and deprecated on 0.x (@andrehjr, #639)
91
+ - Adding documentation related to what is stored on cookies. (@andrehjr, #634)
92
+ - Keep railtie defined under the Split gem namespace (@avit, #666)
93
+ - Update RSpec helper to support block syntax (@clowder, #665)
94
+
95
+ ## 3.4.1 (November 12th, 2019)
96
+
97
+ Bugfixes:
98
+ - Reference ActionController directly when including split helpers, to avoid breaking Rails API Controllers (@andrehjr, #602)
99
+
100
+ ## 3.4.0 (November 9th, 2019)
101
+
102
+ Features:
103
+ - Improve DualAdapter (@santib, #588), adds a new configuration for the DualAdapter, making it possible to keep consistency for logged_out/logged_in users. It's a opt-in flag. No Behavior was changed on this release.
104
+ - Make dashboard pagination default "per" param configurable (@alopatin, #597)
105
+
106
+ Bugfixes:
107
+ - Fix `force_alternative` for experiments with incremented version (@giraffate, #568)
108
+ - Persist alternative weights (@giraffate, #570)
109
+ - Combined experiment performance improvements (@gnanou, #575)
110
+ - Handle correctly case when ab_finished is called before ab_test for a user (@gnanou, #577)
111
+ - When loading active_experiments, it should not look into user's 'finished' keys (@andrehjr, #582)
112
+
113
+ Misc:
114
+ - Remove `rubyforge_project` from gemspec (@giraffate, #583)
115
+ - Fix URLs to replace http with https (@giraffate , #584)
116
+ - Lazily include split helpers in ActionController::Base (@hasghari, #586)
117
+ - Fix unused variable warnings (@andrehjr, #592)
118
+ - Fix ruby warnings (@andrehjr, #593)
119
+ - Update rubocop.yml config (@andrehjr, #594)
120
+ - Add frozen_string_literal to all files that were missing it (@andrehjr, #595)
121
+
122
+ ## 3.3.2 (April 12th, 2019)
123
+
124
+ Features:
125
+ - Added uptime robot to configuration.rb (@razel1982, #556)
126
+ - Check to see if being run in Rails application and run in before_initialize (@husteadrobert, #555)
127
+
128
+ Bugfixes:
129
+ - Fix error message interpolation (@hanibash, #553)
130
+ - Fix Bigdecimal warnings (@agraves, #551)
131
+ - Avoid hitting up on redis for robots/excluded users. (@andrehjr, #544)
132
+ - Checks for defined?(request) on Helper#exclude_visitor?. (@andrehjr)
133
+
134
+ Misc:
135
+ - Update travis to add Rails 6 (@edmilton, #559)
136
+ - Fix broken specs in developement environment (@dougpetronilio, #557)
137
+
138
+ ## 3.3.1 (January 11th, 2019)
139
+
140
+ Features:
141
+ - Filter some more bots (@janosch-x, #542)
142
+
143
+ Bugfixes:
144
+ - Fix Dashboard Pagination Helper typo (@cattekin, #541)
145
+ - Do not storage alternative in cookie if experiment has a winner (@sadhu89, #539)
146
+ - fix user participating alternative not found (@NaturalHokke, #536)
147
+
148
+ Misc:
149
+ - Tweak RSpec instructions (@eliotsykes, #540)
150
+ - Improve README regarding rspec usage (@vermaxik, #538)
151
+
152
+ ## 3.3.0 (August 13th, 2018)
153
+
154
+ Features:
155
+
156
+ - Added pagination for dashboard (@GeorgeGorbanev, #518)
157
+ - Add Facebot crawler to list of bots (@pfeiffer, #530)
158
+ - Ignore previewing requests (@pfeiffer, #531)
159
+ - Fix binding of ignore_filter (@pfeiffer, #533)
160
+
161
+ Bugfixes:
162
+
163
+ - Fix cookie header duplication (@andrehjr, #522)
164
+
165
+ Performance:
166
+
167
+ - Improve performance of RedisInterface#make_list_length by using LTRIM command (@mlovic, #509)
168
+
169
+ Misc:
170
+
171
+ - Update development dependencies
172
+ - test rails 5.2 on travis (@lostapathy, #524)
173
+ - update ruby versions for travis (@lostapathy, #525)
174
+
1
175
  ## 3.2.0 (September 21st, 2017)
2
176
 
3
177
  Features:
data/CODE_OF_CONDUCT.md CHANGED
@@ -68,7 +68,7 @@ members of the project's leadership.
68
68
  ## Attribution
69
69
 
70
70
  This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
- available at [http://contributor-covenant.org/version/1/4][version]
71
+ available at [https://contributor-covenant.org/version/1/4][version]
72
72
 
73
- [homepage]: http://contributor-covenant.org
74
- [version]: http://contributor-covenant.org/version/1/4/
73
+ [homepage]: https://contributor-covenant.org
74
+ [version]: https://contributor-covenant.org/version/1/4/
data/CONTRIBUTING.md CHANGED
@@ -25,7 +25,7 @@ Want to contribute to Split? That's great! Here are a couple of guidelines that
25
25
 
26
26
  ## Setup instructions
27
27
 
28
- You can find in-depth instructions to install in our [README](https://github.com/splitrb/split/blob/master/README.md).
28
+ You can find in-depth instructions to install in our [README](https://github.com/splitrb/split/blob/main/README.md).
29
29
 
30
30
  *Note*: Split requires Ruby 1.9.2 or higher.
31
31
 
data/Gemfile CHANGED
@@ -1,6 +1,11 @@
1
+ # frozen_string_literal: true
2
+
1
3
  source "https://rubygems.org"
2
4
 
3
5
  gemspec
4
6
 
5
- gem "appraisal"
7
+ gem "rubocop", require: false
6
8
  gem "codeclimate-test-reporter"
9
+ gem "concurrent-ruby", "< 1.3.5"
10
+
11
+ gem "rails", "~> #{ENV.fetch('RAILS_VERSION', '8.0')}"
data/README.md CHANGED
@@ -1,12 +1,13 @@
1
- # [Split](http://libraries.io/rubygems/split)
1
+ # [Split](https://libraries.io/rubygems/split)
2
2
 
3
3
  [![Gem Version](https://badge.fury.io/rb/split.svg)](http://badge.fury.io/rb/split)
4
- [![Build Status](https://secure.travis-ci.org/splitrb/split.svg?branch=master)](http://travis-ci.org/splitrb/split)
4
+ ![Build status](https://github.com/splitrb/split/actions/workflows/ci.yml/badge.svg?branch=main)
5
5
  [![Code Climate](https://codeclimate.com/github/splitrb/split/badges/gpa.svg)](https://codeclimate.com/github/splitrb/split)
6
6
  [![Test Coverage](https://codeclimate.com/github/splitrb/split/badges/coverage.svg)](https://codeclimate.com/github/splitrb/split/coverage)
7
7
  [![standard-readme compliant](https://img.shields.io/badge/readme%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/RichardLitt/standard-readme)
8
+ [![Open Source Helpers](https://www.codetriage.com/splitrb/split/badges/users.svg)](https://www.codetriage.com/splitrb/split)
8
9
 
9
- > 📈 The Rack Based A/B testing framework http://libraries.io/rubygems/split
10
+ > 📈 The Rack Based A/B testing framework https://libraries.io/rubygems/split
10
11
 
11
12
  Split is a rack based A/B testing framework designed to work with Rails, Sinatra or any other rack based app.
12
13
 
@@ -18,11 +19,13 @@ Split is designed to be hacker friendly, allowing for maximum customisation and
18
19
 
19
20
  ### Requirements
20
21
 
21
- Split currently requires Ruby 1.9.3 or higher. If your project requires compatibility with Ruby 1.8.x and Rails 2.3, please use v0.8.0.
22
+ Split v4.0+ is currently tested with Ruby >= 2.5 and Rails >= 5.2.
23
+
24
+ If your project requires compatibility with Ruby 2.4.x or older Rails versions. You can try v3.0 or v0.8.0(for Ruby 1.9.3)
22
25
 
23
26
  Split uses Redis as a datastore.
24
27
 
25
- Split only supports Redis 2.0 or greater.
28
+ Split only supports Redis 4.0 or greater.
26
29
 
27
30
  If you're on OS X, Homebrew is the simplest way to install Redis:
28
31
 
@@ -109,9 +112,9 @@ Split has two options for you to use to determine which alternative is the best.
109
112
 
110
113
  The first option (default on the dashboard) uses a z test (n>30) for the difference between your control and alternative conversion rates to calculate statistical significance. This test will tell you whether an alternative is better or worse than your control, but it will not distinguish between which alternative is the best in an experiment with multiple alternatives. Split will only tell you if your experiment is 90%, 95%, or 99% significant, and this test only works if you have more than 30 participants and 5 conversions for each branch.
111
114
 
112
- As per this [blog post](http://www.evanmiller.org/how-not-to-run-an-ab-test.html) on the pitfalls of A/B testing, it is highly recommended that you determine your requisite sample size for each branch before running the experiment. Otherwise, you'll have an increased rate of false positives (experiments which show a significant effect where really there is none).
115
+ As per this [blog post](https://www.evanmiller.org/how-not-to-run-an-ab-test.html) on the pitfalls of A/B testing, it is highly recommended that you determine your requisite sample size for each branch before running the experiment. Otherwise, you'll have an increased rate of false positives (experiments which show a significant effect where really there is none).
113
116
 
114
- [Here](http://www.evanmiller.org/ab-testing/sample-size.html) is a sample size calculator for your convenience.
117
+ [Here](https://www.evanmiller.org/ab-testing/sample-size.html) is a sample size calculator for your convenience.
115
118
 
116
119
  The second option uses simulations from a beta distribution to determine the probability that the given alternative is the winner compared to all other alternatives. You can view these probabilities by clicking on the drop-down menu labeled "Confidence." This option should be used when the experiment has more than just 1 control and 1 alternative. It can also be used for a simple, 2-alternative A/B test.
117
120
 
@@ -158,15 +161,15 @@ In the event you want to disable all tests without having to know the individual
158
161
 
159
162
  It is not required to send `SPLIT_DISABLE=false` to activate Split.
160
163
 
161
- To aid testing with RSpec, write `split_helper.rb` and call `use_ab_test(alternatives_by_experiment)` in your specs as instructed below:
164
+
165
+ ### Rspec Helper
166
+ To aid testing with RSpec, write `spec/support/split_helper.rb` and call `use_ab_test(alternatives_by_experiment)` in your specs as instructed below:
162
167
 
163
168
  ```ruby
164
- # Recommended path for this file is 'spec/support/split_helper.rb', and you will need to ensure it
165
- # is `require`-d by rails_helper.rb or spec_helper.rb
169
+ # Create a file with these contents at 'spec/support/split_helper.rb'
170
+ # and ensure it is `require`d in your rails_helper.rb or spec_helper.rb
166
171
  module SplitHelper
167
172
 
168
- # Usage:
169
- #
170
173
  # Force a specific experiment alternative to always be returned:
171
174
  # use_ab_test(signup_form: "single_page")
172
175
  #
@@ -174,19 +177,29 @@ module SplitHelper
174
177
  # use_ab_test(signup_form: "single_page", pricing: "show_enterprise_prices")
175
178
  #
176
179
  def use_ab_test(alternatives_by_experiment)
177
- allow_any_instance_of(Split::Helper).to receive(:ab_test) do |_receiver, experiment|
178
- alternative =
179
- alternatives_by_experiment.fetch(experiment) { |key| raise "Unknown experiment '#{key}'" }
180
+ allow_any_instance_of(Split::Helper).to receive(:ab_test) do |_receiver, experiment, &block|
181
+ variant = alternatives_by_experiment.fetch(experiment) { |key| raise "Unknown experiment '#{key}'" }
182
+ block.call(variant) unless block.nil?
183
+ variant
180
184
  end
181
185
  end
182
186
  end
183
187
 
188
+ # Make the `use_ab_test` method available to all specs:
184
189
  RSpec.configure do |config|
185
- # Make the `use_ab_test` method available to all specs:
186
190
  config.include SplitHelper
187
191
  end
188
192
  ```
189
193
 
194
+ Now you can call `use_ab_test(alternatives_by_experiment)` in your specs, for example:
195
+ ```ruby
196
+ it "registers using experimental signup" do
197
+ use_ab_test experiment_name: "alternative_name"
198
+ post "/signups"
199
+ ...
200
+ end
201
+ ```
202
+
190
203
 
191
204
  ### Starting experiments manually
192
205
 
@@ -209,6 +222,12 @@ The user will then always see the alternative they started with.
209
222
 
210
223
  Any old unfinished experiment key will be deleted from the user's data storage if the experiment had been removed or is over and a winner had been chosen. This allows a user to enroll into any new experiment in cases when the `allow_multiple_experiments` config option is set to `false`.
211
224
 
225
+ ### Reset experiments manually
226
+
227
+ By default Split automatically resets the experiment whenever it detects the configuration for an experiment has changed (e.g. you call `ab_test` with different alternatives). You can prevent this by setting the option `reset_manually` to `true`.
228
+
229
+ You may want to do this when you want to change something, like the variants' names, the metadata about an experiment, etc. without resetting everything.
230
+
212
231
  ### Multiple experiments at once
213
232
 
214
233
  By default Split will avoid users participating in multiple experiments at once. This means you are less likely to skew results by adding in more variation to your tests.
@@ -248,7 +267,7 @@ Split.configure do |config|
248
267
  end
249
268
  ```
250
269
 
251
- By default, cookies will expire in 1 year. To change that, set the `persistence_cookie_length` in the configuration (unit of time in seconds).
270
+ When using the cookie persistence, Split stores data into an anonymous tracking cookie named 'split', which expires in 1 year. To change that, set the `persistence_cookie_length` in the configuration (unit of time in seconds).
252
271
 
253
272
  ```ruby
254
273
  Split.configure do |config|
@@ -257,6 +276,8 @@ Split.configure do |config|
257
276
  end
258
277
  ```
259
278
 
279
+ The data stored consists of the experiment name and the variants the user is in. Example: { "experiment_name" => "variant_a" }
280
+
260
281
  __Note:__ Using cookies depends on `ActionDispatch::Cookies` or any identical API
261
282
 
262
283
  #### Redis
@@ -345,7 +366,7 @@ end
345
366
 
346
367
  If you are running `ab_test` from a view, you must define your event
347
368
  hook callback as a
348
- [helper_method](http://apidock.com/rails/AbstractController/Helpers/ClassMethods/helper_method)
369
+ [helper_method](https://apidock.com/rails/AbstractController/Helpers/ClassMethods/helper_method)
349
370
  in the controller:
350
371
 
351
372
  ``` ruby
@@ -371,6 +392,8 @@ Split.configure do |config|
371
392
  # before experiment reset or deleted
372
393
  config.on_before_experiment_reset = -> (example) { # Do something on reset }
373
394
  config.on_before_experiment_delete = -> (experiment) { # Do something else on delete }
395
+ # after experiment winner had been set
396
+ config.on_experiment_winner_choose = -> (experiment) { # Do something on winner choose }
374
397
  end
375
398
  ```
376
399
 
@@ -388,7 +411,7 @@ run Rack::URLMap.new \
388
411
  "/split" => Split::Dashboard.new
389
412
  ```
390
413
 
391
- However, if you are using Rails 3: You can mount this inside your app routes by first adding this to the Gemfile:
414
+ However, if you are using Rails 3 or higher: You can mount this inside your app routes by first adding this to the Gemfile:
392
415
 
393
416
  ```ruby
394
417
  gem 'split', require: 'split/dashboard'
@@ -431,7 +454,7 @@ match "/split" => Split::Dashboard, anchor: false, via: [:get, :post, :delete],
431
454
  end
432
455
  ```
433
456
 
434
- More information on this [here](http://steve.dynedge.co.uk/2011/12/09/controlling-access-to-routes-and-rack-apps-in-rails-3-with-devise-and-warden/)
457
+ More information on this [here](https://steve.dynedge.co.uk/2011/12/09/controlling-access-to-routes-and-rack-apps-in-rails-3-with-devise-and-warden/)
435
458
 
436
459
  ### Screenshot
437
460
 
@@ -449,6 +472,7 @@ Split.configure do |config|
449
472
  config.enabled = true
450
473
  config.persistence = Split::Persistence::SessionAdapter
451
474
  #config.start_manually = false ## new test will have to be started manually from the admin panel. default false
475
+ #config.reset_manually = false ## if true, it never resets the experiment data, even if the configuration changes
452
476
  config.include_rails_helper = true
453
477
  config.redis = "redis://custom.redis.url:6380"
454
478
  end
@@ -475,7 +499,7 @@ Split.configure do |config|
475
499
  # IP config
476
500
  config.ignore_ip_addresses << '81.19.48.130' # or regex: /81\.19\.48\.[0-9]+/
477
501
 
478
- # or provide your own filter functionality, the default is proc{ |request| is_robot? || is_ignored_ip_address? }
502
+ # or provide your own filter functionality, the default is proc{ |request| is_robot? || is_ignored_ip_address? || is_preview? }
479
503
  config.ignore_filter = -> (request) { CustomExcludeLogic.excludes?(request) }
480
504
  end
481
505
  ```
@@ -540,7 +564,7 @@ and:
540
564
  ab_finished(:my_first_experiment)
541
565
  ```
542
566
 
543
- You can also add meta data for each experiment, very useful when you need more than an alternative name to change behaviour:
567
+ You can also add meta data for each experiment, which is very useful when you need more than an alternative name to change behaviour:
544
568
 
545
569
  ```ruby
546
570
  Split.configure do |config|
@@ -585,6 +609,8 @@ or in views:
585
609
  <% end %>
586
610
  ```
587
611
 
612
+ The keys used in meta data should be Strings
613
+
588
614
  #### Metrics
589
615
 
590
616
  You might wish to track generic metrics, such as conversions, and use
@@ -626,7 +652,7 @@ The API to define goals for an experiment is this:
626
652
  ab_test({link_color: ["purchase", "refund"]}, "red", "blue")
627
653
  ```
628
654
 
629
- or you can you can define them in a configuration file:
655
+ or you can define them in a configuration file:
630
656
 
631
657
  ```ruby
632
658
  Split.configure do |config|
@@ -662,8 +688,8 @@ Once you finish one of the goals, the test is considered to be completed, and fi
662
688
  **Bad Example**: Test both how button color affects signup *and* how it affects login, at the same time. THIS WILL NOT WORK.
663
689
 
664
690
  #### Combined Experiments
665
- If you want to test how how button color affects signup *and* how it affects login, at the same time. Use combined tests
666
- Configure like so
691
+ If you want to test how button color affects signup *and* how it affects login at the same time, use combined experiments.
692
+ Configure like so:
667
693
  ```ruby
668
694
  Split.configuration.experiments = {
669
695
  :button_color_experiment => {
@@ -734,6 +760,20 @@ split_config = YAML.load_file(Rails.root.join('config', 'split.yml'))
734
760
  Split.redis = split_config[Rails.env]
735
761
  ```
736
762
 
763
+ ### Redis Caching (v4.0+)
764
+
765
+ In some high-volume usage scenarios, Redis load can be incurred by repeated
766
+ fetches for fairly static data. Enabling caching will reduce this load.
767
+
768
+ ```ruby
769
+ Split.configuration.cache = true
770
+ ````
771
+
772
+ This currently caches:
773
+ - `Split::ExperimentCatalog.find`
774
+ - `Split::Experiment.start_time`
775
+ - `Split::Experiment.winner`
776
+
737
777
  ## Namespaces
738
778
 
739
779
  If you're running multiple, separate instances of Split you may want
@@ -750,7 +790,7 @@ library. To configure Split to use `Redis::Namespace`, do the following:
750
790
  ```
751
791
 
752
792
  2. Configure `Split.redis` to use a `Redis::Namespace` instance (possible in an
753
- intializer):
793
+ initializer):
754
794
 
755
795
  ```ruby
756
796
  redis = Redis.new(url: ENV['REDIS_URL']) # or whatever config you want
@@ -767,10 +807,16 @@ conduct experiments that are not tied to a web session.
767
807
  ```ruby
768
808
  # create a new experiment
769
809
  experiment = Split::ExperimentCatalog.find_or_create('color', 'red', 'blue')
810
+
811
+ # find the user
812
+ user = Split::User.find(user_id, :redis)
813
+
770
814
  # create a new trial
771
- trial = Split::Trial.new(:experiment => experiment)
815
+ trial = Split::Trial.new(user: user, experiment: experiment)
816
+
772
817
  # run trial
773
818
  trial.choose!
819
+
774
820
  # get the result, returns either red or blue
775
821
  trial.alternative.name
776
822
 
@@ -808,8 +854,8 @@ end
808
854
 
809
855
  ## Extensions
810
856
 
811
- - [Split::Export](http://github.com/splitrb/split-export) - Easily export A/B test data out of Split.
812
- - [Split::Analytics](http://github.com/splitrb/split-analytics) - Push test data to Google Analytics.
857
+ - [Split::Export](https://github.com/splitrb/split-export) - Easily export A/B test data out of Split.
858
+ - [Split::Analytics](https://github.com/splitrb/split-analytics) - Push test data to Google Analytics.
813
859
  - [Split::Mongoid](https://github.com/MongoHQ/split-mongoid) - Store experiment data in mongoid (still uses redis).
814
860
  - [Split::Cacheable](https://github.com/harrystech/split_cacheable) - Automatically create cache buckets per test.
815
861
  - [Split::Counters](https://github.com/bernardkroes/split-counters) - Add counters per experiment and alternative.
@@ -821,7 +867,7 @@ Ryan bates has produced an excellent 10 minute screencast about split on the Rai
821
867
 
822
868
  ## Blogposts
823
869
 
824
- * [Recipe: A/B testing with KISSMetrics and the split gem](http://robots.thoughtbot.com/post/9595887299/recipe-a-b-testing-with-kissmetrics-and-the-split-gem)
870
+ * [Recipe: A/B testing with KISSMetrics and the split gem](https://robots.thoughtbot.com/post/9595887299/recipe-a-b-testing-with-kissmetrics-and-the-split-gem)
825
871
  * [Rails A/B testing with Split on Heroku](http://blog.nathanhumbert.com/2012/02/rails-ab-testing-with-split-on-heroku.html)
826
872
 
827
873
  ## Backers
@@ -901,9 +947,9 @@ Please do! Over 70 different people have contributed to the project, you can see
901
947
 
902
948
  ### Development
903
949
 
904
- The source code is hosted at [GitHub](http://github.com/splitrb/split).
950
+ The source code is hosted at [GitHub](https://github.com/splitrb/split).
905
951
 
906
- Report issues and feature requests on [GitHub Issues](http://github.com/splitrb/split/issues).
952
+ Report issues and feature requests on [GitHub Issues](https://github.com/splitrb/split/issues).
907
953
 
908
954
  You can find a discussion form on [Google Groups](https://groups.google.com/d/forum/split-ruby).
909
955
 
@@ -934,4 +980,4 @@ Please note that this project is released with a [Contributor Code of Conduct](C
934
980
 
935
981
  ## Copyright
936
982
 
937
- [MIT License](LICENSE) © 2017 [Andrew Nesbitt](https://github.com/andrew).
983
+ [MIT License](LICENSE) © 2019 [Andrew Nesbitt](https://github.com/andrew).
data/Rakefile CHANGED
@@ -1,8 +1,9 @@
1
1
  #!/usr/bin/env rake
2
- require 'bundler/gem_tasks'
3
- require 'rspec/core/rake_task'
4
- require 'appraisal'
2
+ # frozen_string_literal: true
5
3
 
6
- RSpec::Core::RakeTask.new('spec')
4
+ require "bundler/gem_tasks"
5
+ require "rspec/core/rake_task"
7
6
 
8
- task :default => :spec
7
+ RSpec::Core::RakeTask.new("spec")
8
+
9
+ task default: :spec
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # Selects alternative with minimum count of participants
2
4
  # If all counts are even (i.e. all are minimum), samples from all possible alternatives
3
5
 
@@ -10,12 +12,11 @@ module Split
10
12
  end
11
13
 
12
14
  private
13
-
14
- def minimum_participant_alternatives(alternatives)
15
- alternatives_by_count = alternatives.group_by(&:participant_count)
16
- min_group = alternatives_by_count.min_by { |k, v| k }
17
- min_group.last
18
- end
15
+ def minimum_participant_alternatives(alternatives)
16
+ alternatives_by_count = alternatives.group_by(&:participant_count)
17
+ min_group = alternatives_by_count.min_by { |k, v| k }
18
+ min_group.last
19
+ end
19
20
  end
20
21
  end
21
22
  end
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module Split
3
4
  module Algorithms
4
5
  module WeightedSample
@@ -8,7 +9,7 @@ module Split
8
9
  total = weights.inject(:+)
9
10
  point = rand * total
10
11
 
11
- experiment.alternatives.zip(weights).each do |n,w|
12
+ experiment.alternatives.zip(weights).each do |n, w|
12
13
  return n if w >= point
13
14
  point -= w
14
15
  end
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  # A multi-armed bandit implementation inspired by
3
4
  # @aaronsw and victorykit/whiplash
4
- require 'simple-random'
5
5
 
6
6
  module Split
7
7
  module Algorithms
@@ -12,26 +12,25 @@ module Split
12
12
  end
13
13
 
14
14
  private
15
+ def arm_guess(participants, completions)
16
+ a = [participants, 0].max
17
+ b = [participants-completions, 0].max
18
+ Split::Algorithms.beta_distribution_rng(a + fairness_constant, b + fairness_constant)
19
+ end
15
20
 
16
- def arm_guess(participants, completions)
17
- a = [participants, 0].max
18
- b = [participants-completions, 0].max
19
- s = SimpleRandom.new; s.set_seed; s.beta(a+fairness_constant, b+fairness_constant)
20
- end
21
-
22
- def best_guess(alternatives)
23
- guesses = {}
24
- alternatives.each do |alternative|
25
- guesses[alternative.name] = arm_guess(alternative.participant_count, alternative.all_completed_count)
21
+ def best_guess(alternatives)
22
+ guesses = {}
23
+ alternatives.each do |alternative|
24
+ guesses[alternative.name] = arm_guess(alternative.participant_count, alternative.all_completed_count)
25
+ end
26
+ gmax = guesses.values.max
27
+ best = guesses.keys.select { |name| guesses[name] == gmax }
28
+ best.sample
26
29
  end
27
- gmax = guesses.values.max
28
- best = guesses.keys.select { |name| guesses[name] == gmax }
29
- best.sample
30
- end
31
30
 
32
- def fairness_constant
33
- 7
34
- end
31
+ def fairness_constant
32
+ 7
33
+ end
35
34
  end
36
35
  end
37
36
  end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "matrix"
4
+ require "rubystats"
5
+
6
+ module Split
7
+ module Algorithms
8
+ class << self
9
+ def beta_distribution_rng(a, b)
10
+ Rubystats::BetaDistribution.new(a, b).rng
11
+ end
12
+ end
13
+ end
14
+ end