class GoogleTagManager
Public Instance Methods
after_configuration()
click to toggle source
# File lib/middleman-google-tag-manager.rb, line 7 def after_configuration unless options.container_id $stderr.puts 'Google Tag Manager: Please specify a container ID' raise ArgumentError, 'No container ID given' if display? end end
google_tag_manager()
click to toggle source
# File lib/middleman-google-tag-manager.rb, line 15 def google_tag_manager options = extensions[:google_tag_manager].options return unless !legacy_development? || options.development @text ||= <<-END.gsub(/^ {8}/, '') <!-- Google Tag Manager --> <noscript><iframe src="//www.googletagmanager.com/ns.html?id=#{options.container_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','#{options.container_id}');</script> <!-- End Google Tag Manager --> END end
legacy_development?()
click to toggle source
Support for Middleman >= 3.4
# File lib/middleman-google-tag-manager.rb, line 33 def legacy_development? # Middleman 3.4 is_development = try(:development?) unless is_development.nil? return is_development end # Middleman 4.x app.development? end
Private Instance Methods
display?()
click to toggle source
# File lib/middleman-google-tag-manager.rb, line 47 def display? app.build? || app.development? && options.development end