Module: BigBro::Helpers
- Defined in:
- lib/bigbro.rb
Instance Method Summary collapse
-
#analytics(options = {}) ⇒ Object
Embeds the optimized Analytics code and the noscript tag with the direct path to the __utm.gif image into the current page.
Instance Method Details
#analytics(options = {}) ⇒ Object
Embeds the optimized Analytics code and the noscript tag with the direct path to the __utm.gif image into the current page.
If the ‘:track` option is set to false, the current page load is not automatically tracked: you should track it later via the JS API.
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/bigbro.rb', line 14 def analytics( = {}) return if BigBro.disabled? track = .has_key?(:track) ? [:track] : true ga_host = BigBro.host_for(request) ga_cmds = [['_setAccount', BigBro.account]] ga_cmds.push ['_setDomainName', BigBro.domain] if BigBro.domain ga_cmds.concat([:commands]) if [:commands] ga_cmds.push ['_trackPageview'] if track code = '' code.concat javascript_tag(%( var _gaq = #{ga_cmds.to_json}; try { (function(d,t,a) { var g=d.createElement(t),s=d.getElementsByTagName(t)[0]; g[a]=a;g.src='#{ga_host}/ga.js';s.parentNode.insertBefore(g,s); })(document, 'script', 'async'); } catch (err) {} )) code.concat(content_tag(:noscript, image_tag(BigBro.noscript_image_path_for(request, ga_host), :border => '0', :alt => '').html_safe )) return code.html_safe end |