Module: FieldTest::Helpers
- Included in:
- Controller, Mailer
- Defined in:
- lib/field_test/helpers.rb
Instance Method Summary collapse
- #field_test(experiment, **options) ⇒ Object
- #field_test_converted(experiment, **options) ⇒ Object
-
#field_test_experiments(**options) ⇒ Object
TODO fetch in single query.
Instance Method Details
#field_test(experiment, **options) ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/field_test/helpers.rb', line 3 def field_test(experiment, **) exp = FieldTest::Experiment.find(experiment) participants = FieldTest::Participant.standardize([:participant] || field_test_participant) if try(:request) = .dup if ![:variant] && params[:field_test] && params[:field_test][experiment] && exp.variants.include?(params[:field_test][experiment]) params_variant = params[:field_test][experiment] end if FieldTest.exclude_bots? [:exclude] ||= Browser.new(request.user_agent).bot? end [:exclude] ||= FieldTest.excluded_ips.any? { |ip| ip.include?(request.remote_ip) } [:ip] = request.remote_ip [:user_agent] = request.user_agent end # don't update variant when passed via params if params_variant params_variant else # cache results for request # TODO possibly remove in 0.4.0 cache_key = [exp.id, participants.map(&:where_values), .slice(:variant, :exclude)] @field_test_cache ||= {} @field_test_cache[cache_key] ||= exp.variant(participants, ) end end |
#field_test_converted(experiment, **options) ⇒ Object
37 38 39 40 41 42 43 |
# File 'lib/field_test/helpers.rb', line 37 def field_test_converted(experiment, **) exp = FieldTest::Experiment.find(experiment) participants = FieldTest::Participant.standardize([:participant] || field_test_participant) exp.convert(participants, goal: [:goal]) end |
#field_test_experiments(**options) ⇒ Object
TODO fetch in single query
46 47 48 49 50 51 52 53 54 55 |
# File 'lib/field_test/helpers.rb', line 46 def field_test_experiments(**) participants = FieldTest::Participant.standardize([:participant] || field_test_participant) experiments = {} participants.each do |participant| FieldTest::Membership.where(participant.where_values).each do |membership| experiments[membership.experiment] ||= membership.variant end end experiments end |