Module: Split::Analytics

Included in:
Helper
Defined in:
lib/split/analytics.rb,
lib/split/analytics/version.rb

Constant Summary collapse

VERSION =
"0.2.3"

Instance Method Summary collapse

Instance Method Details

#custom_variablesObject



25
26
27
28
29
30
31
32
# File 'lib/split/analytics.rb', line 25

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

#tracking_code(options = {}) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/split/analytics.rb', line 5

def tracking_code(options={})
  # needs more options: http://code.google.com/apis/analytics/docs/gaJS/gaJSApi.html
   = options.delete(:account)

  <<-EOF
    <script type="text/javascript">
      var _gaq = _gaq || [];
      _gaq.push(['_setAccount', '#{}']);
      #{custom_variables}
      _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>
  EOF
end