Class: Consently::Providers::GoogleTagManager

Inherits:
Base
  • Object
show all
Defined in:
lib/consently/providers/google_tag_manager.rb

Constant Summary

Constants inherited from Base

Base::SAFE_OPTION

Instance Attribute Summary

Attributes inherited from Base

#category, #key, #options

Instance Method Summary collapse

Methods inherited from Base

build, cookie, cookie_manifest, #cookies, google?, #google?, #initialize, provider_key, provider_key=, register, registry, #to_s

Constructor Details

This class inherits a constructor from Consently::Providers::Base

Instance Method Details

#noscriptObject



20
21
22
# File 'lib/consently/providers/google_tag_manager.rb', line 20

def noscript
  %(<iframe src="https://www.googletagmanager.com/ns.html?id=#{id}" height="0" width="0" style="display:none;visibility:hidden"></iframe>)
end

#scriptsObject

None of its own: whatever it loads brings its own cookies, so list those tags here as well if you manage them through the container.



11
12
13
14
15
16
17
18
# File 'lib/consently/providers/google_tag_manager.rb', line 11

def scripts
  [ Script.new(inline: <<~JS.strip) ]
    (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='https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
    })(window,document,'script','dataLayer','#{id}');
  JS
end