Module: Vanity::Helpers
- Included in:
- Vanity
- Defined in:
- lib/vanity/helpers.rb
Overview
Helper methods available on Object.
Instance Method Summary collapse
-
#ab_test(name, &block) ⇒ Object
This method returns one of the alternative values in the named A/B test.
-
#track!(name, count_or_options = 1) ⇒ Object
Tracks an action associated with a metric.
Instance Method Details
#ab_test(name, &block) ⇒ Object
This method returns one of the alternative values in the named A/B test.
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/vanity/helpers.rb', line 36 def ab_test(name, &block) # TODO refactor with Vanity::Rails::Helpers#ab_test, however that's used # within Rails views request = respond_to?(:request) ? self.request : nil if Vanity.playground.using_js? value = Vanity.context.vanity_store_experiment_for_js name, Vanity.playground.experiment(name).choose(request) else value = Vanity.playground.experiment(name).choose(request).value end if block content = capture(value, &block) else value end end |
#track!(name, count_or_options = 1) ⇒ Object
Tracks an action associated with a metric. Useful for calling from a Rack handler. Note that a user should already be added to an experiment via #ab_test before this is called - otherwise, the conversion will be tracked, but the user will not be added to the experiment.
66 67 68 |
# File 'lib/vanity/helpers.rb', line 66 def track!(name, = 1) Vanity.playground.track! name, end |