gtm_on_rails 0.1.13 → 0.2.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 2286c644421d286b191d0dcf4d13630a1eb68e64
4
- data.tar.gz: '0595efe9d6e06b2ae8c722b791cbf738d3ee284f'
2
+ SHA256:
3
+ metadata.gz: 11c48a3372589d7ee869e4b12c5772e8a590e5fed3c9827a0997b412afbcb03c
4
+ data.tar.gz: 7808e669d186c1ede37934594d18465e1e7eff525a2a15702b8041eddbc03d78
5
5
  SHA512:
6
- metadata.gz: 49686ed7d4c9dbcf126474313987b491161f2a9f0c09c47f09e18ef8eb8b40f765943d6192f3bc19d16791a9779974c0b791a2292948b3e5a3eef84d8aef19b6
7
- data.tar.gz: aea4782dab512cc8e90f783b243080118dc6bdc088c58c34db8e223de17958c69f7707a209a9c4a648b4f9f90f9e20a3ba783035df9655c5e3f52b663f751eab
6
+ metadata.gz: 7e0b3fc22cfdc33045f5a94ca788af6bfacd5a8a776176ea525391926641cdd295e905bb6cfc33e1b68e2ce706491dd6fa1c3d022d7e04382f2bc4b0a56031ff
7
+ data.tar.gz: 725975a753a98b4d866a679a94df17c6a88b4c1971cf55206e785335560df709af857a774001e7009a9c4309267900d98018e46905ec001467b84f12c2ca41eb
@@ -15,7 +15,7 @@ module GtmOnRails
15
15
  def data_layer
16
16
  @gtm_on_rails_data_layer
17
17
  end
18
-
18
+
19
19
  private
20
20
  def initialize_data_layer
21
21
  @gtm_on_rails_data_layer = GtmOnRails::DataLayer.new
@@ -24,7 +24,7 @@ module GtmOnRails
24
24
  @gtm_on_rails_data_layer.push({
25
25
  rails_controller: controller_name,
26
26
  rails_action: action_name
27
- })
27
+ }, before_page_view: true)
28
28
  end
29
29
  end
30
30
  end
@@ -3,15 +3,10 @@ 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, *args)
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
- 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
9
+ @data = send(:"generate_#{activity_type}_hash", args).with_indifferent_access
15
10
  end
16
11
 
17
12
  class << self
@@ -29,187 +24,214 @@ module GtmOnRails
29
24
  end
30
25
 
31
26
  private
27
+ def generate_product_impression_hash(args)
28
+ result = {}
32
29
 
33
- def generate_product_impression_hash(sanitize, args)
34
- result = get_default_data(args)
35
-
36
- result[:event] = args.delete(:event) if args[:event].present?
30
+ result[:event] = args[:event] if args[:event].present?
37
31
 
38
- result[:ecommerce][:impressions] = get_impression(args) if args[:impressions].present?
32
+ result[:ecommerce] = {}
33
+ result[:ecommerce][:currencyCode] = args[:currency] || GtmOnRails.config.ecommerce_default_currency
39
34
 
40
- result.merge!(args) unless sanitize
35
+ if args[:impressions].present?
36
+ result[:ecommerce][:impressions] = args[:impressions].map{|impression| impression.is_a?(Hash) ? GtmOnRails::DataLayer::Ecommerce::Impression.new(impression) : impression}
37
+ end
41
38
 
42
39
  return result
43
40
  end
44
41
 
45
- def generate_product_click_hash(sanitize, args)
46
- result = get_default_data(args)
47
-
48
- result[:event] = args.delete(:event) || 'productClick'
42
+ def generate_product_click_hash(args)
43
+ result = {}
49
44
 
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'
45
+ result[:event] = args[:event] || 'productClick'
53
46
 
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?
57
-
58
- result.merge!(args) unless sanitize
59
-
60
- return result
61
- end
47
+ result[:event_category] = args[:event_category] || 'Enhanced Ecommerce'
48
+ result[:event_action] = args[:event_action] || 'Product Click'
49
+ result[:event_label] = args[:event_label] || 'Enhanced Ecommerce Product Click'
62
50
 
63
- def generate_product_detail_hash(sanitize, args)
64
- result = get_default_data(args)
51
+ result[:ecommerce] = {}
52
+ result[:ecommerce][:currencyCode] = args[:currency] || GtmOnRails.config.ecommerce_default_currency
65
53
 
66
- result[:event] = args.delete(:event) if args[:event].present?
54
+ result[:ecommerce][:click] = {}
67
55
 
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?
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
71
60
 
72
- result.merge!(args) unless sanitize
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
73
64
 
74
65
  return result
75
66
  end
76
67
 
77
- def generate_add_to_cart_hash(sanitize, args)
78
- result = get_default_data(args)
68
+ def generate_product_detail_hash(args)
69
+ result = {}
79
70
 
