Module: AbPanel
- Defined in:
- lib/ab_panel.rb,
lib/ab_panel/config.rb,
lib/ab_panel/version.rb,
lib/ab_panel/mixpanel.rb,
lib/ab_panel/javascript.rb,
lib/ab_panel/controller_additions.rb
Defined Under Namespace
Modules: ControllerAdditions, Mixpanel
Classes: Config, Javascript
Constant Summary
collapse
- VERSION =
"0.4.4"
Class Method Summary
collapse
Class Method Details
.add_funnel(funnel) ⇒ Object
83
84
85
|
# File 'lib/ab_panel.rb', line 83
def add_funnel(funnel)
funnels.add(funnel) if funnel.present?
end
|
.conditions ⇒ Object
21
22
23
|
# File 'lib/ab_panel.rb', line 21
def conditions
Thread.current[:ab_panel_conditions] ||= assign_conditions!
end
|
.conditions=(custom_conditions) ⇒ Object
Set the experiment’s conditions.
This is used to persist conditions from the session.
39
40
41
42
|
# File 'lib/ab_panel.rb', line 39
def conditions=(custom_conditions)
return conditions unless custom_conditions
Thread.current[:ab_panel_conditions] = assign_conditions! custom_conditions
end
|
.env ⇒ Object
60
61
62
63
64
|
# File 'lib/ab_panel.rb', line 60
def env
Thread.current[:ab_panel_env] ||= {
'conditions' => conditions
}
end
|
.environment ⇒ Object
87
88
89
90
91
92
93
94
95
96
|
# File 'lib/ab_panel.rb', line 87
def environment
props = { distinct_id: self.env["distinct_id"] }
props.merge!(self.properties) if self.properties
self.funnels.each { |f| props["funnel_#{f}"] = true }
self.experiments.each { |exp| props[exp] = self.conditions.send(exp).condition }
props
end
|
.experiments ⇒ Object
44
45
46
|
# File 'lib/ab_panel.rb', line 44
def experiments
config.experiments
end
|
.funnels ⇒ Object
75
76
77
|
# File 'lib/ab_panel.rb', line 75
def funnels
env[:funnels] ||= Set.new
end
|
.funnels=(funnels) ⇒ Object
79
80
81
|
# File 'lib/ab_panel.rb', line 79
def funnels=(funnels)
env[:funnels] = funnels
end
|
.identify(distinct_id) ⇒ Object
17
18
19
|
# File 'lib/ab_panel.rb', line 17
def identify(distinct_id)
tracker.identify distinct_id
end
|
.properties ⇒ Object
56
57
58
|
# File 'lib/ab_panel.rb', line 56
def properties
env[:properties]
end
|
.reset! ⇒ Object
66
67
68
69
|
# File 'lib/ab_panel.rb', line 66
def reset!
Thread.current[:ab_panel_env] = nil
Thread.current[:ab_panel_conditions] = nil
end
|
.scenarios(experiment) ⇒ Object
48
49
50
|
# File 'lib/ab_panel.rb', line 48
def scenarios(experiment)
config.scenarios experiment
end
|
.serialized_conditions ⇒ Object
25
26
27
28
29
30
31
32
33
|
# File 'lib/ab_panel.rb', line 25
def serialized_conditions
cs = {}
conditions.each_pair do |key, value|
cs[key] = value.marshal_dump
end
cs.to_json
end
|
.set_env(key, value) ⇒ Object
71
72
73
|
# File 'lib/ab_panel.rb', line 71
def set_env(key, value)
env[key] = value
end
|
.track(event_name, properties) ⇒ Object
Track event in Mixpanel backend.
12
13
14
|
# File 'lib/ab_panel.rb', line 12
def track(event_name, properties)
tracker.track event_name, properties
end
|
.weights(experiment) ⇒ Object
52
53
54
|
# File 'lib/ab_panel.rb', line 52
def weights(experiment)
config.weights experiment
end
|