Module: Vanity::Helpers
- Included in:
- Vanity
- Defined in:
- lib/vanity/helpers.rb
Overview
Helper methods available on the Vanity module.
Instance Method Summary collapse
-
#ab_test(name, request = nil, &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, request = nil, &block) ⇒ Object
This method returns one of the alternative values in the named A/B test.
35 36 37 38 39 40 41 42 43 44 |
# File 'lib/vanity/helpers.rb', line 35 def ab_test(name, request = nil, &block) request ||= Vanity.context.respond_to?(:request) ? Vanity.context.request : nil alternative = Vanity.playground.experiment(name).choose(request) Vanity.context.vanity_add_to_active_experiments(name, alternative) Vanity.logger.warn("Deprecated: This method used to accept a block, however, calling it with a block would result in an exception. The block will be removed from the signature in an upcoming version.") if block alternative.value 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.
59 60 61 |
# File 'lib/vanity/helpers.rb', line 59 def track!(name, = 1) Vanity.playground.track!(name, ) end |