Class: EmbedGoogle::Analytics
- Inherits:
-
Object
- Object
- EmbedGoogle::Analytics
- Defined in:
- lib/embed_google/analytics.rb
Class Attribute Summary collapse
-
.id ⇒ Object
Returns the value of attribute id.
Instance Attribute Summary collapse
-
#account_id ⇒ Object
Returns the value of attribute account_id.
Instance Method Summary collapse
-
#initialize(id = nil, options = {}) ⇒ Analytics
constructor
A new instance of Analytics.
- #script ⇒ Object
Constructor Details
#initialize(id = nil, options = {}) ⇒ Analytics
Returns a new instance of Analytics.
9 10 11 12 |
# File 'lib/embed_google/analytics.rb', line 9 def initialize(id=nil, ={}) self.account_id = id || self.class.id raise ArgumentError, 'Account ID is required' unless account_id end |
Class Attribute Details
.id ⇒ Object
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_id ⇒ Object
Returns the value of attribute account_id.
7 8 9 |
# File 'lib/embed_google/analytics.rb', line 7 def account_id @account_id end |
Instance Method Details
#script ⇒ Object
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', '#{account_id}']);\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 |