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 11 12 13 14 15 |
# 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) sanitize = true if args.first.keys.count == 1 && args.first.keys.first.to_sym == :sanitize sanitize = args.shift[:sanitize] end @data = send(:"generate_#{activity_type}_hash", *[sanitize, args.first]).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
18 19 20 21 22 23 24 |
# File 'lib/gtm_on_rails/models/data_layer/ecommerce.rb', line 18 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
27 28 29 |
# File 'lib/gtm_on_rails/models/data_layer/ecommerce.rb', line 27 def to_event(event_name = 'ga_event') GtmOnRails::DataLayer::Event.new(event_name || @data[:event], @data.except(:event).deep_symbolize_keys) end |