Module: Rubaidh::GoogleAnalyticsMixin

Defined in:
lib/rubaidh/google_analytics.rb

Overview

This module gets mixed in to ActionController::Base

Instance Method Summary collapse

Instance Method Details

#add_google_analytics_codeObject

An after_filter to automatically add the analytics code. If you intend to use the link_to_tracked view helpers, you need to set Rubaidh::GoogleAnalytics.defer_load = false to load the code at the top of the page (see www.google.com/support/googleanalytics/bin/answer.py?answer=55527&topic=11006)



19
20
21
22
23
24
25
# File 'lib/rubaidh/google_analytics.rb', line 19

def add_google_analytics_code
  if GoogleAnalytics.defer_load
    response.body.sub! /<\/[bB][oO][dD][yY]>/, "#{google_analytics_code}</body>" if response.body.respond_to?(:sub!)
  else
    response.body.sub! /(<[bB][oO][dD][yY][^>]*>)/, "\\1#{google_analytics_code}" if response.body.respond_to?(:sub!)
  end
end

#google_analytics_codeObject

The javascript code to enable Google Analytics on the current page. Normally you won’t need to call this directly; the add_google_analytics_code after filter will insert it for you.



11
12
13
# File 'lib/rubaidh/google_analytics.rb', line 11

def google_analytics_code
  GoogleAnalytics.google_analytics_code(request.ssl?) if GoogleAnalytics.enabled?(request.format)
end