Class: EmbedGoogle::Analytics

Inherits:
Object
  • Object
show all
Defined in:
lib/embed_google/analytics.rb

Class Attribute Summary collapse

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id = nil, options = {}) ⇒ Analytics

Returns a new instance of Analytics.

Raises:

  • (ArgumentError)


9
10
11
12
# File 'lib/embed_google/analytics.rb', line 9

def initialize(id=nil, options={})
  self. = id || self.class.id
  raise ArgumentError, 'Account ID is required' unless 
end

Class Attribute Details

.idObject

Returns the value of attribute id.



4
5
6
# File 'lib/embed_google/analytics.rb', line 4

def id
  @id
end

Instance Attribute Details

#account_idObject

Returns the value of attribute account_id.



7
8
9
# File 'lib/embed_google/analytics.rb', line 7

def 
  @account_id
end

Instance Method Details

#scriptObject



14
15
16
17
18
19
20
21
22
23
24
# File 'lib/embed_google/analytics.rb', line 14

def script
  str  = "var _gaq = _gaq || [];\n"
  str += "_gaq.push(['_setAccount', '#{}']);\n"
  str += "_gaq.push(['_trackPageview']);\n\n"
  str += "(function() {\n"
  str += "  var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;\n"
  str += "  ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';\n"
  str += "  var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);\n"
  str += "})();\n"
  "<script type='text/javascript'>\n" + str + "</script>\n"
end