80
- result[:event] = args.delete(:event) || 'addToCart'
71
+ result[:event] = args[:event] if args[:event].present?
81
72
 
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'
73
+ result[:ecommerce] = {}
74
+ result[:ecommerce][:currencyCode] = args[:currency] || GtmOnRails.config.ecommerce_default_currency
85
75
 
86
- result[:ecommerce][:add] = {}
87
- result[:ecommerce][:add][:products] = get_products(args) if args[:products].present?
76
+ result[:ecommerce][:detail] = {}
88
77
 
89
- result.merge!(args) unless sanitize
78
+ if args[:action].present?
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
90
86
 
91
87
  return result
92
88
  end
93
89
 
94
- def generate_remove_from_cart_hash(sanitize, args)
95
- result = get_default_data(args)
90
+ def generate_add_to_cart_hash(args)
91
+ result = {}
96
92
 
97
- result[:event] = args.delete(:event) || 'removeFromCart'
93
+ result[:event] = args[:event] || 'addToCart'
98
94
 
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'
95
+ result[:event_category] = args[:event_category] || 'Enhanced Ecommerce'
96
+ result[:event_action] = args[:event_action] || 'Add to Cart'
97
+ result[:event_label] = args[:event_label] || 'Enhanced Ecommerce Add to Cart'
102
98
 
103
- result[:ecommerce][:remove] = {}
104
- result[:ecommerce][:remove][:products] = get_products(args) if args[:products].present?
99
+ result[:ecommerce] = {}
100
+ result[:ecommerce][:currencyCode] = args[:currency] || GtmOnRails.config.ecommerce_default_currency
105
101
 
106
- result.merge!(args) unless sanitize
102
+ result[:ecommerce][:add] = {}
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
107
106
 
108
107
  return result
109
108
  end
110
109
 
111
- def generate_promotion_impression_hash(sanitize, args)
112
- result = get_default_data(args)
110
+ def generate_remove_from_cart_hash(args)
111
+ result = {}
112
+
113
+ result[:event] = args[:event] || 'removeFromCart'
113
114
 
114
- result[:event] = args.delete(:event) if args[:event].present?
115
+ result[:event_category] = args[:event_category] || 'Enhanced Ecommerce'
116
+ result[:event_action] = args[:event_action] || 'Remove from Cart'
117
+ result[:event_label] = args[:event_label] || 'Enhanced Ecommerce Remove from Cart'
115
118
 
116
- result[:ecommerce][:promoView] = {}
117
- result[:ecommerce][:promoView][:promotions] = get_promotion(args) if args[:promotions].present?
119
+ result[:ecommerce] = {}
120
+ result[:ecommerce][:currencyCode] = args[:currency] || GtmOnRails.config.ecommerce_default_currency
118
121
 
119
- result.merge!(args) unless sanitize
122
+ result[:ecommerce][:remove] = {}
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
120
126
 
121
127
  return result
122
128
  end
123
129
 
124
- def generate_promotion_click_hash(sanitize, args)
125
- result = get_default_data(args)
130
+ def generate_promotion_impression_hash(args)
131
+ result = {}
126
132
 
127
- result[:event] = args.delete(:event) || 'promotionClick'
133
+ result[:event] = args[:event] if args[:event].present?
128
134
 
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'
135
+ result[:ecommerce] = {}
136
+ result[:ecommerce][:currencyCode] = args[:currency] || GtmOnRails.config.ecommerce_default_currency
132
137
 
133
- result[:ecommerce][:promoClick] = {}
134
- result[:ecommerce][:promoClick][:promotions] = get_promotion(args) if args[:promotions].present?
138
+ result[:ecommerce][:promoView] = {}
135
139
 
136
- result.merge!(args) unless sanitize
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
137
143
 
138
144
  return result
139
145
  end
140
146
 
141
- def generate_checkout_hash(sanitize, args)
142
- result = get_default_data(args)
147
+ def generate_promotion_click_hash(args)
148
+ result = {}
143
149
 
144
- result[:event] = args.delete(:event) || 'checkout'
150
+ result[:event] = args[:event] || 'promotionClick'
145
151
 
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'
152
+ result[:event_category] = args[:event_category] || 'Enhanced Ecommerce'
153
+ result[:event_action] = args[:event_action] || 'Promotion Click'
154
+ result[:event_label] = args[:event_label] || 'Enhanced Ecommerce Promotion Click'
149
155
 
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?
156
+ result[:ecommerce] = {}
157
+ result[:ecommerce][:currencyCode] = args[:currency] || GtmOnRails.config.ecommerce_default_currency
153
158
 
154
- result.merge!(args) unless sanitize
159
+ result[:ecommerce][:promoClick] = {}
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
155
164
 
156
165
  return result
157
166
  end
158
167
 
159
- def generate_purchase_hash(sanitize, args)
160
- result = get_default_data(args)
168
+ def generate_checkout_hash(args)
169
+ result = {}
170
+
171
+ result[:event] = args[:event] || 'checkout'
161
172
 
