Module: Bacchanalytics::GoogleAnalytics::TrackingCode

Included in:
Analytics
Defined in:
lib/bacchanalytics/google_analytics.rb

Instance Method Summary collapse

Instance Method Details

#google_analytics_tracking_code(web_property_id, domain_name = nil) ⇒ Object

Construct the new asynchronous version of the Google Analytics code. code.google.com/apis/analytics/docs/tracking/asyncTracking.html



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/bacchanalytics/google_analytics.rb', line 35

def google_analytics_tracking_code(web_property_id, domain_name = nil)
  "    <script type=\"text/javascript\">\n\n    var _gaq = _gaq || [];\n    _gaq.push(['_setAccount', '\#{web_property_id}']);\n    if ('\#{domain_name}' !== ''){\n_gaq.push(['_setDomainName', '\#{domain_name}']);\n    }\n    \#{ignored_organic_script}\n    _gaq.push(['_trackPageview']);\n\n    \#{load_ga_src}\n    </script>\n  SCRIPT\nend\n"

#ignored_organic_scriptObject



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/bacchanalytics/google_analytics.rb', line 52

def ignored_organic_script
  script = ""

  begin
    if @ignored_organic.is_a?(Array)
      @ignored_organic.each { |item|
        script << "  _gaq.push(['_addIgnoredOrganic', '\#{item}']);\n        CODE\n      }\n    elsif @ignored_organic.is_a?(String)\n      script << <<-CODE\n  _gaq.push(['_addIgnoredOrganic', '\#{@ignored_organic}']);\n      CODE\n    end\n  rescue\n  end\n\n  script\nend\n"