Class: Conductor::Experiment
- Inherits:
-
Object
- Object
- Conductor::Experiment
- Defined in:
- lib/conductor/experiment.rb,
app/models/conductor/experiment/raw.rb,
app/models/conductor/experiment/daily.rb,
app/models/conductor/experiment/weight.rb,
app/models/conductor/experiment/history.rb
Defined Under Namespace
Classes: Daily, History, Raw, Weight
Class Method Summary collapse
-
.pick(group_name, alternatives, options = {}) ⇒ Object
Selects the best alternative for a given group.
-
.track!(options = {}) ⇒ Object
Records a conversion for the visitor.
-
.weights(group_name, alternatives) ⇒ Object
returns the raw weighting table for all alternatives for a specified group.
Class Method Details
.pick(group_name, alternatives, options = {}) ⇒ Object
Selects the best alternative for a given group
Method also saves the selection to the database so everything happens in one move
options allow you to specify a specific GOAL in case you have multiple goals per site. For example, if you are using Conductor to maximize newsletter signups and orders, you might have: => “signup” and {:goal => “purchase” }
goals are important since you can specify which goal converted with the track! method to only update records for that specific goal.
21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/conductor/experiment.rb', line 21 def pick(group_name, alternatives, ={}) group_name = Conductor.sanitize(group_name) # => clean up and standardize # check for previous selection selection = Conductor.cache.read("Conductor::#{Conductor.identity}::Experience::#{group_name}") if selection.blank? selection = select_alternative_for_group(group_name, alternatives) Conductor::Experiment::Raw.create!({:identity_id => Conductor.identity.to_s, :group_name => group_name, :alternative => selection}.merge!()) Conductor.cache.write("Conductor::#{Conductor.identity}::Experience::#{group_name}", selection) end return selection end |
.track!(options = {}) ⇒ Object
Records a conversion for the visitor.
May optionally supply a conversion value and goal.
Conversion value is specified as => 123.45
If no goal is specified as an option, than ALL selected alternatives for the experiments for a specific user will be updated with the conversion value. If a goal is specified, then only those records will be updated.
To clarify by explaination -
Assume you are selecting a landing page to maximize newsletter signups and are selecting a price point to maximize purchases. In this case you would have two goals -
- signup
- purchase
Now, if we assume that for visitor 24601 a landing page and price point are selected before they signup for the newsletter, if you called track! after a newsletter signup occurred without specifying the goal, then a conversion would ALSO (and incorrectly) be recorded by the PURCHASE goal as well as the SIGNUP goal.
What you needed to do was call track!(=> ‘signup’) to correctly record a conversion for visitor 24601 and the newsletter signup only.
70 71 72 73 74 |
# File 'lib/conductor/experiment.rb', line 70 def track!(={}) value = (.delete(:value) || 1) # => pull the conversion value and remove from hash or set value to 1 experiments = Conductor::Experiment::Raw.where({:identity_id => Conductor.identity.to_s}.merge!()) experiments.each {|x| x.update_attributes(:conversion_value => value)} if experiments end |
.weights(group_name, alternatives) ⇒ Object
returns the raw weighting table for all alternatives for a specified group
37 38 39 40 |
# File 'lib/conductor/experiment.rb', line 37 def weights(group_name, alternatives) group_name = Conductor.sanitize(group_name) # => clean up and standardize return generate_weighting_table(group_name, alternatives) end |