gtm_on_rails 0.1.12 → 0.1.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/gtm_on_rails/models/data_layer/ecommerce.rb +113 -135
- data/lib/gtm_on_rails/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2286c644421d286b191d0dcf4d13630a1eb68e64
|
4
|
+
data.tar.gz: '0595efe9d6e06b2ae8c722b791cbf738d3ee284f'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 49686ed7d4c9dbcf126474313987b491161f2a9f0c09c47f09e18ef8eb8b40f765943d6192f3bc19d16791a9779974c0b791a2292948b3e5a3eef84d8aef19b6
|
7
|
+
data.tar.gz: aea4782dab512cc8e90f783b243080118dc6bdc088c58c34db8e223de17958c69f7707a209a9c4a648b4f9f90f9e20a3ba783035df9655c5e3f52b663f751eab
|
@@ -3,10 +3,15 @@ module GtmOnRails
|
|
3
3
|
class DataLayer::Ecommerce < DataLayer::Object
|
4
4
|
ACTIVITY_TYPES = [:product_impression, :product_click, :product_detail, :add_to_cart, :remove_from_cart, :promotion_impression, :promotion_click, :checkout, :purchase, :refund]
|
5
5
|
|
6
|
-
def initialize(activity_type,
|
6
|
+
def initialize(activity_type, *args)
|
7
7
|
raise ArgumentError.new("'#{activity_type}' is undefined activity type.") unless activity_type.in?(ACTIVITY_TYPES)
|
8
8
|
|
9
|
-
|
9
|
+
sanitize = true
|
10
|
+
if args.first.keys.count == 1 && args.first.keys.first.to_sym == :sanitize
|
11
|
+
sanitize = args.shift[:sanitize]
|
12
|
+
end
|
13
|
+
|
14
|
+
@data = send(:"generate_#{activity_type}_hash", *[sanitize, args.first]).with_indifferent_access
|
10
15
|
end
|
11
16
|
|
12
17
|
class << self
|
@@ -24,214 +29,187 @@ module GtmOnRails
|
|
24
29
|
end
|
25
30
|
|
26
31
|
private
|
27
|
-
def generate_product_impression_hash(args)
|
28
|
-
result = {}
|
29
32
|
|
30
|
-
|
33
|
+
def generate_product_impression_hash(sanitize, args)
|
34
|
+
result = get_default_data(args)
|
31
35
|
|
32
|
-
result[:
|
33
|
-
result[:ecommerce][:currencyCode] = args[:currency] || GtmOnRails.config.ecommerce_default_currency
|
36
|
+
result[:event] = args.delete(:event) if args[:event].present?
|
34
37
|
|
35
|
-
if args[:impressions].present?
|
36
|
-
|
37
|
-
|
38
|
+
result[:ecommerce][:impressions] = get_impression(args) if args[:impressions].present?
|
39
|
+
|
40
|
+
result.merge!(args) unless sanitize
|
38
41
|
|
39
42
|
return result
|
40
43
|
end
|
41
44
|
|
42
|
-
def generate_product_click_hash(args)
|
43
|
-
result =
|
45
|
+
def generate_product_click_hash(sanitize, args)
|
46
|
+
result = get_default_data(args)
|
44
47
|
|
45
|
-
result[:event] = args
|
48
|
+
result[:event] = args.delete(:event) || 'productClick'
|
46
49
|
|
47
|
-
result[:event_category] = args
|
48
|
-
result[:event_action] = args
|
49
|
-
result[:event_label] = args
|
50
|
+
result[:event_category] = args.delete(:event_category) || 'Enhanced Ecommerce'
|
51
|
+
result[:event_action] = args.delete(:event_action) || 'Product Click'
|
52
|
+
result[:event_label] = args.delete(:event_label) || 'Enhanced Ecommerce Product Click'
|
50
53
|
|
51
|
-
result[:ecommerce]
|
52
|
-
result[:ecommerce][:
|
54
|
+
result[:ecommerce][:click] = {}
|
55
|
+
result[:ecommerce][:click][:actionField] = get_action(args) if args[:action].present?
|
56
|
+
result[:ecommerce][:click][:products] = get_products(args) if args[:products].present?
|
53
57
|
|
54
|
-
result
|
55
|
-
|
56
|
-
if args[:action].present?
|
57
|
-
action = args[:action].is_a?(Hash) ? GtmOnRails::DataLayer::Ecommerce::Action.new(args[:action]) : args[:action]
|
58
|
-
result[:ecommerce][:click][:actionField] = action
|
59
|
-
end
|
60
|
-
|
61
|
-
if args[:products].present?
|
62
|
-
result[:ecommerce][:click][:products] = args[:products].map{|product| product.is_a?(Hash) ? GtmOnRails::DataLayer::Ecommerce::Product.new(product) : product}
|
63
|
-
end
|
58
|
+
result.merge!(args) unless sanitize
|
64
59
|
|
65
60
|
return result
|
66
61
|
end
|
67
62
|
|
68
|
-
def generate_product_detail_hash(args)
|
69
|
-
result =
|
70
|
-
|
71
|
-
result[:event] = args[:event] if args[:event].present?
|
63
|
+
def generate_product_detail_hash(sanitize, args)
|
64
|
+
result = get_default_data(args)
|
72
65
|
|
73
|
-
result[:
|
74
|
-
result[:ecommerce][:currencyCode] = args[:currency] || GtmOnRails.config.ecommerce_default_currency
|
66
|
+
result[:event] = args.delete(:event) if args[:event].present?
|
75
67
|
|
76
|
-
result[:ecommerce][:detail]
|
68
|
+
result[:ecommerce][:detail] = {}
|
69
|
+
result[:ecommerce][:detail][:actionField] = get_action(args) if args[:action].present?
|
70
|
+
result[:ecommerce][:detail][:products] = get_products(args) if args[:products].present?
|
77
71
|
|
78
|
-
|
79
|
-
action = args[:action].is_a?(Hash) ? GtmOnRails::DataLayer::Ecommerce::Action.new(args[:action]) : args[:action]
|
80
|
-
result[:ecommerce][:detail][:actionField] = action
|
81
|
-
end
|
82
|
-
|
83
|
-
if args[:products].present?
|
84
|
-
result[:ecommerce][:detail][:products] = args[:products].map{|product| product.is_a?(Hash) ? GtmOnRails::DataLayer::Ecommerce::Product.new(product) : product}
|
85
|
-
end
|
72
|
+
result.merge!(args) unless sanitize
|
86
73
|
|
87
74
|
return result
|
88
75
|
end
|
89
76
|
|
90
|
-
def generate_add_to_cart_hash(args)
|
91
|
-
result =
|
77
|
+
def generate_add_to_cart_hash(sanitize, args)
|
78
|
+
result = get_default_data(args)
|
92
79
|
|
93
|
-
result[:event] = args
|
80
|
+
result[:event] = args.delete(:event) || 'addToCart'
|
94
81
|
|
95
|
-
result[:event_category] = args
|
96
|
-
result[:event_action] = args
|
97
|
-
result[:event_label] = args
|
82
|
+
result[:event_category] = args.delete(:event_category) || 'Enhanced Ecommerce'
|
83
|
+
result[:event_action] = args.delete(:event_action) || 'Add to Cart'
|
84
|
+
result[:event_label] = args.delete(:event_label) || 'Enhanced Ecommerce Add to Cart'
|
98
85
|
|
99
|
-
result[:ecommerce]
|
100
|
-
result[:ecommerce][:
|
86
|
+
result[:ecommerce][:add] = {}
|
87
|
+
result[:ecommerce][:add][:products] = get_products(args) if args[:products].present?
|
101
88
|
|
102
|
-
result
|
103
|
-
if args[:products].present?
|
104
|
-
result[:ecommerce][:add][:products] = args[:products].map{|product| product.is_a?(Hash) ? GtmOnRails::DataLayer::Ecommerce::Product.new(product) : product}
|
105
|
-
end
|
89
|
+
result.merge!(args) unless sanitize
|
106
90
|
|
107
91
|
return result
|
108
92
|
end
|
109
93
|
|
110
|
-
def generate_remove_from_cart_hash(args)
|
111
|
-
result =
|
94
|
+
def generate_remove_from_cart_hash(sanitize, args)
|
95
|
+
result = get_default_data(args)
|
112
96
|
|
113
|
-
result[:event] = args
|
97
|
+
result[:event] = args.delete(:event) || 'removeFromCart'
|
114
98
|
|
115
|
-
result[:event_category] = args
|
116
|
-
result[:event_action] = args
|
117
|
-
result[:event_label] = args
|
99
|
+
result[:event_category] = args.delete(:event_category) || 'Enhanced Ecommerce'
|
100
|
+
result[:event_action] = args.delete(:event_action) || 'Remove from Cart'
|
101
|
+
result[:event_label] = args.delete(:event_label) || 'Enhanced Ecommerce Remove from Cart'
|
118
102
|
|
119
|
-
result[:ecommerce]
|
120
|
-
result[:ecommerce][:
|
103
|
+
result[:ecommerce][:remove] = {}
|
104
|
+
result[:ecommerce][:remove][:products] = get_products(args) if args[:products].present?
|
121
105
|
|
122
|
-
result
|
123
|
-
if args[:products].present?
|
124
|
-
result[:ecommerce][:remove][:products] = args[:products].map{|product| product.is_a?(Hash) ? GtmOnRails::DataLayer::Ecommerce::Product.new(product) : product}
|
125
|
-
end
|
106
|
+
result.merge!(args) unless sanitize
|
126
107
|
|
127
108
|
return result
|
128
109
|
end
|
129
110
|
|
130
|
-
def generate_promotion_impression_hash(args)
|
131
|
-
result =
|
111
|
+
def generate_promotion_impression_hash(sanitize, args)
|
112
|
+
result = get_default_data(args)
|
132
113
|
|
133
|
-
result[:event] = args
|
114
|
+
result[:event] = args.delete(:event) if args[:event].present?
|
134
115
|
|
135
|
-
result[:ecommerce]
|
136
|
-
result[:ecommerce][:
|
116
|
+
result[:ecommerce][:promoView] = {}
|
117
|
+
result[:ecommerce][:promoView][:promotions] = get_promotion(args) if args[:promotions].present?
|
137
118
|
|
138
|
-
result
|
139
|
-
|
140
|
-
if args[:promotions].present?
|
141
|
-
result[:ecommerce][:promoView][:promotions] = args[:promotions].map{|promotion| promotion.is_a?(Hash) ? GtmOnRails::DataLayer::Ecommerce::Promotion.new(promotion) : promotion}
|
142
|
-
end
|
119
|
+
result.merge!(args) unless sanitize
|
143
120
|
|
144
121
|
return result
|
145
122
|
end
|
146
123
|
|
147
|
-
def generate_promotion_click_hash(args)
|
148
|
-
result =
|
124
|
+
def generate_promotion_click_hash(sanitize, args)
|
125
|
+
result = get_default_data(args)
|
149
126
|
|
150
|
-
result[:event] = args
|
127
|
+
result[:event] = args.delete(:event) || 'promotionClick'
|
151
128
|
|
152
|
-
result[:event_category] = args
|
153
|
-
result[:event_action] = args
|
154
|
-
result[:event_label] = args
|
129
|
+
result[:event_category] = args.delete(:event_category) || 'Enhanced Ecommerce'
|
130
|
+
result[:event_action] = args.delete(:event_action) || 'Promotion Click'
|
131
|
+
result[:event_label] = args.delete(:event_label) || 'Enhanced Ecommerce Promotion Click'
|
155
132
|
|
156
|
-
result[:ecommerce]
|
157
|
-
result[:ecommerce][:
|
133
|
+
result[:ecommerce][:promoClick] = {}
|
134
|
+
result[:ecommerce][:promoClick][:promotions] = get_promotion(args) if args[:promotions].present?
|
158
135
|
|
159
|
-
result
|
160
|
-
|
161
|
-
if args[:promotions].present?
|
162
|
-
result[:ecommerce][:promoClick][:promotions] = args[:promotions].map{|promotion| promotion.is_a?(Hash) ? GtmOnRails::DataLayer::Ecommerce::Promotion.new(promotion) : promotion}
|
163
|
-
end
|
136
|
+
result.merge!(args) unless sanitize
|
164
137
|
|
165
138
|
return result
|
166
139
|
end
|
167
140
|
|
168
|
-
def generate_checkout_hash(args)
|
169
|
-
result =
|
141
|
+
def generate_checkout_hash(sanitize, args)
|
142
|
+
result = get_default_data(args)
|
170
143
|
|
171
|
-
result[:event] = args
|
144
|
+
result[:event] = args.delete(:event) || 'checkout'
|
172
145
|
|
173
|
-
result[:event_category] = args
|
174
|
-
result[:event_action] = args
|
175
|
-
result[:event_label] = args
|
146
|
+
result[:event_category] = args.delete(:event_category) || 'Enhanced Ecommerce'
|
147
|
+
result[:event_action] = args.delete(:event_action) || 'Checkout'
|
148
|
+
result[:event_label] = args.delete(:event_label) || 'Enhanced Ecommerce Checkout'
|
176
149
|
|
177
|
-
result[:ecommerce]
|
178
|
-
result[:ecommerce][:
|
150
|
+
result[:ecommerce][:checkout] = {}
|
151
|
+
result[:ecommerce][:checkout][:actionField] = get_action(args) if args[:action].present?
|
152
|
+
result[:ecommerce][:checkout][:products] = get_products(args) if args[:products].present?
|
179
153
|
|
180
|
-
result
|
154
|
+
result.merge!(args) unless sanitize
|
181
155
|
|
182
|
-
|
183
|
-
|
184
|
-
result[:ecommerce][:checkout][:actionField] = action
|
185
|
-
end
|
156
|
+
return result
|
157
|
+
end
|
186
158
|
|
187
|
-
|
188
|
-
|
189
|
-
|
159
|
+
def generate_purchase_hash(sanitize, args)
|
160
|
+
result = get_default_data(args)
|
161
|
+
|
162
|
+
result[:event] = args.delete(:event) if args[:event].present?
|
163
|
+
|
164
|
+
result[:ecommerce][:purchase] = {}
|
165
|
+
result[:ecommerce][:purchase][:actionField] = get_action(args) if args[:action].present?
|
166
|
+
result[:ecommerce][:purchase][:products] = get_products(args) if args[:products].present?
|
167
|
+
|
168
|
+
result.merge!(args) unless sanitize
|
190
169
|
|
191
170
|
return result
|
192
171
|
end
|
193
172
|
|
194
|
-
def
|
195
|
-
result =
|
173
|
+
def generate_refund_hash(sanitize, args)
|
174
|
+
result = get_default_data(args)
|
196
175
|
|
197
|
-
result[:event] = args
|
176
|
+
result[:event] = args.delete(:event) if args[:event].present?
|
198
177
|
|
199
|
-
result[:ecommerce]
|
200
|
-
result[:ecommerce][:
|
178
|
+
result[:ecommerce][:refund] = {}
|
179
|
+
result[:ecommerce][:refund][:actionField] = get_action(args) if args[:action].present?
|
180
|
+
result[:ecommerce][:refund][:products] = get_products(args) if args[:products].present?
|
201
181
|
|
202
|
-
result
|
203
|
-
|
204
|
-
action = args[:action] || {}
|
205
|
-
action = action.is_a?(Hash) ? GtmOnRails::DataLayer::Ecommerce::Action.new(action) : action
|
206
|
-
result[:ecommerce][:purchase][:actionField] = action
|
207
|
-
|
208
|
-
if args[:products].present?
|
209
|
-
result[:ecommerce][:purchase][:products] = args[:products].map{|product| product.is_a?(Hash) ? GtmOnRails::DataLayer::Ecommerce::Product.new(product) : product}
|
210
|
-
end
|
182
|
+
result.merge!(args) unless sanitize
|
211
183
|
|
212
184
|
return result
|
213
185
|
end
|
214
186
|
|
215
|
-
def generate_refund_hash(args)
|
216
|
-
result = {}
|
217
187
|
|
218
|
-
|
188
|
+
def get_default_data(args)
|
189
|
+
hash = {}
|
190
|
+
hash[:ecommerce] = {}
|
191
|
+
hash[:ecommerce][:currencyCode] = get_currency(args)
|
192
|
+
hash
|
193
|
+
end
|
219
194
|
|
220
|
-
|
221
|
-
|
195
|
+
def get_currency(args)
|
196
|
+
args.delete(:currency) || GtmOnRails.config.ecommerce_default_currency
|
197
|
+
end
|
222
198
|
|
223
|
-
|
199
|
+
def get_impression(args)
|
200
|
+
args.delete(:impressions).map{|impression| impression.is_a?(Hash) ? GtmOnRails::DataLayer::Ecommerce::Impression.new(impression) : impression}
|
201
|
+
end
|
224
202
|
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
end
|
229
|
-
|
230
|
-
if args[:products].present?
|
231
|
-
result[:ecommerce][:refund][:products] = args[:products].map{|product| product.is_a?(Hash) ? GtmOnRails::DataLayer::Ecommerce::Product.new(product) : product}
|
232
|
-
end
|
203
|
+
def get_promotion(args)
|
204
|
+
args.delete(:promotions).map{|promotion| promotion.is_a?(Hash) ? GtmOnRails::DataLayer::Ecommerce::Promotion.new(promotion) : promotion}
|
205
|
+
end
|
233
206
|
|
234
|
-
|
207
|
+
def get_products(args)
|
208
|
+
args.delete(:products).map{|product| product.is_a?(Hash) ? GtmOnRails::DataLayer::Ecommerce::Product.new(product) : product}
|
209
|
+
end
|
210
|
+
|
211
|
+
def get_action(args)
|
212
|
+
args[:action].is_a?(Hash) ? GtmOnRails::DataLayer::Ecommerce::Action.new(args.delete(:action)) : args.delete(:action)
|
235
213
|
end
|
236
214
|
end
|
237
215
|
end
|
data/lib/gtm_on_rails/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gtm_on_rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.13
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ykogure
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-06-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|