Sha256: d6d5c1b6c3db86f25b2552d48c02a952c0b5a4ba134c351a6686b67006273396
Contents?: true
Size: 1.4 KB
Versions: 2
Compression:
Stored size: 1.4 KB
Contents
require "split/helper" module Split module Analytics def tracking_code(options={}) # needs more options: http://code.google.com/apis/analytics/docs/gaJS/gaJSApi.html account = options.delete(:account) code = <<-EOF <script type="text/javascript"> var _gaq = _gaq || []; _gaq.push(['_setAccount', '#{account}']); #{custom_variables} _gaq.push(['_trackPageview']); _gaq.push(['_trackPageLoadTime']); (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> EOF code = raw(code)if defined?(raw) code end def custom_variables return nil if session[:split].nil? arr = [] session[:split].each_with_index do |h,i| arr << "_gaq.push(['_setCustomVar', #{i+1}, '#{h[0]}', '#{h[1]}', 1]);" end arr.reverse[0..4].reverse.join("\n") end end end module Split::Helper include Split::Analytics end if defined?(Rails) class ActionController::Base ActionController::Base.send :include, Split::Analytics ActionController::Base.helper Split::Analytics end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
split-analytics-0.3.0 | lib/split/analytics.rb |
split-analytics-0.2.5 | lib/split/analytics.rb |