Class: Analytical::Modules::Google

Inherits:
Object
  • Object
show all
Includes:
Base
Defined in:
lib/analytical/modules/google.rb

Instance Attribute Summary

Attributes included from Base

#command_store, #initialized, #options, #tracking_command_location

Instance Method Summary collapse

Methods included from Base

#init_location, #init_location?, #process_queued_commands, #protocol, #queue

Constructor Details

#initialize(options = {}) ⇒ Google

Returns a new instance of Google.



6
7
8
9
# File 'lib/analytical/modules/google.rb', line 6

def initialize(options={})
  super
  @tracking_command_location = :head_append
end

Instance Method Details

#event(name, *args) ⇒ Object



36
37
38
39
40
41
# File 'lib/analytical/modules/google.rb', line 36

def event(name, *args)
  data = args.first || {}
  data = data[:value] if data.is_a?(Hash)
  data_string = !data.nil? ? ", #{data}" : ""
  "_gaq.push(['_trackEvent', \"Event\", \"#{name}\"" + data_string + "]);"
end

#init_javascript(location) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/analytical/modules/google.rb', line 11

def init_javascript(location)
  init_location(location) do
    js = "    <!-- Analytical Init: Google -->\n    <script type=\"text/javascript\">\n      var _gaq = _gaq || [];\n      _gaq.push(['_setAccount', '\#{options[:key]}']);\n      _gaq.push(['_setDomainName', '\#{options[:domain]}']);\n      \#{\"_gaq.push(['_setAllowLinker', true]);\" if options[:allow_linker]}\n      _gaq.push(['_trackPageview']);\n      (function() {\n        var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;\n        ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';\n        var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);\n      })();\n    </script>\n    HTML\n    js\n  end\nend\n"

#track(*args) ⇒ Object



32
33
34
# File 'lib/analytical/modules/google.rb', line 32

def track(*args)
  "_gaq.push(['_trackPageview'#{args.empty? ? ']' : ', "' + args.first + '"]'});"
end