Class: TheTracker::Trackers::Gtm

Inherits:
Base
  • Object
show all
Defined in:
lib/the_tracker/trackers/gtm.rb

Instance Attribute Summary collapse

Attributes inherited from Base

#active

Instance Method Summary collapse

Methods inherited from Base

#body_bottom, #header

Constructor Details

#initialize(options) ⇒ Gtm

Gtm info



8
9
10
11
# File 'lib/the_tracker/trackers/gtm.rb', line 8

def initialize(options)
  @gtmid = options[:gtmid]
  super()
end

Instance Attribute Details

#data_layer=(value) ⇒ Object

Sets the attribute data_layer

Parameters:

  • value

    the value to set the attribute data_layer to.



5
6
7
# File 'lib/the_tracker/trackers/gtm.rb', line 5

def data_layer=(value)
  @data_layer = value
end

Instance Method Details

#add_data_layer(data, value) ⇒ Object



33
34
35
# File 'lib/the_tracker/trackers/gtm.rb', line 33

def add_data_layer(data, value)
  data_layer[data] = value
end

#body_topObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/the_tracker/trackers/gtm.rb', line 17

def body_top
  return if !active
  <<-EOF
    #{show_data_layer}
    <!-- Google Tag Manager -->
    <noscript><iframe src="//www.googletagmanager.com/ns.html?id=#{@gtmid}"
    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','#{@gtmid}');</script>
    <!-- End Google Tag Manager -->
  EOF
end

#nameObject



13
14
15
# File 'lib/the_tracker/trackers/gtm.rb', line 13

def name
  :gtm
end