Sha256: f771619e0aaff06bca4b5b5101bda71e23fc52fb434509eefd8a12e6b67edb33

Contents?: true

Size: 1013 Bytes

Versions: 16

Compression:

Stored size: 1013 Bytes

Contents

require 'orange-core/middleware/base'

module Orange::Middleware
  class Analytics < Base
    
    # Passes packet then parses the return
    def packet_call(packet)
      pass packet
      ga_key = orange.options['google_analytics_key'] || false
      if packet['route.context'] == :live && ga_key
          ga = "<script type=\"text/javascript\">

            var _gaq = _gaq || [];
            _gaq.push(['_setAccount', '"+ga_key+"']);
            _gaq.push(['_trackPageview']);

            (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>"
          packet[:content] = packet[:content].sub(/.*<\/head>$/, ga + '</head>')
      end
      packet.finish
    end
    
  end
end

Version data entries

16 entries across 16 versions & 2 rubygems

Version Path
orange-more-0.7.3 lib/orange-more/analytics/middleware/analytics.rb
orange-more-0.7.2 lib/orange-more/analytics/middleware/analytics.rb
orange-more-0.7.1 lib/orange-more/analytics/middleware/analytics.rb
orange-more-0.6.5 lib/orange-more/analytics/middleware/analytics.rb
orange-more-0.6.4 lib/orange-more/analytics/middleware/analytics.rb
orange-more-0.6.3 lib/orange-more/analytics/middleware/analytics.rb
orange-more-0.6.2 lib/orange-more/analytics/middleware/analytics.rb
orange-more-0.6.0 lib/orange-more/analytics/middleware/analytics.rb
orange-more-0.5.8 lib/orange-more/analytics/middleware/analytics.rb
orange-more-0.5.7 lib/orange-more/analytics/middleware/analytics.rb
orange-0.5.5 lib/orange-more/analytics/middleware/analytics.rb
orange-0.5.4 lib/orange-more/analytics/middleware/analytics.rb
orange-0.5.3 lib/orange-more/analytics/middleware/analytics.rb
orange-0.5.2 lib/orange-more/analytics/middleware/analytics.rb
orange-0.5.1 lib/orange-more/analytics/middleware/analytics.rb
orange-0.4.0 lib/orange-more/analytics/middleware/analytics.rb