module SimpleAbs
Constants
- VERSION
Public Instance Methods
ab_test(name, tests)
click to toggle source
# File lib/simple_abs.rb, line 16 def ab_test(name, tests) if is_bot? test_value = tests[rand(tests.size)] return test_value end if params[:test_value] return params[:test_value] end test_value = cookies[name] if test_value.blank? || !tests.include?(test_value) test_value = tests[rand(tests.size)] cookies.permanent[name] = test_value find_or_create_by_experiment_and_which_method(name, test_value).increment!(:participants) end return test_value end
converted!(name)
click to toggle source
# File lib/simple_abs.rb, line 39 def converted!(name) if !is_bot? test_value = cookies[name] if test_value && cookies[name.to_s + "_converted"].blank? find_or_create_by_experiment_and_which_method(name, test_value).increment!(:conversions) cookies.permanent[name.to_s + "_converted"] = true end end end
find_or_create_by_experiment_and_which_method(experiment, which)
click to toggle source
# File lib/simple_abs.rb, line 50 def find_or_create_by_experiment_and_which_method(experiment, which) alternative = Alternative.where(experiment: experiment, which: which).first if alternative.nil? alternative = Alternative.new alternative.experiment = experiment alternative.which = which alternative.save end return alternative end
is_bot?()
click to toggle source
# File lib/simple_abs.rb, line 5 def is_bot? agent = request.env["HTTP_USER_AGENT"] matches = nil matches = agent.match(/(facebook|postrank|voyager|twitterbot|googlebot|slurp|butterfly|pycurl|tweetmemebot|metauri|evrinid|reddit|digg)/mi) if agent if (agent.nil? or matches) return true else return false end end