gtm_on_rails 0.1.1 → 0.1.2
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 +35 -0
- data/README.md +48 -7
- data/lib/generators/templates/gtm_on_rails.rb +1 -1
- data/lib/gtm_on_rails/models/data_layer.rb +2 -2
- data/lib/gtm_on_rails/models/data_layer_object.rb +16 -2
- 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: 161f6aefbee25eb72bbde39f556a1d31922c9e85
|
4
|
+
data.tar.gz: 02ed437da032b4b921858401559a5acfcebe84cd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 04f69bbb0adffce5e6994147dee884009ec61a5c8ba90c7c09ce932177c433518cd8ae47ef5e3fcd2be4fd71ba330be826c8c043ab9d1d241fe92063d068c255
|
7
|
+
data.tar.gz: 0cce859b62d1a8f8c3fb8487f9515546be86c9fce823755d2af346ddecfe9c33b314919ae015861888adde7495035bc40a25813dcdfeebca4e4216c513638e6d
|
data/README.ja.md
CHANGED
@@ -37,6 +37,41 @@ controller名とaction名はJavaScriptのコードとしてHTMLのソースコ
|
|
37
37
|
この設定を有効にすることによって、JavaScriptのコードとして出力される際に、dataLayerに設定した値などの問題でエラーが発生場合にエラーを握りつぶします。
|
38
38
|
つまり、計測周りのエラーによってサイトの表示に影響が出ないようにします。
|
39
39
|
|
40
|
+
## Usage
|
41
|
+
#### 基本
|
42
|
+
`data_layer`という変数(正確にはhelperが呼び出す変数@gtm_on_rails_data_layer)にdataLayerで送信したい内容をHash型で追加するだけでdataLayerで好きな値を送信できます。
|
43
|
+
controller内等で以下のように記述する感じになると思います。
|
44
|
+
|
45
|
+
```ruby
|
46
|
+
data_layer.push({
|
47
|
+
name: 'name'
|
48
|
+
})
|
49
|
+
```
|
50
|
+
|
51
|
+
送信したdataLayerの内容は、GoogleTagManager側で変数に設定する等して使用して下さい。
|
52
|
+
|
53
|
+
#### `GtmOnRails::DataLayerObject`
|
54
|
+
```ruby
|
55
|
+
object = GtmOnRails::DataLayerObject.new({name: 'name'})
|
56
|
+
data_layer.push(object)
|
57
|
+
```
|
58
|
+
Hash形式ではなく、上記のように`GtmOnRails::DataLayerObject`クラスを用いることもできます。
|
59
|
+
|
60
|
+
```ruby
|
61
|
+
object = GtmOnRails::DataLayerObject.new({name: 'name'})
|
62
|
+
puts object.name
|
63
|
+
```
|
64
|
+
`GtmOnRails::DataLayerObject`クラスでは、上記のように値にアクセスできます。
|
65
|
+
|
66
|
+
|
67
|
+
#### `GtmOnRails::DataLayerEvent`
|
68
|
+
```ruby
|
69
|
+
event = GtmOnRails::DataLayerEvent.new('イベント名', {name: 'name'})
|
70
|
+
data_layer.push(event)
|
71
|
+
```
|
72
|
+
上記のように記述することで、イベント名を設定して送信できます。
|
73
|
+
|
74
|
+
|
40
75
|
## License
|
41
76
|
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
42
77
|
|
data/README.md
CHANGED
@@ -1,5 +1,9 @@
|
|
1
1
|
# GTMonRails
|
2
|
-
GTMonRails enables you to integrate Google Tag Manager easy.
|
2
|
+
GTMonRails enables you to integrate Google Tag Manager easy with Rails application.
|
3
|
+
|
4
|
+
GTMonRails not only embed Google Tag Manager snippet, but simply operate and send JavaScript's variable 'dataLayer' for GTM in Ruby code.
|
5
|
+
|
6
|
+
GTMonRails basically can't be used only this, you have to set up Tag and Trigger on Google Tag Manager.
|
3
7
|
|
4
8
|
*Read this in other languages: [日本語](README.ja.md)*
|
5
9
|
|
@@ -15,21 +19,58 @@ And then execute:
|
|
15
19
|
$ bundle
|
16
20
|
```
|
17
21
|
|
18
|
-
And then
|
22
|
+
And then run initial settings:
|
19
23
|
```bash
|
20
24
|
$ rails g gtm_on_rails:install
|
21
25
|
```
|
22
26
|
|
23
|
-
Or install it yourself as:
|
24
|
-
```bash
|
25
|
-
$ gem install gtm_on_rails
|
26
|
-
```
|
27
|
-
|
28
27
|
## Configure
|
28
|
+
Edit the `/config/initializers/gtm_on_rails.rb` file and customize following settings.
|
29
29
|
#### container_id
|
30
|
+
Set your Google Tag Manager container ID.
|
30
31
|
#### data_layer_limit_byte_size
|
32
|
+
DataLayer is limited by bytesize at once post. If post size is over this bytesize, exception occured.
|
31
33
|
#### send_controller_and_action_in_data_layer
|
34
|
+
Settings that send google tag manager controller and action name by dataLayer.
|
35
|
+
Be careful using this, if you enable this option, controller and action name output in html source code.
|
32
36
|
#### rescue_when_error_occurred
|
37
|
+
If somthing error occurred when output tags, subsequent tag's output is stopped and run subsequent processing.
|
38
|
+
The point is, dataLayer error won't affect displaying website, if you enable this option.
|
39
|
+
|
40
|
+
## Usage
|
41
|
+
#### Basic
|
42
|
+
You only push Hash object in `data_layer` variable, can send values what you want by dataLayer.
|
43
|
+
Usually I’d say you write like the following code in contoller.
|
44
|
+
|
45
|
+
```ruby
|
46
|
+
data_layer.push({
|
47
|
+
name: 'name'
|
48
|
+
})
|
49
|
+
```
|
50
|
+
Configure the variable and so on Google Tag Manager when use sended values.
|
51
|
+
|
52
|
+
#### `GtmOnRails::DataLayerObject`
|
53
|
+
```ruby
|
54
|
+
object = GtmOnRails::DataLayerObject.new({name: 'name'})
|
55
|
+
data_layer.push(object)
|
56
|
+
```
|
57
|
+
You also can use `GtmOnRails::DataLayerObject` object rather than Hash as the above.
|
58
|
+
|
59
|
+
```ruby
|
60
|
+
object = GtmOnRails::DataLayerObject.new({name: 'name'})
|
61
|
+
puts object.name
|
62
|
+
```
|
63
|
+
You can access values with `GtmOnRails::DataLayerObject` object as the above.
|
64
|
+
|
65
|
+
#### `GtmOnRails::DataLayerEvent`
|
66
|
+
```ruby
|
67
|
+
event = GtmOnRails::DataLayerEvent.new('イベント名', {name: 'name'})
|
68
|
+
data_layer.push(event)
|
69
|
+
```
|
70
|
+
You can send dataLayer with Google Tag Manager's event name, when write like the above code.
|
33
71
|
|
34
72
|
## License
|
35
73
|
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
74
|
+
|
75
|
+
## Author
|
76
|
+
[ykogure](https://github.com/ykogure)
|
@@ -11,6 +11,6 @@ GtmOnRails.configure do |config|
|
|
11
11
|
config.send_controller_and_action_in_data_layer = false
|
12
12
|
|
13
13
|
# If somthing error occurred when output tags, subsequent tag's output is stopped and run subsequent processing.
|
14
|
-
# The point is, dataLayer error won't affect displaying website, if this option
|
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
16
|
end
|
@@ -7,7 +7,7 @@ module GtmOnRails
|
|
7
7
|
|
8
8
|
def initialize(*args)
|
9
9
|
options = args.extract_options!
|
10
|
-
@objects = args # @objects
|
10
|
+
@objects = args # @objects are instances of GTM::DataLayerObject
|
11
11
|
end
|
12
12
|
|
13
13
|
def push(objects)
|
@@ -33,7 +33,7 @@ module GtmOnRails
|
|
33
33
|
raise ArgumentError.new("DataLayer bytesize is over limit #{GtmOnRails.config.data_layer_limit_byte_size} bytes. Size is #{size} bytes.")
|
34
34
|
end
|
35
35
|
|
36
|
-
js_codes <<
|
36
|
+
js_codes << data_layer_object.to_js
|
37
37
|
end
|
38
38
|
|
39
39
|
return content_tag(:script, js_codes.join.html_safe)
|
@@ -15,9 +15,23 @@ module GtmOnRails
|
|
15
15
|
@data.to_json
|
16
16
|
end
|
17
17
|
|
18
|
+
def to_js
|
19
|
+
"dataLayer.push(#{self.to_json});"
|
20
|
+
end
|
21
|
+
|
18
22
|
def method_missing(method, *args, &block)
|
19
|
-
if
|
20
|
-
|
23
|
+
if method.to_s.end_with?('=')
|
24
|
+
key = method.to_s.chop.to_sym
|
25
|
+
_method = :[]=
|
26
|
+
_args = [key] + args
|
27
|
+
else
|
28
|
+
key = method
|
29
|
+
_method = :[]
|
30
|
+
_args = [key]
|
31
|
+
end
|
32
|
+
|
33
|
+
if @data.has_key?(key)
|
34
|
+
@data.send(_method, *_args)
|
21
35
|
else
|
22
36
|
super
|
23
37
|
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.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ykogure
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-05-
|
11
|
+
date: 2017-05-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|