lib/rubaidh/google_analytics.rb in google_analytics-1.1.3 vs lib/rubaidh/google_analytics.rb in google_analytics-1.1.5

- old
+ new

@@ -16,13 +16,13 @@ # 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 http://www.google.com/support/googleanalytics/bin/answer.py?answer=55527&topic=11006) def add_google_analytics_code if GoogleAnalytics.defer_load - response.body.sub! '</body>', "#{google_analytics_code}</body>" if response.body.respond_to?(:sub!) + response.body.sub! /<\/[bB][oO][dD][yY]>/, "#{google_analytics_code}</body>" if response.body.respond_to?(:sub!) else - response.body.sub! '<body>', "<body>#{google_analytics_code}" if response.body.respond_to?(:sub!) + response.body.sub! /(<[bB][oO][dD][yY][^>]*>)/, "\\1#{google_analytics_code}" if response.body.respond_to?(:sub!) end end end class GoogleAnalyticsConfigurationError < StandardError; end @@ -172,13 +172,15 @@ end code << <<-HTML <script type="text/javascript"> <!--//--><![CDATA[//><!-- + try { var pageTracker = _gat._getTracker('#{request_tracker_id}'); #{extra_code} pageTracker._initData(); pageTracker._trackPageview(#{request_tracked_path}); + } catch(err) {} //--><!]]> </script> HTML end