Class: GtmOnRails::DataLayer::Ecommerce
- Defined in:
- lib/gtm_on_rails/models/data_layer/ecommerce.rb
Defined Under Namespace
Classes: Action, Impression, Product, Promotion
Constant Summary collapse
- ACTIVITY_TYPES =
[:product_impression, :product_click, :product_detail, :add_to_cart, :remove_from_cart, :promotion_impression, :promotion_click, :checkout, :purchase, :refund]
Instance Attribute Summary
Attributes inherited from Object
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(activity_type, **args) ⇒ Ecommerce
constructor
A new instance of Ecommerce.
- #to_event(event_name = 'ga_event') ⇒ Object
Methods inherited from Object
#add, #as_json, #method_missing, #to_js, #to_json
Constructor Details
#initialize(activity_type, **args) ⇒ Ecommerce
Returns a new instance of Ecommerce.
6 7 8 9 10 |
# File 'lib/gtm_on_rails/models/data_layer/ecommerce.rb', line 6 def initialize(activity_type, **args) raise ArgumentError.new("'#{activity_type}' is undefined activity type.") unless activity_type.in?(ACTIVITY_TYPES) @data = send(:"generate_#{activity_type}_hash", args).with_indifferent_access end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class GtmOnRails::DataLayer::Object
Class Method Details
.method_missing(method, *args, &block) ⇒ Object
13 14 15 16 17 18 19 |
# File 'lib/gtm_on_rails/models/data_layer/ecommerce.rb', line 13 def method_missing(method, *args, &block) if method.in?(ACTIVITY_TYPES) self.new(method, *args) else super end end |
Instance Method Details
#to_event(event_name = 'ga_event') ⇒ Object
22 23 24 |
# File 'lib/gtm_on_rails/models/data_layer/ecommerce.rb', line 22 def to_event(event_name = 'ga_event') GtmOnRails::DataLayer::Event.new(event_name || @data[:event], @data.except(:event).deep_symbolize_keys) end |