Module: Useful::ErbHelpers::Analytics

Includes:
Common
Defined in:
lib/useful/erb_helpers/analytics.rb

Constant Summary

Constants included from Common

Common::OPTIONS

Instance Method Summary collapse

Methods included from Common

#erb_helper_clear_output_buffer

Instance Method Details

#google_analytics(key) ⇒ Object

Use the keyed google analytics account



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/useful/erb_helpers/analytics.rb', line 11

def google_analytics(key)
  %{
    <script type="text/javascript">
      var _gaq = _gaq || [];
      _gaq.push(['_setAccount', '#{key}']);
      _gaq.push(['_trackPageview']);

      (function() {
      var ga = document.createElement('script');
      ga.src = ('https:' == document.location.protocol ?
          'https://ssl' : 'http://www') +
          '.google-analytics.com/ga.js';
      ga.setAttribute('async', 'true');
      document.documentElement.firstChild.appendChild(ga);
      })();
    </script>
  } if production?
end