gtm_on_rails 0.1.4 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.ja.md +285 -2
- data/README.md +285 -1
- data/lib/generators/templates/gtm_on_rails.rb +4 -0
- data/lib/gtm_on_rails/config.rb +1 -0
- data/lib/gtm_on_rails/engine.rb +7 -2
- data/lib/gtm_on_rails/models/data_layer.rb +3 -3
- data/lib/gtm_on_rails/models/data_layer/ecommerce.rb +223 -0
- data/lib/gtm_on_rails/models/data_layer/ecommerce/action.rb +22 -0
- data/lib/gtm_on_rails/models/data_layer/ecommerce/impression.rb +29 -0
- data/lib/gtm_on_rails/models/data_layer/ecommerce/product.rb +43 -0
- data/lib/gtm_on_rails/models/data_layer/ecommerce/promotion.rb +19 -0
- data/lib/gtm_on_rails/models/{data_layer_event.rb → data_layer/event.rb} +2 -2
- data/lib/gtm_on_rails/models/{data_layer_object.rb → data_layer/object.rb} +11 -5
- data/lib/gtm_on_rails/version.rb +1 -1
- metadata +9 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 20b03197ee5403fbb9798f2542967ac06455d533
|
4
|
+
data.tar.gz: 573fe001b486037942939d5f969dcee799a622e3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 95577feac38fae6ed55de4da7ac9bed3f95bd57476f8c0f38846557dcb523af05dc98634e557e429f2e8b54fd48866077a0c0849590919c416dac36e8aae5373
|
7
|
+
data.tar.gz: b287e7c290cf85c1ade3ff46c6587a232ab74a679afba9df6db0a6896e7dbfab925735ae92e55b38cd88c2f793d9a6f5c8fb487764fde638e208f43ba1a4b50f
|
data/README.ja.md
CHANGED
@@ -36,8 +36,10 @@ controller名とaction名はJavaScriptのコードとしてHTMLのソースコ
|
|
36
36
|
#### rescue_when_error_occurred
|
37
37
|
この設定を有効にすることによって、JavaScriptのコードとして出力される際に、dataLayerに設定した値などの問題でエラーが発生場合にエラーを握りつぶします。
|
38
38
|
つまり、計測周りのエラーによってサイトの表示に影響が出ないようにします。
|
39
|
+
#### ecommerce_default_currency
|
40
|
+
拡張Eコマース機能を用いる場合のデフォルトの通貨を設定します。ISO4217規格の文字列で指定して下さい。
|
39
41
|
|
40
|
-
##
|
42
|
+
## BasicUsage
|
41
43
|
#### 基本
|
42
44
|
`data_layer`という変数(正確にはhelperが呼び出す変数@gtm_on_rails_data_layer)にdataLayerで送信したい内容をHash型で追加するだけでdataLayerで好きな値を送信できます。
|
43
45
|
controller内等で以下のように記述する感じになると思います。
|
@@ -64,7 +66,6 @@ object.name = 'name2'
|
|
64
66
|
```
|
65
67
|
`GtmOnRails::DataLayerObject`クラスでは、上記のように値にアクセスできます。
|
66
68
|
|
67
|
-
|
68
69
|
#### `GtmOnRails::DataLayerEvent`
|
69
70
|
```ruby
|
70
71
|
event = GtmOnRails::DataLayerEvent.new('イベント名', {name: 'name'})
|
@@ -72,6 +73,288 @@ data_layer.push(event)
|
|
72
73
|
```
|
73
74
|
上記のように記述することで、イベント名を設定して送信できます。
|
74
75
|
|
76
|
+
## 拡張Eコマース
|
77
|
+
GoogleAnalyticsの拡張Eコマース機能を本Gemで簡単に設定できます。
|
78
|
+
拡張Eコマース機能の仕様については下記を参照して下さい。
|
79
|
+
https://developers.google.com/analytics/devguides/collection/analyticsjs/enhanced-ecommerce
|
80
|
+
https://developers.google.com/tag-manager/enhanced-ecommerce
|
81
|
+
|
82
|
+
### 基本
|
83
|
+
拡張Eコマースには、
|
84
|
+
- インプレッション
|
85
|
+
- 商品
|
86
|
+
- プロモーション
|
87
|
+
- アクション
|
88
|
+
|
89
|
+
の4種類のデータ型と、
|
90
|
+
|
91
|
+
- 商品インプレッション(product_impression)
|
92
|
+
- 商品クリック(product_click)
|
93
|
+
- 商品詳細表示(product_detail)
|
94
|
+
- カート追加(add_to_cart)
|
95
|
+
- カートから削除(remove_from_cart)
|
96
|
+
- プロモーションインプレッション(promotion_impression)
|
97
|
+
- プロモーションクリック(promotion_click)
|
98
|
+
- 決済(checkout)
|
99
|
+
- 購入(purchase)
|
100
|
+
- 払い戻し(refund)
|
101
|
+
|
102
|
+
の10種類のアクションが存在します。
|
103
|
+
|
104
|
+
4種類のデータは各アクションで使用します。
|
105
|
+
9種類のアクションは、GoogleAnalyticsの'PageView'か'Event'で拡張Eコマース機能を有効にし、データレイヤーを使用して送信します。
|
106
|
+
|
107
|
+
### データ型
|
108
|
+
基本はGoogle公式のヘルプを参照して下さい。
|
109
|
+
ここではGTMonRails固有の内容のみ記載します。
|
110
|
+
|
111
|
+
#### インプレッション `GtmOnRails::DataLayer::Ecommerce::Impression`
|
112
|
+
公式仕様:https://developers.google.com/analytics/devguides/collection/analyticsjs/enhanced-ecommerce#impression-data
|
113
|
+
|
114
|
+
ex.
|
115
|
+
```ruby
|
116
|
+
GtmOnRails::DataLayer::Ecommerce::Impression.new(id: '01', name: '商品1')
|
117
|
+
```
|
118
|
+
|
119
|
+
キー | 説明
|
120
|
+
------------ | -------------
|
121
|
+
id | ヘルプ参照
|
122
|
+
name | ヘルプ参照
|
123
|
+
list | ヘルプ参照
|
124
|
+
brand | ヘルプ参照
|
125
|
+
category | Arrayで指定することが可能。最大で5つまで指定可能。
|
126
|
+
variant | ヘルプ参照
|
127
|
+
position | ヘルプ参照
|
128
|
+
price | ヘルプ参照
|
129
|
+
|
130
|
+
#### 商品 `GtmOnRails::DataLayer::Ecommerce::Product`
|
131
|
+
公式仕様:https://developers.google.com/analytics/devguides/collection/analyticsjs/enhanced-ecommerce#product-data
|
132
|
+
|
133
|
+
ex.
|
134
|
+
```ruby
|
135
|
+
GtmOnRails::DataLayer::Ecommerce::Product.new(id: '01', name: '商品1')
|
136
|
+
```
|
137
|
+
|
138
|
+
キー | 説明
|
139
|
+
------------ | -------------
|
140
|
+
id | ヘルプ参照
|
141
|
+
name | ヘルプ参照
|
142
|
+
list | ヘルプ参照
|
143
|
+
brand | ヘルプ参照
|
144
|
+
category | Arrayで指定することが可能。最大で5つまで指定可能。
|
145
|
+
variant | ヘルプ参照
|
146
|
+
price | ヘルプ参照
|
147
|
+
quantity | ヘルプ参照
|
148
|
+
coupon | ヘルプ参照
|
149
|
+
position | ヘルプ参照
|
150
|
+
|
151
|
+
#### プロモーション `GtmOnRails::DataLayer::Ecommerce::Promotion`
|
152
|
+
公式仕様:https://developers.google.com/analytics/devguides/collection/analyticsjs/enhanced-ecommerce#promotion-data
|
153
|
+
|
154
|
+
ex.
|
155
|
+
```ruby
|
156
|
+
GtmOnRails::DataLayer::Ecommerce::Promotion.new(id: '01', name: '商品1')
|
157
|
+
```
|
158
|
+
|
159
|
+
キー | 説明
|
160
|
+
------------ | -------------
|
161
|
+
id | ヘルプ参照
|
162
|
+
name | ヘルプ参照
|
163
|
+
creative | ヘルプ参照
|
164
|
+
position | ヘルプ参照
|
165
|
+
|
166
|
+
#### アクション `GtmOnRails::DataLayer::Ecommerce::Action`
|
167
|
+
公式仕様:https://developers.google.com/analytics/devguides/collection/analyticsjs/enhanced-ecommerce#action-data
|
168
|
+
|
169
|
+
ex.
|
170
|
+
```ruby
|
171
|
+
GtmOnRails::DataLayer::Ecommerce::Action.new(list: '商品一覧')
|
172
|
+
```
|
173
|
+
|
174
|
+
キー | 説明
|
175
|
+
------------ | -------------
|
176
|
+
id | ヘルプ参照
|
177
|
+
affiliation | ヘルプ参照
|
178
|
+
revenue | ヘルプ参照
|
179
|
+
tax | ヘルプ参照
|
180
|
+
shipping | ヘルプ参照
|
181
|
+
coupon | ヘルプ参照
|
182
|
+
list | ヘルプ参照
|
183
|
+
step | ヘルプ参照
|
184
|
+
option | ヘルプ参照
|
185
|
+
|
186
|
+
### アクション型
|
187
|
+
基本はGoogle公式のヘルプを参照して下さい。
|
188
|
+
ここではGTMonRails固有の内容のみ記載します。
|
189
|
+
|
190
|
+
#### 商品インプレッション(product_impression)
|
191
|
+
公式仕様:https://developers.google.com/tag-manager/enhanced-ecommerce#product-impressions
|
192
|
+
|
193
|
+
このアクションは「PageView」でGoogleAnalytics側に送信する。
|
194
|
+
|
195
|
+
ex.
|
196
|
+
```ruby
|
197
|
+
GtmOnRails::DataLayer::Ecommerce.product_impression(impressions: impressions)
|
198
|
+
```
|
199
|
+
|
200
|
+
キー | 説明
|
201
|
+
------------ | -------------
|
202
|
+
currency | 通貨。「ISO 4217」規格のアルファベットを指定する。未指定の場合は`config/initializers/gtm_o_rails.rb`で指定したデフォルト値が使用される。
|
203
|
+
impressions | `GtmOnRails::DataLayer::Ecommerce::Impression`クラスのオブジェクトまたはHashのArrayを指定する。
|
204
|
+
|
205
|
+
#### 商品クリック(product_click)
|
206
|
+
公式仕様:https://developers.google.com/tag-manager/enhanced-ecommerce#product-clicks
|
207
|
+
|
208
|
+
このアクションは「Event」でGoogleAnalytics側に送信する。
|
209
|
+
|
210
|
+
ex.
|
211
|
+
```ruby
|
212
|
+
GtmOnRails::DataLayer::Ecommerce.product_click(action: action, products: products)
|
213
|
+
```
|
214
|
+
|
215
|
+
キー | 説明
|
216
|
+
------------ | -------------
|
217
|
+
currency | 通貨。「ISO 4217」規格のアルファベットを指定する。未指定の場合は`config/initializers/gtm_o_rails.rb`で指定したデフォルト値が使用される。
|
218
|
+
action | `GtmOnRails::DataLayer::Ecommerce::Action`クラスのオブジェクトまたはHashを指定する。
|
219
|
+
products | `GtmOnRails::DataLayer::Ecommerce::Product`クラスのオブジェクトまたはHashのArrayを指定する。
|
220
|
+
|
221
|
+
#### 商品詳細表示(product_detail)
|
222
|
+
公式仕様:https://developers.google.com/tag-manager/enhanced-ecommerce#details
|
223
|
+
|
224
|
+
このアクションは「PageView」でGoogleAnalytics側に送信する。
|
225
|
+
|
226
|
+
ex.
|
227
|
+
```ruby
|
228
|
+
GtmOnRails::DataLayer::Ecommerce.product_detail(action: action, products: products)
|
229
|
+
```
|
230
|
+
|
231
|
+
キー | 説明
|
232
|
+
------------ | -------------
|
233
|
+
currency | 通貨。「ISO 4217」規格のアルファベットを指定する。未指定の場合は`config/initializers/gtm_o_rails.rb`で指定したデフォルト値が使用される。
|
234
|
+
action | `GtmOnRails::DataLayer::Ecommerce::Action`クラスのオブジェクトまたはHashを指定する。
|
235
|
+
products | `GtmOnRails::DataLayer::Ecommerce::Product`クラスのオブジェクトまたはHashのArrayを指定する。
|
236
|
+
|
237
|
+
#### カート追加(add_to_cart)
|
238
|
+
公式仕様:https://developers.google.com/tag-manager/enhanced-ecommerce#add
|
239
|
+
|
240
|
+
このアクションは「Event」でGoogleAnalytics側に送信する。
|
241
|
+
|
242
|
+
ex.
|
243
|
+
```ruby
|
244
|
+
GGtmOnRails::DataLayer::Ecommerce.add_to_cart(products: products)
|
245
|
+
```
|
246
|
+
|
247
|
+
キー | 説明
|
248
|
+
------------ | -------------
|
249
|
+
currency | 通貨。「ISO 4217」規格のアルファベットを指定する。未指定の場合は`config/initializers/gtm_o_rails.rb`で指定したデフォルト値が使用される。
|
250
|
+
products | `GtmOnRails::DataLayer::Ecommerce::Product`クラスのオブジェクトまたはHashのArrayを指定する。
|
251
|
+
|
252
|
+
#### カートから削除(remove_from_cart)
|
253
|
+
公式仕様:https://developers.google.com/tag-manager/enhanced-ecommerce#add
|
254
|
+
|
255
|
+
このアクションは「Event」でGoogleAnalytics側に送信する。
|
256
|
+
|
257
|
+
ex.
|
258
|
+
```ruby
|
259
|
+
GtmOnRails::DataLayer::Ecommerce.remove_from_cart(products: products)
|
260
|
+
```
|
261
|
+
|
262
|
+
キー | 説明
|
263
|
+
------------ | -------------
|
264
|
+
currency | 通貨。「ISO 4217」規格のアルファベットを指定する。未指定の場合は`config/initializers/gtm_o_rails.rb`で指定したデフォルト値が使用される。
|
265
|
+
products | `GtmOnRails::DataLayer::Ecommerce::Product`クラスのオブジェクトまたはHashのArrayを指定する。
|
266
|
+
|
267
|
+
#### プロモーションインプレッション(promotion_impression)
|
268
|
+
公式仕様:https://developers.google.com/tag-manager/enhanced-ecommerce#promo-impressions
|
269
|
+
|
270
|
+
このアクションは「PageView」でGoogleAnalytics側に送信する。
|
271
|
+
|
272
|
+
ex.
|
273
|
+
```ruby
|
274
|
+
GtmOnRails::DataLayer::Ecommerce.promotion_impression(promotions: promotions)
|
275
|
+
```
|
276
|
+
|
277
|
+
キー | 説明
|
278
|
+
------------ | -------------
|
279
|
+
currency | 通貨。「ISO 4217」規格のアルファベットを指定する。未指定の場合は`config/initializers/gtm_o_rails.rb`で指定したデフォルト値が使用される。
|
280
|
+
promotions | `GtmOnRails::DataLayer::Ecommerce::Promotion`クラスのオブジェクトまたはHashのArrayを指定する。
|
281
|
+
|
282
|
+
#### プロモーションクリック(promotion_click)
|
283
|
+
公式仕様:https://developers.google.com/tag-manager/enhanced-ecommerce#promo-clicks
|
284
|
+
|
285
|
+
このアクションは「Event」でGoogleAnalytics側に送信する。
|
286
|
+
|
287
|
+
ex.
|
288
|
+
```ruby
|
289
|
+
GtmOnRails::DataLayer::Ecommerce.promotion_click(promotions: promotions)
|
290
|
+
```
|
291
|
+
|
292
|
+
キー | 説明
|
293
|
+
------------ | -------------
|
294
|
+
currency | 通貨。「ISO 4217」規格のアルファベットを指定する。未指定の場合は`config/initializers/gtm_o_rails.rb`で指定したデフォルト値が使用される。
|
295
|
+
promotions | `GtmOnRails::DataLayer::Ecommerce::Promotion`クラスのオブジェクトまたはHashのArrayを指定する。
|
296
|
+
|
297
|
+
#### 決済(checkout)
|
298
|
+
公式仕様:https://developers.google.com/tag-manager/enhanced-ecommerce#checkoutstep
|
299
|
+
|
300
|
+
このアクションは「Event」でGoogleAnalytics側に送信する。
|
301
|
+
|
302
|
+
ex.
|
303
|
+
```ruby
|
304
|
+
action = GtmOnRails::DataLayer::Ecommerce::Action.new({
|
305
|
+
step: 1
|
306
|
+
})
|
307
|
+
GtmOnRails::DataLayer::Ecommerce.checkout(action: action, products: products)
|
308
|
+
```
|
309
|
+
|
310
|
+
キー | 説明
|
311
|
+
------------ | -------------
|
312
|
+
currency | 通貨。「ISO 4217」規格のアルファベットを指定する。未指定の場合は`config/initializers/gtm_o_rails.rb`で指定したデフォルト値が使用される。
|
313
|
+
action | `GtmOnRails::DataLayer::Ecommerce::Action`クラスのオブジェクトまたはHashを指定する。
|
314
|
+
products | `GtmOnRails::DataLayer::Ecommerce::Product`クラスのオブジェクトまたはHashのArrayを指定する。
|
315
|
+
|
316
|
+
#### 購入(purchase)
|
317
|
+
公式仕様:https://developers.google.com/tag-manager/enhanced-ecommerce#purchases
|
318
|
+
|
319
|
+
このアクションは「PageView」でGoogleAnalytics側に送信する。
|
320
|
+
|
321
|
+
ex.
|
322
|
+
```ruby
|
323
|
+
action = GtmOnRails::DataLayer::Ecommerce::Action.new({
|
324
|
+
id: '01',
|
325
|
+
affiliation: 'Online Store',
|
326
|
+
revenue: '35.43',
|
327
|
+
tax: '4.90',
|
328
|
+
shipping: '5.99',
|
329
|
+
coupon: 'SUMMER_SALE'
|
330
|
+
})
|
331
|
+
GtmOnRails::DataLayer::Ecommerce.purchase(action: action, products: products)
|
332
|
+
```
|
333
|
+
|
334
|
+
キー | 説明
|
335
|
+
------------ | -------------
|
336
|
+
currency | 通貨。「ISO 4217」規格のアルファベットを指定する。未指定の場合は`config/initializers/gtm_o_rails.rb`で指定したデフォルト値が使用される。
|
337
|
+
action | `GtmOnRails::DataLayer::Ecommerce::Action`クラスのオブジェクトまたはHashを指定する。
|
338
|
+
products | `GtmOnRails::DataLayer::Ecommerce::Product`クラスのオブジェクトまたはHashのArrayを指定する。
|
339
|
+
|
340
|
+
#### 払い戻し(refund)
|
341
|
+
公式仕様:https://developers.google.com/tag-manager/enhanced-ecommerce#refunds
|
342
|
+
|
343
|
+
このアクションは「PageView」でGoogleAnalytics側に送信する。
|
344
|
+
|
345
|
+
ex.
|
346
|
+
```ruby
|
347
|
+
action = GtmOnRails::DataLayer::Ecommerce::Action.new({
|
348
|
+
id: '01'
|
349
|
+
})
|
350
|
+
GtmOnRails::DataLayer::Ecommerce.refund(action: action)
|
351
|
+
```
|
352
|
+
|
353
|
+
キー | 説明
|
354
|
+
------------ | -------------
|
355
|
+
currency | 通貨。「ISO 4217」規格のアルファベットを指定する。未指定の場合は`config/initializers/gtm_o_rails.rb`で指定したデフォルト値が使用される。
|
356
|
+
action | `GtmOnRails::DataLayer::Ecommerce::Action`クラスのオブジェクトまたはHashを指定する。
|
357
|
+
|
75
358
|
|
76
359
|
## License
|
77
360
|
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/README.md
CHANGED
@@ -36,8 +36,11 @@ Be careful using this, if you enable this option, controller and action name out
|
|
36
36
|
#### rescue_when_error_occurred
|
37
37
|
If somthing error occurred when output tags, subsequent tag's output is stopped and run subsequent processing.
|
38
38
|
The point is, dataLayer error won't affect displaying website, if you enable this option.
|
39
|
+
#### ecommerce_default_currency
|
40
|
+
Default local currency code when use Enhanced Ecommerce.
|
41
|
+
The local currency must be specified in the ISO 4217 standard.
|
39
42
|
|
40
|
-
##
|
43
|
+
## BasicUsage
|
41
44
|
#### Basic
|
42
45
|
You only push Hash object in `data_layer` variable, can send values what you want by dataLayer.
|
43
46
|
Usually I’d say you write like the following code in contoller.
|
@@ -70,6 +73,287 @@ data_layer.push(event)
|
|
70
73
|
```
|
71
74
|
You can send dataLayer with Google Tag Manager's event name, when write like the above code.
|
72
75
|
|
76
|
+
## Enhanced Ecommerce
|
77
|
+
You can use Enhanced Ecommerce of Google Analytics easily using GTMonRails.
|
78
|
+
Please look official help about details of Enhanced Ecommerce.
|
79
|
+
https://developers.google.com/analytics/devguides/collection/analyticsjs/enhanced-ecommerce
|
80
|
+
https://developers.google.com/tag-manager/enhanced-ecommerce
|
81
|
+
|
82
|
+
### Basis
|
83
|
+
Enhanced Ecommerce has the following 4 types of data object,
|
84
|
+
|
85
|
+
- Impression
|
86
|
+
- Product
|
87
|
+
- Promotion
|
88
|
+
- Action
|
89
|
+
|
90
|
+
and, the following 10 types of measuring activity object.
|
91
|
+
|
92
|
+
- Product Impressions(product_impression)
|
93
|
+
- Product Clicks(product_click)
|
94
|
+
- Views of Product Details(product_detail)
|
95
|
+
- Adding a Product to a Shopping Cart(add_to_cart)
|
96
|
+
- Removing a Product from a Shopping Cart(remove_from_cart)
|
97
|
+
- Promotion Impressions(promotion_impression)
|
98
|
+
- Promotion Clicks(promotion_click)
|
99
|
+
- Checkout Steps(checkout)
|
100
|
+
- Purchases(purchase)
|
101
|
+
- Refunds(refund)
|
102
|
+
|
103
|
+
4 types of data object is used in each measuring activity objects.
|
104
|
+
You enable Enhanced Ecommerce at Google Tag Manager, and 9 tyoes of measuring activity object is sent with 'dataLayer' with 'PageView' or 'Event' of Google Analytics.
|
105
|
+
|
106
|
+
### Data Object
|
107
|
+
Please look official help about details of Enhanced Ecommerce data object.
|
108
|
+
Only GTMonRails's own configures are described.
|
109
|
+
|
110
|
+
#### Impression `GtmOnRails::DataLayer::Ecommerce::Impression`
|
111
|
+
Official Help : https://developers.google.com/analytics/devguides/collection/analyticsjs/enhanced-ecommerce#impression-data
|
112
|
+
|
113
|
+
ex.
|
114
|
+
```ruby
|
115
|
+
GtmOnRails::DataLayer::Ecommerce::Impression.new(id: '01', name: 'product_1')
|
116
|
+
```
|
117
|
+
|
118
|
+
Key | Description
|
119
|
+
------------ | -------------
|
120
|
+
id | In Official Help
|
121
|
+
name | In Official Help
|
122
|
+
list | In Official Help
|
123
|
+
brand | In Official Help
|
124
|
+
category | Array of String. Maximum 5.
|
125
|
+
variant | In Official Help
|
126
|
+
position | In Official Help
|
127
|
+
price | In Official Help
|
128
|
+
|
129
|
+
#### Product `GtmOnRails::DataLayer::Ecommerce::Product`
|
130
|
+
Official Help : https://developers.google.com/analytics/devguides/collection/analyticsjs/enhanced-ecommerce#product-data
|
131
|
+
|
132
|
+
ex.
|
133
|
+
```ruby
|
134
|
+
GtmOnRails::DataLayer::Ecommerce::Product.new(id: '01', name: 'product_1')
|
135
|
+
```
|
136
|
+
|
137
|
+
Key | Description
|
138
|
+
------------ | -------------
|
139
|
+
id | In Official Help
|
140
|
+
name | In Official Help
|
141
|
+
list | In Official Help
|
142
|
+
brand | In Official Help
|
143
|
+
category | Array of String. Maximum 5.
|
144
|
+
variant | In Official Help
|
145
|
+
price | In Official Help
|
146
|
+
quantity | In Official Help
|
147
|
+
coupon | In Official Help
|
148
|
+
position | In Official Help
|
149
|
+
|
150
|
+
#### Promotion `GtmOnRails::DataLayer::Ecommerce::Promotion`
|
151
|
+
Official Help : https://developers.google.com/analytics/devguides/collection/analyticsjs/enhanced-ecommerce#promotion-data
|
152
|
+
|
153
|
+
ex.
|
154
|
+
```ruby
|
155
|
+
GtmOnRails::DataLayer::Ecommerce::Promotion.new(id: '01', name: 'product_1')
|
156
|
+
```
|
157
|
+
|
158
|
+
Key | Description
|
159
|
+
------------ | -------------
|
160
|
+
id | In Official Help
|
161
|
+
name | In Official Help
|
162
|
+
creative | In Official Help
|
163
|
+
position | In Official Help
|
164
|
+
|
165
|
+
#### Action `GtmOnRails::DataLayer::Ecommerce::Action`
|
166
|
+
Official Help : https://developers.google.com/analytics/devguides/collection/analyticsjs/enhanced-ecommerce#action-data
|
167
|
+
|
168
|
+
ex.
|
169
|
+
```ruby
|
170
|
+
GtmOnRails::DataLayer::Ecommerce::Action.new(list: 'general product list')
|
171
|
+
```
|
172
|
+
|
173
|
+
Key | Description
|
174
|
+
------------ | -------------
|
175
|
+
id | In Official Help
|
176
|
+
affiliation | In Official Help
|
177
|
+
revenue | In Official Help
|
178
|
+
tax | In Official Help
|
179
|
+
shipping | In Official Help
|
180
|
+
coupon | In Official Help
|
181
|
+
list | In Official Help
|
182
|
+
step | In Official Help
|
183
|
+
option | In Official Help
|
184
|
+
|
185
|
+
### Measuring Activity Object
|
186
|
+
Please look official help about details of Enhanced Ecommerce data object.
|
187
|
+
Only GTMonRails's own configures are described.
|
188
|
+
|
189
|
+
#### Product Impressions(product_impression)
|
190
|
+
Official Help : https://developers.google.com/tag-manager/enhanced-ecommerce#product-impressions
|
191
|
+
|
192
|
+
You need to send this activity to GoogleAnalytics as 'PageView'.
|
193
|
+
|
194
|
+
ex.
|
195
|
+
```ruby
|
196
|
+
GtmOnRails::DataLayer::Ecommerce.product_impression(impressions: impressions)
|
197
|
+
```
|
198
|
+
|
199
|
+
Key | Description
|
200
|
+
------------ | -------------
|
201
|
+
currency | Local currency. The local currency must be specified in the ISO 4217 standard. Default value is configured in `config/initializers/gtm_o_rails.rb`.
|
202
|
+
impressions | Array of `GtmOnRails::DataLayer::Ecommerce::Impression` object or Hash.
|
203
|
+
|
204
|
+
#### Product Clicks(product_click)
|
205
|
+
Official Help : https://developers.google.com/tag-manager/enhanced-ecommerce#product-clicks
|
206
|
+
|
207
|
+
You need to send this activity to GoogleAnalytics as 'Event'.
|
208
|
+
|
209
|
+
ex.
|
210
|
+
```ruby
|
211
|
+
GtmOnRails::DataLayer::Ecommerce.product_click(action: action, products: products)
|
212
|
+
```
|
213
|
+
|
214
|
+
Key | Description
|
215
|
+
------------ | -------------
|
216
|
+
currency | Local currency. The local currency must be specified in the ISO 4217 standard. Default value is configured in `config/initializers/gtm_o_rails.rb`.
|
217
|
+
action | `GtmOnRails::DataLayer::Ecommerce::Action` object or Hash.
|
218
|
+
products | Array of `GtmOnRails::DataLayer::Ecommerce::Product` object or Hash.
|
219
|
+
|
220
|
+
#### Views of Product Details(product_detail)
|
221
|
+
Official Help : https://developers.google.com/tag-manager/enhanced-ecommerce#details
|
222
|
+
|
223
|
+
You need to send this activity to GoogleAnalytics as 'PageView'.
|
224
|
+
|
225
|
+
ex.
|
226
|
+
```ruby
|
227
|
+
GtmOnRails::DataLayer::Ecommerce.product_detail(action: action, products: products)
|
228
|
+
```
|
229
|
+
|
230
|
+
Key | Description
|
231
|
+
------------ | -------------
|
232
|
+
currency | Local currency. The local currency must be specified in the ISO 4217 standard. Default value is configured in `config/initializers/gtm_o_rails.rb`.
|
233
|
+
action | `GtmOnRails::DataLayer::Ecommerce::Action` object or Hash.
|
234
|
+
products | Array of `GtmOnRails::DataLayer::Ecommerce::Product` object or Hash.
|
235
|
+
|
236
|
+
#### Adding a Product to a Shopping Cart(add_to_cart)
|
237
|
+
Official Help : https://developers.google.com/tag-manager/enhanced-ecommerce#add
|
238
|
+
|
239
|
+
You need to send this activity to GoogleAnalytics as 'Event'.
|
240
|
+
|
241
|
+
ex.
|
242
|
+
```ruby
|
243
|
+
GGtmOnRails::DataLayer::Ecommerce.add_to_cart(products: products)
|
244
|
+
```
|
245
|
+
|
246
|
+
Key | Description
|
247
|
+
------------ | -------------
|
248
|
+
currency | Local currency. The local currency must be specified in the ISO 4217 standard. Default value is configured in `config/initializers/gtm_o_rails.rb`.
|
249
|
+
products | Array of `GtmOnRails::DataLayer::Ecommerce::Product` object or Hash.
|
250
|
+
|
251
|
+
#### Removing a Product from a Shopping Cart(remove_from_cart)
|
252
|
+
Official Help : https://developers.google.com/tag-manager/enhanced-ecommerce#add
|
253
|
+
|
254
|
+
You need to send this activity to GoogleAnalytics as 'Event'.
|
255
|
+
|
256
|
+
ex.
|
257
|
+
```ruby
|
258
|
+
GtmOnRails::DataLayer::Ecommerce.remove_from_cart(products: products)
|
259
|
+
```
|
260
|
+
|
261
|
+
Key | Description
|
262
|
+
------------ | -------------
|
263
|
+
currency | Local currency. The local currency must be specified in the ISO 4217 standard. Default value is configured in `config/initializers/gtm_o_rails.rb`.
|
264
|
+
products | Array of `GtmOnRails::DataLayer::Ecommerce::Product` object or Hash.
|
265
|
+
|
266
|
+
#### Promotion Impressions(promotion_impression)
|
267
|
+
Official Help : https://developers.google.com/tag-manager/enhanced-ecommerce#promo-impressions
|
268
|
+
|
269
|
+
You need to send this activity to GoogleAnalytics as 'PageView'.
|
270
|
+
|
271
|
+
ex.
|
272
|
+
```ruby
|
273
|
+
GtmOnRails::DataLayer::Ecommerce.promotion_impression(promotions: promotions)
|
274
|
+
```
|
275
|
+
|
276
|
+
Key | Description
|
277
|
+
------------ | -------------
|
278
|
+
currency | Local currency. The local currency must be specified in the ISO 4217 standard. Default value is configured in `config/initializers/gtm_o_rails.rb`.
|
279
|
+
promotions | Array of `GtmOnRails::DataLayer::Ecommerce::Promotion` object or Hash.
|
280
|
+
|
281
|
+
#### Promotion Clicks(promotion_click)
|
282
|
+
Official Help : https://developers.google.com/tag-manager/enhanced-ecommerce#promo-clicks
|
283
|
+
|
284
|
+
You need to send this activity to GoogleAnalytics as 'Event'.
|
285
|
+
|
286
|
+
ex.
|
287
|
+
```ruby
|
288
|
+
GtmOnRails::DataLayer::Ecommerce.promotion_click(promotions: promotions)
|
289
|
+
```
|
290
|
+
|
291
|
+
Key | Description
|
292
|
+
------------ | -------------
|
293
|
+
currency | Local currency. The local currency must be specified in the ISO 4217 standard. Default value is configured in `config/initializers/gtm_o_rails.rb`.
|
294
|
+
promotions | Array of `GtmOnRails::DataLayer::Ecommerce::Promotion` object or Hash.
|
295
|
+
|
296
|
+
#### Checkout Steps(checkout)
|
297
|
+
Official Help : https://developers.google.com/tag-manager/enhanced-ecommerce#checkoutstep
|
298
|
+
|
299
|
+
You need to send this activity to GoogleAnalytics as 'Event'.
|
300
|
+
|
301
|
+
ex.
|
302
|
+
```ruby
|
303
|
+
action = GtmOnRails::DataLayer::Ecommerce::Action.new({
|
304
|
+
step: 1
|
305
|
+
})
|
306
|
+
GtmOnRails::DataLayer::Ecommerce.checkout(action: action, products: products)
|
307
|
+
```
|
308
|
+
|
309
|
+
Key | Description
|
310
|
+
------------ | -------------
|
311
|
+
currency | Local currency. The local currency must be specified in the ISO 4217 standard. Default value is configured in `config/initializers/gtm_o_rails.rb`.
|
312
|
+
action | `GtmOnRails::DataLayer::Ecommerce::Action` object or Hash.
|
313
|
+
products | Array of `GtmOnRails::DataLayer::Ecommerce::Product` object or Hash.
|
314
|
+
|
315
|
+
#### Purchases(purchase)
|
316
|
+
Official Help : https://developers.google.com/tag-manager/enhanced-ecommerce#purchases
|
317
|
+
|
318
|
+
You need to send this activity to GoogleAnalytics as 'PageView'.
|
319
|
+
|
320
|
+
ex.
|
321
|
+
```ruby
|
322
|
+
action = GtmOnRails::DataLayer::Ecommerce::Action.new({
|
323
|
+
id: '01',
|
324
|
+
affiliation: 'Online Store',
|
325
|
+
revenue: '35.43',
|
326
|
+
tax: '4.90',
|
327
|
+
shipping: '5.99',
|
328
|
+
coupon: 'SUMMER_SALE'
|
329
|
+
})
|
330
|
+
GtmOnRails::DataLayer::Ecommerce.purchase(action: action, products: products)
|
331
|
+
```
|
332
|
+
|
333
|
+
Key | Description
|
334
|
+
------------ | -------------
|
335
|
+
currency | Local currency. The local currency must be specified in the ISO 4217 standard. Default value is configured in `config/initializers/gtm_o_rails.rb`.
|
336
|
+
action | `GtmOnRails::DataLayer::Ecommerce::Action` object or Hash.
|
337
|
+
products | Array of `GtmOnRails::DataLayer::Ecommerce::Product` object or Hash.
|
338
|
+
|
339
|
+
#### Refunds(refund)
|
340
|
+
Official Help : https://developers.google.com/tag-manager/enhanced-ecommerce#refunds
|
341
|
+
|
342
|
+
You need to send this activity to GoogleAnalytics as 'PageView'.
|
343
|
+
|
344
|
+
ex.
|
345
|
+
```ruby
|
346
|
+
action = GtmOnRails::DataLayer::Ecommerce::Action.new({
|
347
|
+
id: '01'
|
348
|
+
})
|
349
|
+
GtmOnRails::DataLayer::Ecommerce.refund(action: action)
|
350
|
+
```
|
351
|
+
|
352
|
+
Key | Description
|
353
|
+
------------ | -------------
|
354
|
+
currency | Local currency. The local currency must be specified in the ISO 4217 standard. Default value is configured in `config/initializers/gtm_o_rails.rb`.
|
355
|
+
action | `GtmOnRails::DataLayer::Ecommerce::Action` object or Hash.
|
356
|
+
|
73
357
|
## License
|
74
358
|
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
75
359
|
|
@@ -13,4 +13,8 @@ GtmOnRails.configure do |config|
|
|
13
13
|
# If somthing error occurred when output tags, subsequent tag's output is stopped and run subsequent processing.
|
14
14
|
# The point is, dataLayer error won't affect displaying website, if you enable this option.
|
15
15
|
config.rescue_when_error_occurred = false
|
16
|
+
|
17
|
+
# Default local currency code when use Enhanced Ecommerce.
|
18
|
+
# The local currency must be specified in the ISO 4217 standard.
|
19
|
+
config.ecommerce_default_currency = 'USD'
|
16
20
|
end
|
data/lib/gtm_on_rails/config.rb
CHANGED
data/lib/gtm_on_rails/engine.rb
CHANGED
@@ -1,8 +1,13 @@
|
|
1
1
|
require 'gtm_on_rails/config'
|
2
2
|
require 'gtm_on_rails/controllers/initialize_data_layer'
|
3
3
|
require 'gtm_on_rails/models/data_layer'
|
4
|
-
require 'gtm_on_rails/models/
|
5
|
-
require 'gtm_on_rails/models/
|
4
|
+
require 'gtm_on_rails/models/data_layer/object'
|
5
|
+
require 'gtm_on_rails/models/data_layer/event'
|
6
|
+
require 'gtm_on_rails/models/data_layer/ecommerce'
|
7
|
+
require 'gtm_on_rails/models/data_layer/ecommerce/action'
|
8
|
+
require 'gtm_on_rails/models/data_layer/ecommerce/impression'
|
9
|
+
require 'gtm_on_rails/models/data_layer/ecommerce/product'
|
10
|
+
require 'gtm_on_rails/models/data_layer/ecommerce/promotion'
|
6
11
|
require 'gtm_on_rails/tag_helper'
|
7
12
|
|
8
13
|
module GtmOnRails
|
@@ -15,10 +15,10 @@ module GtmOnRails
|
|
15
15
|
objects.each do |object|
|
16
16
|
case object
|
17
17
|
when Hash
|
18
|
-
@objects << GtmOnRails::
|
19
|
-
when GtmOnRails::
|
18
|
+
@objects << GtmOnRails::DataLayer::Object.new(object)
|
19
|
+
when GtmOnRails::DataLayer::Object
|
20
20
|
@objects << object
|
21
|
-
end
|
21
|
+
end
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
@@ -0,0 +1,223 @@
|
|
1
|
+
# Class to take a roll as javascript's object in dataLayer for Enhanced Ecommerce
|
2
|
+
module GtmOnRails
|
3
|
+
class DataLayer::Ecommerce < DataLayer::Object
|
4
|
+
ACTIVITY_TYPES = [:product_impression, :product_click, :product_detail, :add_to_cart, :remove_from_cart, :promotion_impression, :promotion_click, :checkout, :purchase, :refund]
|
5
|
+
|
6
|
+
def initialize(activity_type, **args)
|
7
|
+
raise ArgumentError.new("'#{activity_type}' is undefined activity type.") unless activity_type.in?(ACTIVITY_TYPES)
|
8
|
+
|
9
|
+
@data = send(:"generate_#{activity_type}_hash", args).with_indifferent_access
|
10
|
+
end
|
11
|
+
|
12
|
+
class << self
|
13
|
+
def method_missing(method, *args, &block)
|
14
|
+
if method.in?(ACTIVITY_TYPES)
|
15
|
+
self.new(method, *args)
|
16
|
+
else
|
17
|
+
super
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def to_event(event_name = 'ga_event')
|
23
|
+
GtmOnRails::DataLayer::Event.new(event_name || @data[:event], @data.except(:event).deep_symbolize_keys)
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
def generate_product_impression_hash(args)
|
28
|
+
result = {}
|
29
|
+
|
30
|
+
result[:ecommerce] = {}
|
31
|
+
result[:ecommerce][:currencyCode] = args[:currency] || GtmOnRails.config.ecommerce_default_currency
|
32
|
+
|
33
|
+
if args[:impressions].present?
|
34
|
+
result[:ecommerce][:impressions] = args[:impressions].map{|impression| impression.is_a?(Hash) ? GtmOnRails::DataLayer::Ecommerce::Impression.new(impression) : impression}
|
35
|
+
end
|
36
|
+
|
37
|
+
return result
|
38
|
+
end
|
39
|
+
|
40
|
+
def generate_product_click_hash(args)
|
41
|
+
result = {}
|
42
|
+
|
43
|
+
result[:event_category] = args[:event_category] || 'Enhanced Ecommerce'
|
44
|
+
result[:event_action] = args[:event_action] || 'Product Click'
|
45
|
+
result[:event_label] = args[:event_label] || 'Enhanced Ecommerce Product Click'
|
46
|
+
|
47
|
+
result[:ecommerce] = {}
|
48
|
+
result[:ecommerce][:currencyCode] = args[:currency] || GtmOnRails.config.ecommerce_default_currency
|
49
|
+
|
50
|
+
result[:ecommerce][:click] = {}
|
51
|
+
|
52
|
+
if args[:action].present?
|
53
|
+
action = args[:action].is_a?(Hash) ? GtmOnRails::DataLayer::Ecommerce::Action.new(args[:action]) : args[:action]
|
54
|
+
result[:ecommerce][:click][:actionField] = action
|
55
|
+
end
|
56
|
+
|
57
|
+
if args[:products].present?
|
58
|
+
result[:ecommerce][:click][:products] = args[:products].map{|product| product.is_a?(Hash) ? GtmOnRails::DataLayer::Ecommerce::Product.new(product) : product}
|
59
|
+
end
|
60
|
+
|
61
|
+
return result
|
62
|
+
end
|
63
|
+
|
64
|
+
def generate_product_detail_hash(args)
|
65
|
+
result = {}
|
66
|
+
|
67
|
+
result[:ecommerce] = {}
|
68
|
+
result[:ecommerce][:currencyCode] = args[:currency] || GtmOnRails.config.ecommerce_default_currency
|
69
|
+
|
70
|
+
result[:ecommerce][:detail] = {}
|
71
|
+
|
72
|
+
if args[:action].present?
|
73
|
+
action = args[:action].is_a?(Hash) ? GtmOnRails::DataLayer::Ecommerce::Action.new(args[:action]) : args[:action]
|
74
|
+
result[:ecommerce][:detail][:actionField] = action
|
75
|
+
end
|
76
|
+
|
77
|
+
if args[:products].present?
|
78
|
+
result[:ecommerce][:detail][:products] = args[:products].map{|product| product.is_a?(Hash) ? GtmOnRails::DataLayer::Ecommerce::Product.new(product) : product}
|
79
|
+
end
|
80
|
+
|
81
|
+
return result
|
82
|
+
end
|
83
|
+
|
84
|
+
def generate_add_to_cart_hash(args)
|
85
|
+
result = {}
|
86
|
+
|
87
|
+
result[:event] = 'addToCart'
|
88
|
+
|
89
|
+
result[:event_category] = args[:event_category] || 'Enhanced Ecommerce'
|
90
|
+
result[:event_action] = args[:event_action] || 'Add to Cart'
|
91
|
+
result[:event_label] = args[:event_label] || 'Enhanced Ecommerce Add to Cart'
|
92
|
+
|
93
|
+
result[:ecommerce] = {}
|
94
|
+
result[:ecommerce][:currencyCode] = args[:currency] || GtmOnRails.config.ecommerce_default_currency
|
95
|
+
|
96
|
+
result[:ecommerce][:add] = {}
|
97
|
+
if args[:products].present?
|
98
|
+
result[:ecommerce][:add][:products] = args[:products].map{|product| product.is_a?(Hash) ? GtmOnRails::DataLayer::Ecommerce::Product.new(product) : product}
|
99
|
+
end
|
100
|
+
|
101
|
+
return result
|
102
|
+
end
|
103
|
+
|
104
|
+
def generate_remove_from_cart_hash(args)
|
105
|
+
result = {}
|
106
|
+
|
107
|
+
result[:event_category] = args[:event_category] || 'Enhanced Ecommerce'
|
108
|
+
result[:event_action] = args[:event_action] || 'Remove from Cart'
|
109
|
+
result[:event_label] = args[:event_label] || 'Enhanced Ecommerce Remove from Cart'
|
110
|
+
|
111
|
+
result[:ecommerce] = {}
|
112
|
+
result[:ecommerce][:currencyCode] = args[:currency] || GtmOnRails.config.ecommerce_default_currency
|
113
|
+
|
114
|
+
result[:ecommerce][:remove] = {}
|
115
|
+
if args[:products].present?
|
116
|
+
result[:ecommerce][:remove][:products] = args[:products].map{|product| product.is_a?(Hash) ? GtmOnRails::DataLayer::Ecommerce::Product.new(product) : product}
|
117
|
+
end
|
118
|
+
|
119
|
+
return result
|
120
|
+
end
|
121
|
+
|
122
|
+
def generate_promotion_impression_hash(args)
|
123
|
+
result = {}
|
124
|
+
|
125
|
+
result[:ecommerce] = {}
|
126
|
+
result[:ecommerce][:currencyCode] = args[:currency] || GtmOnRails.config.ecommerce_default_currency
|
127
|
+
|
128
|
+
result[:ecommerce][:promoView] = {}
|
129
|
+
|
130
|
+
if args[:promotions].present?
|
131
|
+
result[:ecommerce][:promoView][:promotions] = args[:promotions].map{|promotion| promotion.is_a?(Hash) ? GtmOnRails::DataLayer::Ecommerce::Promotion.new(promotion) : promotion}
|
132
|
+
end
|
133
|
+
|
134
|
+
return result
|
135
|
+
end
|
136
|
+
|
137
|
+
def generate_promotion_click_hash(args)
|
138
|
+
result = {}
|
139
|
+
|
140
|
+
result[:event] = 'promotionClick'
|
141
|
+
|
142
|
+
result[:event_category] = args[:event_category] || 'Enhanced Ecommerce'
|
143
|
+
result[:event_action] = args[:event_action] || 'Promotion Click'
|
144
|
+
result[:event_label] = args[:event_label] || 'Enhanced Ecommerce Promotion Click'
|
145
|
+
|
146
|
+
result[:ecommerce] = {}
|
147
|
+
result[:ecommerce][:currencyCode] = args[:currency] || GtmOnRails.config.ecommerce_default_currency
|
148
|
+
|
149
|
+
result[:ecommerce][:promoClick] = {}
|
150
|
+
|
151
|
+
if args[:promotions].present?
|
152
|
+
result[:ecommerce][:promoClick][:promotions] = args[:promotions].map{|promotion| promotion.is_a?(Hash) ? GtmOnRails::DataLayer::Ecommerce::Promotion.new(promotion) : promotion}
|
153
|
+
end
|
154
|
+
|
155
|
+
return result
|
156
|
+
end
|
157
|
+
|
158
|
+
def generate_checkout_hash(args)
|
159
|
+
result = {}
|
160
|
+
|
161
|
+
result[:event] = 'checkout'
|
162
|
+
|
163
|
+
result[:event_category] = args[:event_category] || 'Enhanced Ecommerce'
|
164
|
+
result[:event_action] = args[:event_action] || 'Checkout'
|
165
|
+
result[:event_label] = args[:event_label] || 'Enhanced Ecommerce Checkout'
|
166
|
+
|
167
|
+
result[:ecommerce] = {}
|
168
|
+
result[:ecommerce][:currencyCode] = args[:currency] || GtmOnRails.config.ecommerce_default_currency
|
169
|
+
|
170
|
+
result[:ecommerce][:checkout] = {}
|
171
|
+
|
172
|
+
if args[:action].present?
|
173
|
+
action = args[:action].is_a?(Hash) ? GtmOnRails::DataLayer::Ecommerce::Action.new(args[:action]) : args[:action]
|
174
|
+
result[:ecommerce][:checkout][:actionField] = action
|
175
|
+
end
|
176
|
+
|
177
|
+
if args[:products].present?
|
178
|
+
result[:ecommerce][:checkout][:products] = args[:products].map{|product| product.is_a?(Hash) ? GtmOnRails::DataLayer::Ecommerce::Product.new(product) : product}
|
179
|
+
end
|
180
|
+
|
181
|
+
return result
|
182
|
+
end
|
183
|
+
|
184
|
+
def generate_purchase_hash(args)
|
185
|
+
result = {}
|
186
|
+
|
187
|
+
result[:ecommerce] = {}
|
188
|
+
result[:ecommerce][:currencyCode] = args[:currency] || GtmOnRails.config.ecommerce_default_currency
|
189
|
+
|
190
|
+
result[:ecommerce][:purchase] = {}
|
191
|
+
|
192
|
+
action = args[:action] || {}
|
193
|
+
action = action.is_a?(Hash) ? GtmOnRails::DataLayer::Ecommerce::Action.new(action) : action
|
194
|
+
result[:ecommerce][:purchase][:actionField] = action
|
195
|
+
|
196
|
+
if args[:products].present?
|
197
|
+
result[:ecommerce][:purchase][:products] = args[:products].map{|product| product.is_a?(Hash) ? GtmOnRails::DataLayer::Ecommerce::Product.new(product) : product}
|
198
|
+
end
|
199
|
+
|
200
|
+
return result
|
201
|
+
end
|
202
|
+
|
203
|
+
def generate_refund_hash(args)
|
204
|
+
result = {}
|
205
|
+
|
206
|
+
result[:ecommerce] = {}
|
207
|
+
result[:ecommerce][:currencyCode] = args[:currency] || GtmOnRails.config.ecommerce_default_currency
|
208
|
+
|
209
|
+
result[:ecommerce][:refund] = {}
|
210
|
+
|
211
|
+
if args[:action].present?
|
212
|
+
action = args[:action].is_a?(Hash) ? GtmOnRails::DataLayer::Ecommerce::Action.new(args[:action]) : args[:action]
|
213
|
+
result[:ecommerce][:refund][:actionField] = action
|
214
|
+
end
|
215
|
+
|
216
|
+
if args[:products].present?
|
217
|
+
result[:ecommerce][:refund][:products] = args[:products].map{|product| product.is_a?(Hash) ? GtmOnRails::DataLayer::Ecommerce::Product.new(product) : product}
|
218
|
+
end
|
219
|
+
|
220
|
+
return result
|
221
|
+
end
|
222
|
+
end
|
223
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# Class to take a roll as javascript's object in dataLayer for actionFieldObject of Enhanced Ecommerce
|
2
|
+
module GtmOnRails
|
3
|
+
class DataLayer::Ecommerce::Action < DataLayer::Object
|
4
|
+
def initialize(**args)
|
5
|
+
@data = {}
|
6
|
+
|
7
|
+
@data[:id] = args[:id] if args[:id].present?
|
8
|
+
@data[:affiliation] = args[:affiliation] if args[:affiliation].present?
|
9
|
+
@data[:revenue] = args[:revenue] if args[:revenue].present?
|
10
|
+
@data[:tax] = args[:tax] if args[:tax].present?
|
11
|
+
@data[:shipping] = args[:shipping] if args[:shipping].present?
|
12
|
+
@data[:coupon] = args[:coupon] if args[:coupon].present?
|
13
|
+
@data[:list] = args[:list] if args[:list].present?
|
14
|
+
@data[:step] = args[:step] if args[:step].present?
|
15
|
+
@data[:option] = args[:option] if args[:option].present?
|
16
|
+
end
|
17
|
+
|
18
|
+
def to_js
|
19
|
+
to_json
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# Class to take a roll as javascript's object in dataLayer for impressionFieldObjects of Enhanced Ecommerce
|
2
|
+
module GtmOnRails
|
3
|
+
class DataLayer::Ecommerce::Impression < DataLayer::Object
|
4
|
+
def initialize(**args)
|
5
|
+
raise ArgumentError.new("required either 'id' or 'name', or both.") if args[:id].blank? && args[:name].blank?
|
6
|
+
|
7
|
+
@data = {}
|
8
|
+
|
9
|
+
@data[:id] = args[:id] if args[:id].present?
|
10
|
+
@data[:name] = args[:name] if args[:name].present?
|
11
|
+
@data[:list] = args[:list] if args[:list].present?
|
12
|
+
@data[:brand] = args[:brand] if args[:brand].present?
|
13
|
+
@data[:variant] = args[:variant] if args[:variant].present?
|
14
|
+
@data[:position] = args[:position] if args[:position].present?
|
15
|
+
@data[:price] = args[:price] if args[:price].present?
|
16
|
+
if args[:category].present?
|
17
|
+
if args[:category].is_a?(Array)
|
18
|
+
@data[:category] = args[:category].join('/')
|
19
|
+
else
|
20
|
+
@data[:category] = args[:category]
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def to_js
|
26
|
+
to_json
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# Class to take a roll as javascript's object in dataLayer for productFieldObjects of Enhanced Ecommerce
|
2
|
+
module GtmOnRails
|
3
|
+
class DataLayer::Ecommerce::Product < DataLayer::Object
|
4
|
+
def initialize(**args)
|
5
|
+
raise ArgumentError.new("required either 'id' or 'name', or both.") if args[:id].blank? && args[:name].blank?
|
6
|
+
|
7
|
+
@data = {}
|
8
|
+
|
9
|
+
@data[:id] = args[:id] if args[:id].present?
|
10
|
+
@data[:name] = args[:name] if args[:name].present?
|
11
|
+
@data[:brand] = args[:brand] if args[:brand].present?
|
12
|
+
@data[:variant] = args[:variant] if args[:variant].present?
|
13
|
+
@data[:price] = args[:price] if args[:price].present?
|
14
|
+
@data[:quantity] = args[:quantity] if args[:quantity].present?
|
15
|
+
@data[:coupon] = args[:coupon] if args[:coupon].present?
|
16
|
+
@data[:position] = args[:position] if args[:position].present?
|
17
|
+
if args[:category].present?
|
18
|
+
if args[:category].is_a?(Array)
|
19
|
+
raise ArgumentError.new("'category' can be up to 5.") if args[:category].count > 5
|
20
|
+
@data[:category] = args[:category].join('/')
|
21
|
+
else
|
22
|
+
@data[:category] = args[:category]
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
# Custom Dimensions
|
27
|
+
dimension_keys = args.keys.map(&:to_s).select{|key| key.match(/^dimension[0-9]+/)}.map(&:to_sym)
|
28
|
+
dimension_keys.each do |dimension_key|
|
29
|
+
@data[dimension_key] = args[dimension_key]
|
30
|
+
end
|
31
|
+
|
32
|
+
# Custom Metrics
|
33
|
+
metric_keys = args.keys.map(&:to_s).select{|key| key.match(/^metric[0-9]+/)}.map(&:to_sym)
|
34
|
+
metric_keys.each do |metric_key|
|
35
|
+
@data[metric_key] = args[metric_key]
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def to_js
|
40
|
+
to_json
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# Class to take a roll as javascript's object in dataLayer for promoFieldObjects of Enhanced Ecommerce
|
2
|
+
module GtmOnRails
|
3
|
+
class DataLayer::Ecommerce::Promotion < DataLayer::Object
|
4
|
+
def initialize(**args)
|
5
|
+
raise ArgumentError.new("required either 'id' or 'name', or both.") if args[:id].blank? && args[:name].blank?
|
6
|
+
|
7
|
+
@data = {}
|
8
|
+
|
9
|
+
@data[:id] = args[:id] if args[:id].present?
|
10
|
+
@data[:name] = args[:name] if args[:name].present?
|
11
|
+
@data[:creative] = args[:creative] if args[:creative].present?
|
12
|
+
@data[:position] = args[:position] if args[:position].present?
|
13
|
+
end
|
14
|
+
|
15
|
+
def to_js
|
16
|
+
to_json
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# Class to take a roll as javascript's object in dataLayer for google tag manager event
|
2
2
|
module GtmOnRails
|
3
|
-
class
|
4
|
-
def initialize(event_name, **args)
|
3
|
+
class DataLayer::Event < DataLayer::Object
|
4
|
+
def initialize(event_name = 'ga_event', **args)
|
5
5
|
@data = args.merge(event: event_name).with_indifferent_access
|
6
6
|
end
|
7
7
|
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# Class to take a roll as javascript's object in dataLayer
|
2
2
|
module GtmOnRails
|
3
|
-
class
|
3
|
+
class DataLayer::Object
|
4
4
|
attr_accessor :data
|
5
5
|
|
6
6
|
def initialize(**args)
|
@@ -11,12 +11,18 @@ module GtmOnRails
|
|
11
11
|
@data.merge!(hash)
|
12
12
|
end
|
13
13
|
|
14
|
-
def
|
15
|
-
@data.
|
14
|
+
def as_json(options = nil)
|
15
|
+
@data.as_json(options)
|
16
16
|
end
|
17
17
|
|
18
|
-
def
|
19
|
-
|
18
|
+
def to_json(options = nil)
|
19
|
+
hash = as_json(options)
|
20
|
+
|
21
|
+
hash.to_json
|
22
|
+
end
|
23
|
+
|
24
|
+
def to_js(options = nil)
|
25
|
+
"dataLayer.push(#{self.to_json(options)});".html_safe
|
20
26
|
end
|
21
27
|
|
22
28
|
def method_missing(method, *args, &block)
|
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.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ykogure
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-09-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -59,8 +59,13 @@ files:
|
|
59
59
|
- lib/gtm_on_rails/controllers/initialize_data_layer.rb
|
60
60
|
- lib/gtm_on_rails/engine.rb
|
61
61
|
- lib/gtm_on_rails/models/data_layer.rb
|
62
|
-
- lib/gtm_on_rails/models/
|
63
|
-
- lib/gtm_on_rails/models/
|
62
|
+
- lib/gtm_on_rails/models/data_layer/ecommerce.rb
|
63
|
+
- lib/gtm_on_rails/models/data_layer/ecommerce/action.rb
|
64
|
+
- lib/gtm_on_rails/models/data_layer/ecommerce/impression.rb
|
65
|
+
- lib/gtm_on_rails/models/data_layer/ecommerce/product.rb
|
66
|
+
- lib/gtm_on_rails/models/data_layer/ecommerce/promotion.rb
|
67
|
+
- lib/gtm_on_rails/models/data_layer/event.rb
|
68
|
+
- lib/gtm_on_rails/models/data_layer/object.rb
|
64
69
|
- lib/gtm_on_rails/tag_helper.rb
|
65
70
|
- lib/gtm_on_rails/version.rb
|
66
71
|
homepage: https://github.com/ZIGExN/gtm_on_rails
|