Class: Caboose::AbTesting
- Inherits:
-
Object
- Object
- Caboose::AbTesting
- Defined in:
- app/models/caboose/ab_testing.rb
Constant Summary collapse
- @@session_id =
nil
Class Method Summary collapse
-
.[](analytics_name) ⇒ Object
Get this session’s ab_value value for the variant with the given analytics name.
-
.analytics_string ⇒ Object
Get the analytics string.
-
.create_ab_value(var) ⇒ Object
Ensure that an ab_value exists for the given session and variant.
-
.init(session_id) ⇒ Object
Sets the ab_variants for the user’s session.
- .value_for_name(analytics_name) ⇒ Object
Class Method Details
.[](analytics_name) ⇒ Object
Get this session’s ab_value value for the variant with the given analytics name
21 22 23 |
# File 'app/models/caboose/ab_testing.rb', line 21 def self.[](analytics_name) return self.value_for_name(analytics_name) end |
.analytics_string ⇒ Object
Get the analytics string
33 34 35 36 |
# File 'app/models/caboose/ab_testing.rb', line 33 def self.analytics_string arr = AbValue.where(:session_id => @@session_id).all.collect { |abv| abv.keyval } return "|#{arr.join('|')}|" end |
.create_ab_value(var) ⇒ Object
Ensure that an ab_value exists for the given session and variant
13 14 15 16 17 18 |
# File 'app/models/caboose/ab_testing.rb', line 13 def self.create_ab_value(var) if AbValue.where(:session_id => @@session_id, :ab_variant_id => var.id).exists? return AbValue.where(:session_id => @@session_id, :ab_variant_id => var.id).first end return AbValue.create(:session_id => @@session_id, :ab_variant_id => var.id, :ab_option_id => var.random_option.id) end |
.init(session_id) ⇒ Object
Sets the ab_variants for the user’s session
7 8 9 10 |
# File 'app/models/caboose/ab_testing.rb', line 7 def self.init(session_id) @@session_id = "#{session_id}" AbVariant.all.each { |var| self.create_ab_value(var) } end |
.value_for_name(analytics_name) ⇒ Object
25 26 27 28 29 30 |
# File 'app/models/caboose/ab_testing.rb', line 25 def self.value_for_name(analytics_name) return nil if !AbVariant.where(:analytics_name => analytics_name).exists? var = AbVariant.where(:analytics_name => analytics_name).first abv = self.create_ab_value(var) return abv.ab_option.value end |