gtm_rails 0.1.0
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 +7 -0
- data/LICENSE +19 -0
- data/README.md +60 -0
- data/lib/gtm_rails.rb +5 -0
- data/lib/gtm_rails/config.rb +9 -0
- data/lib/gtm_rails/helper.rb +21 -0
- data/lib/gtm_rails/hooks.rb +17 -0
- data/lib/gtm_rails/railtie.rb +9 -0
- data/lib/gtm_rails/version.rb +3 -0
- data/lib/gtm_rails/yaml_loader.rb +23 -0
- metadata +94 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 71fcae571ffbb04c94123e71552fea23417f812d
|
4
|
+
data.tar.gz: b6340e272eec3ca50ddfd3d08fdc7e51b2c448bb
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c07325a4baa3a6e3e48cf7206ade905eb58016a8173dc13b667fc7c97feb184b385f7ea8675fffc1ad45ada5fc61e5c2ba0ee5740fdcc1401e983a34938b3ad1
|
7
|
+
data.tar.gz: cefc83f80fc492f2cc0e913020acc120f4b2fb9df5dac4e785a6307ff27931981a0479f22a9e288d0a4e6209b873a27e735acabb725dd35252eec5aaf1e63153
|
data/LICENSE
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
Copyright (c) 2017 Koichi ITO
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
of this software and associated documentation files (the "Software"), to deal
|
5
|
+
in the Software without restriction, including without limitation the rights
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
copies of the Software, and to permit persons to whom the Software is
|
8
|
+
furnished to do so, subject to the following conditions:
|
9
|
+
|
10
|
+
The above copyright notice and this permission notice shall be included in
|
11
|
+
all copies or substantial portions of the Software.
|
12
|
+
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
# gtm_rails
|
2
|
+
|
3
|
+
Simply embed Google Tag Manager container snippet into Rails application.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add these lines to your application's Gemfile:
|
8
|
+
|
9
|
+
```
|
10
|
+
gem 'gtm_rails'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
```
|
16
|
+
$ bundle
|
17
|
+
```
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
```
|
22
|
+
$ gem install gtm_rails
|
23
|
+
```
|
24
|
+
|
25
|
+
## Configuration
|
26
|
+
|
27
|
+
Create `config/google_tag_manager.yml` in your Rails application.
|
28
|
+
|
29
|
+
```yaml
|
30
|
+
development:
|
31
|
+
- foo: GTM-YourGtmId1
|
32
|
+
- bar: GTM-YourGtmId2
|
33
|
+
- baz: GTM-YourGtmId3
|
34
|
+
production:
|
35
|
+
- foo: GTM-YourGtmId4
|
36
|
+
- bar: GTM-YourGtmId5
|
37
|
+
- baz: GTM-YourGtmId6
|
38
|
+
```
|
39
|
+
|
40
|
+
The above is a sample. `foo`, `bar`, `baz` are arbitrary label names.
|
41
|
+
|
42
|
+
In view, use as follows. The argument is a label name specified in `config/google_tag_manager.yml`.
|
43
|
+
|
44
|
+
```ruby
|
45
|
+
<%= google_tag_manager(:foo) %>
|
46
|
+
```
|
47
|
+
|
48
|
+
Google Tag Manager container snippet expands to RAILS_ENV and label name. If there is no match, a blank is returned.
|
49
|
+
|
50
|
+
## Contributing
|
51
|
+
|
52
|
+
1. Fork it
|
53
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
54
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
55
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
56
|
+
5. Create new Pull Request
|
57
|
+
|
58
|
+
## License
|
59
|
+
|
60
|
+
gtm_rails is released under the [MIT License](http://www.opensource.org/licenses/MIT).
|
data/lib/gtm_rails.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
module GtmRails
|
2
|
+
module Helper
|
3
|
+
def google_tag_manager(label)
|
4
|
+
gtm = GtmRails::Config.gtm[label]
|
5
|
+
|
6
|
+
return '' if gtm.blank?
|
7
|
+
|
8
|
+
<<-HTML.html_safe
|
9
|
+
<!-- Google Tag Manager -->
|
10
|
+
<noscript><iframe src="//www.googletagmanager.com/ns.html?id=#{gtm}"
|
11
|
+
height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
|
12
|
+
<script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
|
13
|
+
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
|
14
|
+
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
|
15
|
+
'//www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
|
16
|
+
})(window,document,'script','dataLayer','#{gtm}');</script>
|
17
|
+
<!-- End Google Tag Manager -->
|
18
|
+
HTML
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module GtmRails
|
2
|
+
class Hooks
|
3
|
+
def self.init
|
4
|
+
require 'gtm_rails/yaml_loader'
|
5
|
+
|
6
|
+
loader = ::GtmRails::YamlLoader.new
|
7
|
+
|
8
|
+
gtms = loader.load.fetch(ENV['RAILS_ENV'] || 'development')
|
9
|
+
|
10
|
+
GtmRails::Config.gtm = gtms.each_with_object({}.with_indifferent_access) {|gtm, ret|
|
11
|
+
ret[gtm.keys.first] = gtm.values.first
|
12
|
+
}
|
13
|
+
|
14
|
+
ActionView::Base.send :include, GtmRails::Helper
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module GtmRails
|
2
|
+
class YamlLoader
|
3
|
+
def load
|
4
|
+
yaml = Rails.root.join('config', 'google_tag_manager.yml')
|
5
|
+
|
6
|
+
config = if yaml && yaml.exist?
|
7
|
+
require 'yaml'
|
8
|
+
require 'erb'
|
9
|
+
YAML.load(ERB.new(yaml.read).result) || {}
|
10
|
+
else
|
11
|
+
raise 'Could not load database configuration. No such file - config/google_tag_manager.yml'
|
12
|
+
end
|
13
|
+
|
14
|
+
config
|
15
|
+
rescue Psych::SyntaxError => e
|
16
|
+
raise "YAML syntax error occurred while parsing config/google_tag_manager.yml. " \
|
17
|
+
"Please note that YAML must be consistently indented using spaces. Tabs are not allowed. " \
|
18
|
+
"Error: #{e.message}"
|
19
|
+
rescue => e
|
20
|
+
raise e, "Cannot load `GtmRails:YamlLoader.load`:\n#{e.message}", e.backtrace
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
metadata
ADDED
@@ -0,0 +1,94 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: gtm_rails
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Koichi ITO
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-01-25 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rails
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 4.2.0
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 4.2.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rspec-rails
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 3.0.0
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 3.0.0
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: sqlite3
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: Simply embed Google Tag Manager container snippet into Rails application
|
56
|
+
email: koic.ito@gmail.com
|
57
|
+
executables: []
|
58
|
+
extensions: []
|
59
|
+
extra_rdoc_files: []
|
60
|
+
files:
|
61
|
+
- LICENSE
|
62
|
+
- README.md
|
63
|
+
- lib/gtm_rails.rb
|
64
|
+
- lib/gtm_rails/config.rb
|
65
|
+
- lib/gtm_rails/helper.rb
|
66
|
+
- lib/gtm_rails/hooks.rb
|
67
|
+
- lib/gtm_rails/railtie.rb
|
68
|
+
- lib/gtm_rails/version.rb
|
69
|
+
- lib/gtm_rails/yaml_loader.rb
|
70
|
+
homepage: http://github.com/koic/gtm_rails
|
71
|
+
licenses:
|
72
|
+
- MIT
|
73
|
+
metadata: {}
|
74
|
+
post_install_message:
|
75
|
+
rdoc_options: []
|
76
|
+
require_paths:
|
77
|
+
- lib
|
78
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 2.2.2
|
83
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
84
|
+
requirements:
|
85
|
+
- - ">="
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: '0'
|
88
|
+
requirements: []
|
89
|
+
rubyforge_project:
|
90
|
+
rubygems_version: 2.6.8
|
91
|
+
signing_key:
|
92
|
+
specification_version: 4
|
93
|
+
summary: Simply embed Google Tag Manager container snippet into Rails application
|
94
|
+
test_files: []
|