Module: Staccato::Measurable
- Included in:
- Staccato::Measurement::Checkout, Staccato::Measurement::CheckoutOption, Staccato::Measurement::ImpressionList, Staccato::Measurement::Product, Staccato::Measurement::ProductImpression, Staccato::Measurement::Promotion, Staccato::Measurement::Transaction
- Defined in:
- lib/staccato/measurable.rb
Overview
Measurable adds field mapping and param collection
for Measurement classes to be add to Hit
Class Method Summary collapse
Instance Method Summary collapse
-
#add_custom_dimension(dimension_index, value) ⇒ Object
Set a custom dimension value at an index.
-
#add_custom_metric(metric_index, value) ⇒ Object
Set a custom metric value at an index.
-
#custom_dimensions ⇒ Hash
Custom dimensions for this measurable.
-
#custom_fields_allowed? ⇒ Boolean
not all measurements allow custom dimensions or metrics.
-
#custom_metrics ⇒ Hash
Custom metrics for this measurable.
-
#fields ⇒ Object
fields from options for this measurement.
- #initialize(options = {}) ⇒ Object
-
#params ⇒ Hash
collects the parameters from options for this measurement.
-
#prefix ⇒ String
measurement option prefix.
Class Method Details
.included(model) ⇒ Object
5 6 7 8 9 10 11 12 13 |
# File 'lib/staccato/measurable.rb', line 5 def self.included(model) model.extend Forwardable model.class_eval do attr_accessor :options def_delegators :@options, *model::FIELDS.keys end end |
Instance Method Details
#add_custom_dimension(dimension_index, value) ⇒ Object
Set a custom dimension value at an index
49 50 51 52 |
# File 'lib/staccato/measurable.rb', line 49 def add_custom_dimension(dimension_index, value) return unless custom_fields_allowed? self.custom_dimensions["#{prefix}cd#{dimension_index}"] = value end |
#add_custom_metric(metric_index, value) ⇒ Object
Set a custom metric value at an index
63 64 65 66 |
# File 'lib/staccato/measurable.rb', line 63 def add_custom_metric(metric_index, value) return unless custom_fields_allowed? self.custom_metrics["#{prefix}cm#{metric_index}"] = value end |
#custom_dimensions ⇒ Hash
Custom dimensions for this measurable
56 57 58 |
# File 'lib/staccato/measurable.rb', line 56 def custom_dimensions @custom_dimensions ||= {} end |
#custom_fields_allowed? ⇒ Boolean
not all measurements allow custom dimensions or metrics
32 33 34 |
# File 'lib/staccato/measurable.rb', line 32 def custom_fields_allowed? false end |
#custom_metrics ⇒ Hash
Custom metrics for this measurable
70 71 72 |
# File 'lib/staccato/measurable.rb', line 70 def custom_metrics @custom_metrics ||= {} end |
#fields ⇒ Object
fields from options for this measurement
21 22 23 |
# File 'lib/staccato/measurable.rb', line 21 def fields self.class::FIELDS end |
#initialize(options = {}) ⇒ Object
16 17 18 |
# File 'lib/staccato/measurable.rb', line 16 def initialize( = {}) self. = OptionSet.new() end |
#params ⇒ Hash
collects the parameters from options for this measurement
38 39 40 41 42 43 44 |
# File 'lib/staccato/measurable.rb', line 38 def params {}. merge!(measurable_params). merge!(custom_dimensions). merge!(custom_metrics). reject {|_,v| v.nil?} end |
#prefix ⇒ String
measurement option prefix
27 28 29 |
# File 'lib/staccato/measurable.rb', line 27 def prefix '' end |