gtm_rails 0.2.1 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0f6af697231db8b11dba6e63daf23694fcbbb20b
4
- data.tar.gz: 292fb6aa44b4951f2c886084d63543aea001218e
3
+ metadata.gz: f9b47055f9b0503a5da6958685c6143684e8b848
4
+ data.tar.gz: a7aedddc9f401bfbcb1830a7a4da44dcacd54d95
5
5
  SHA512:
6
- metadata.gz: '00437849ccc7cd075a761ca71f63aefdc2ff4c01013fbcb96432670176c3ad1617c774eb6b33c075e09bacc4bc8ea4817360cc760e96ecc2d82be71582259259'
7
- data.tar.gz: 246d5f5380e6dfd7b57aebad8ccd193c2223f0192bddc9082096eb100f73a8d5984324f2e379c47d57d6933ca474b6cc675a5518ce72fca82de791b48fbf5887
6
+ metadata.gz: 7901270779c9cb549424e6c402014676fabec9a9664eadd47a8ade816d5ebb27810396bc3fb91848e81c82f630055e8646b9e5202011cb94219b071558bb3e53
7
+ data.tar.gz: c3f811f8936e4afb3afc9f6e7ca2d2a4d38dac74d0eb0ee1779312f833398db74f50b8dd56d5970895ffe9198b83afd01dc6ae0c59d96148e88616f704cf9b42
data/README.md CHANGED
@@ -37,7 +37,7 @@ production:
37
37
  baz: GTM-YourGtmId6
38
38
  ```
39
39
 
40
- The above is a sample. `foo`, `bar`, `baz` are arbitrary label names.
40
+ The above is a sample. `foo`, `bar`, `baz` are arbitrary label names, and replacing GTM-XXXX with your container ID.
41
41
 
42
42
  In view, use as follows. The argument is a label name specified in `config/google_tag_manager.yml`.
43
43
 
@@ -45,7 +45,21 @@ In view, use as follows. The argument is a label name specified in `config/googl
45
45
  <%= google_tag_manager(:foo) %>
46
46
  ```
47
47
 
48
- Google Tag Manager container snippet expands to RAILS_ENV and label name. If there is no match, a blank is returned.
48
+ Or do next 2 steps. (recommended, click here to [read more](https://developers.google.com/tag-manager/quickstart))
49
+
50
+ First, following method as close to the opening `<head>` tag as possible on every page of your website.
51
+
52
+ ```ruby
53
+ <%= google_tag_manager_script_tag(:foo) %>
54
+ ```
55
+
56
+ Second, following method immediately after the opening `<body>` tag on every page of your website.
57
+
58
+ ```ruby
59
+ <%= google_tag_manager_noscript_tag(:foo) %>
60
+ ```
61
+
62
+ Google Tag Manager container snippet will be expanded based on `Rails.env` and label name. If there is no match, a blank string is returned.
49
63
 
50
64
  ## Contributing
51
65
 
@@ -4,6 +4,6 @@ module GtmRails
4
4
  class Config
5
5
  include Singleton
6
6
 
7
- cattr_accessor :gtm
7
+ cattr_accessor :container_ids
8
8
  end
9
9
  end
@@ -1,21 +1,56 @@
1
1
  module GtmRails
2
2
  module Helper
3
3
  def google_tag_manager(label)
4
- gtm = GtmRails::Config.gtm[label]
4
+ container_id = GtmRails::Config.container_ids[label]
5
5
 
6
- return '' if gtm.blank?
6
+ return '' if container_id.blank?
7
7
 
8
8
  <<-HTML.html_safe
9
9
  <!-- Google Tag Manager -->
10
- <noscript><iframe src="//www.googletagmanager.com/ns.html?id=#{gtm}"
10
+ <noscript><iframe src="//www.googletagmanager.com/ns.html?id=#{container_id}"
11
11
  height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
12
12
  <script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
13
13
  new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
14
14
  j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
15
15
  '//www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
16
- })(window,document,'script','dataLayer','#{gtm}');</script>
16
+ })(window,document,'script','dataLayer','#{container_id}');</script>
17
17
  <!-- End Google Tag Manager -->
18
18
  HTML
19
19
  end
20
+
21
+ #
22
+ # Use this method as close to the opening <head> tag as possible on every page of your website.
23
+ #
24
+ def google_tag_manager_script_tag(label)
25
+ container_id = GtmRails::Config.container_ids[label]
26
+
27
+ return '' if container_id.blank?
28
+
29
+ <<-HTML.html_safe
30
+ <!-- Google Tag Manager -->
31
+ <script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
32
+ new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
33
+ j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
34
+ 'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
35
+ })(window,document,'script','dataLayer','#{container_id}');</script>
36
+ <!-- End Google Tag Manager -->
37
+ HTML
38
+ end
39
+
40
+ #
41
+ # Use this method immediately after the opening <body> tag on every page of your website.
42
+ #
43
+ def google_tag_manager_noscript_tag(label)
44
+ container_id = GtmRails::Config.container_ids[label]
45
+
46
+ return '' if container_id.blank?
47
+
48
+ <<-HTML.html_safe
49
+ <!-- Google Tag Manager (noscript) -->
50
+ <noscript><iframe src="https://www.googletagmanager.com/ns.html?id=#{container_id}"
51
+ height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
52
+ <!-- End Google Tag Manager (noscript) -->
53
+ HTML
54
+ end
20
55
  end
21
56
  end
@@ -5,7 +5,7 @@ module GtmRails
5
5
 
6
6
  loader = ::GtmRails::YamlLoader.new
7
7
 
8
- GtmRails::Config.gtm = (loader.load[Rails.env] || {}).with_indifferent_access
8
+ GtmRails::Config.container_ids = (loader.load[Rails.env] || {}).with_indifferent_access
9
9
 
10
10
  ActionView::Base.send :include, GtmRails::Helper
11
11
  end
@@ -1,3 +1,3 @@
1
1
  module GtmRails
2
- VERSION = '0.2.1'
2
+ VERSION = '0.3.0'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gtm_rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Koichi ITO