Module: GoogleTagManager

Defined in:
lib/google-tag-manager-rails.rb,
lib/google-tag-manager/version.rb

Defined Under Namespace

Modules: Rails

Constant Summary collapse

PLACEHOLDER_GTM_ID =
"GTM-XXXX"
VERSION =
"0.1.3"

Class Method Summary collapse

Class Method Details

.gtm_idObject



7
8
9
# File 'lib/google-tag-manager-rails.rb', line 7

def self.gtm_id
  @@gtm_id ||= PLACEHOLDER_GTM_ID
end

.gtm_id=(gtm_id) ⇒ Object



10
11
12
# File 'lib/google-tag-manager-rails.rb', line 10

def self.gtm_id=(gtm_id)
  @@gtm_id = gtm_id
end

.to_htmlObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/google-tag-manager-rails.rb', line 14

def self.to_html
  <<-HTML
<!-- Google Tag Manager -->
<noscript><iframe src="//www.googletagmanager.com/ns.html?id=#{gtm_id}"
height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
<script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
'//www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
})(window,document,'script','dataLayer','#{gtm_id}');</script>
<!-- End Google Tag Manager -->
  HTML

end

.valid_gtm_id?Boolean

Returns:

  • (Boolean)


4
5
6
# File 'lib/google-tag-manager-rails.rb', line 4

def self.valid_gtm_id?
   gtm_id.nil? || gtm_id == "" || gtm_id == PLACEHOLDER_GTM_ID ? false : true
end