162
- result[:event] = args.delete(:event) if args[:event].present?
173
+ result[:event_category] = args[:event_category] || 'Enhanced Ecommerce'
174
+ result[:event_action] = args[:event_action] || 'Checkout'
175
+ result[:event_label] = args[:event_label] || 'Enhanced Ecommerce Checkout'
163
176
 
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?
177
+ result[:ecommerce] = {}
178
+ result[:ecommerce][:currencyCode] = args[:currency] || GtmOnRails.config.ecommerce_default_currency
167
179
 
168
- result.merge!(args) unless sanitize
180
+ result[:ecommerce][:checkout] = {}
181
+
182
+ if args[:action].present?
183
+ action = args[:action].is_a?(Hash) ? GtmOnRails::DataLayer::Ecommerce::Action.new(args[:action]) : args[:action]
184
+ result[:ecommerce][:checkout][:actionField] = action
185
+ end
186
+
187
+ if args[:products].present?
188
+ result[:ecommerce][:checkout][:products] = args[:products].map{|product| product.is_a?(Hash) ? GtmOnRails::DataLayer::Ecommerce::Product.new(product) : product}
189
+ end
169
190
 
170
191
  return result
171
192
  end
172
193
 
173
- def generate_refund_hash(sanitize, args)
174
- result = get_default_data(args)
194
+ def generate_purchase_hash(args)
195
+ result = {}
175
196
 
176
- result[:event] = args.delete(:event) if args[:event].present?
197
+ result[:event] = args[:event] if args[:event].present?
177
198
 
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?
199
+ result[:ecommerce] = {}
200
+ result[:ecommerce][:currencyCode] = args[:currency] || GtmOnRails.config.ecommerce_default_currency
181
201
 
182
- result.merge!(args) unless sanitize
202
+ result[:ecommerce][:purchase] = {}
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
183
211
 
184
212
  return result
185
213
  end
186
214
 
215
+ def generate_refund_hash(args)
216
+ result = {}
187
217
 
188
- def get_default_data(args)
189
- hash = {}
190
- hash[:ecommerce] = {}
191
- hash[:ecommerce][:currencyCode] = get_currency(args)
192
- hash
193
- end
218
+ result[:event] = args[:event] if args[:event].present?
194
219
 
195
- def get_currency(args)
196
- args.delete(:currency) || GtmOnRails.config.ecommerce_default_currency
197
- end
220
+ result[:ecommerce] = {}
221
+ result[:ecommerce][:currencyCode] = args[:currency] || GtmOnRails.config.ecommerce_default_currency
198
222
 
199
- def get_impression(args)
200
- args.delete(:impressions).map{|impression| impression.is_a?(Hash) ? GtmOnRails::DataLayer::Ecommerce::Impression.new(impression) : impression}
201
- end
202
-
203
- def get_promotion(args)
204
- args.delete(:promotions).map{|promotion| promotion.is_a?(Hash) ? GtmOnRails::DataLayer::Ecommerce::Promotion.new(promotion) : promotion}
205
- end
223
+ result[:ecommerce][:refund] = {}
206
224
 
207
- def get_products(args)
208
- args.delete(:products).map{|product| product.is_a?(Hash) ? GtmOnRails::DataLayer::Ecommerce::Product.new(product) : product}
209
- end
225
+ if args[:action].present?
226
+ action = args[:action].is_a?(Hash) ? GtmOnRails::DataLayer::Ecommerce::Action.new(args[:action]) : args[:action]
227
+ result[:ecommerce][:refund][:actionField] = action
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
210
233
 
211
- def get_action(args)
212
- args[:action].is_a?(Hash) ? GtmOnRails::DataLayer::Ecommerce::Action.new(args.delete(:action)) : args.delete(:action)
234
+ return result
213
235
  end
214
236
  end
215
237
  end
@@ -17,7 +17,7 @@ module GtmOnRails
17
17
  args.each do |object|
18
18
  case object
19
19
  when Hash
20
- obj = GtmOnRails::DataLayer::Object.new(object)
20
+ obj = GtmOnRails::DataLayer::Object.new(**object)
21
21
  when GtmOnRails::DataLayer::Object
22
22
  obj = object
23
23
  end
@@ -1,3 +1,3 @@
1
1
  module GtmOnRails
2
- VERSION = '0.1.13'
2
+ VERSION = '0.2.1'
3
3
  end
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.13
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - ykogure
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-06-01 00:00:00.000000000 Z
11
+ date: 2024-05-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: 3.2.22
27
+ - !ruby/object:Gem::Dependency
28
+ name: puma
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: mysql2
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -88,8 +102,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
88
102
  - !ruby/object:Gem::Version
89
103
  version: '0'
90
104
  requirements: []
91
- rubyforge_project:
92
- rubygems_version: 2.6.11
105
+ rubygems_version: 3.4.10
93
106
  signing_key:
94
107
  specification_version: 4
95
108
  summary: An plugin that integrate Google Tag Manager easy with Rails