Module: Bacchanalytics::GoogleAnalytics::Base

Included in:
AdwordsConversion, Analytics, WebsiteOptimizer
Defined in:
lib/bacchanalytics/google_analytics.rb

Instance Method Summary collapse

Instance Method Details

#load_ga_srcObject

Return the javascript code used to load google analytics code



6
7
8
9
10
11
12
13
14
# File 'lib/bacchanalytics/google_analytics.rb', line 6

def load_ga_src
  <<-SCRIPT
    (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
    })();
  SCRIPT
end

#response_source(response) ⇒ Object



25
26
27
28
29
# File 'lib/bacchanalytics/google_analytics.rb', line 25

def response_source(response)
  source = nil
  response.each { |fragment| (source) ? (source << fragment) : (source = fragment) }
  source
end

#should_instrument?(headers) ⇒ Boolean

headers will be nil if the status of the response is 304 (Not Modified) From the HTTP Status Code Definitions: If the client has performed a conditional GET request and access is allowed, but the document has not been modified, the server SHOULD respond with this status code. www.w3.org/Protocols/rfc2616/rfc2616-sec10.html

Returns:

  • (Boolean)


21
22
23
# File 'lib/bacchanalytics/google_analytics.rb', line 21

def should_instrument?(headers)
  !headers["Content-Type"].nil? && (headers["Content-Type"].include? "text/html")
end