Module: YouthTree::Helpers::AnalyticsHelper
- Defined in:
- lib/youth_tree/helpers/analytics_helper.rb
Instance Method Summary collapse
- #analytics_code ⇒ Object
- #clicky_analytics ⇒ Object
- #clicky_snippet_js(site_id) ⇒ Object
- #google_analytics ⇒ Object
- #google_analytics_snippet_js(identifier) ⇒ Object
Instance Method Details
#analytics_code ⇒ Object
37 38 39 |
# File 'lib/youth_tree/helpers/analytics_helper.rb', line 37 def analytics_code [clicky_analytics, google_analytics].compact.sum(ActiveSupport::SafeBuffer.new) end |
#clicky_analytics ⇒ Object
20 21 22 23 24 25 26 27 28 29 |
# File 'lib/youth_tree/helpers/analytics_helper.rb', line 20 def clicky_analytics if Settings.clicky.site_id? content = ActiveSupport::SafeBuffer.new site_id = Settings.clicky.site_id.to_i; content << javascript_tag(clicky_snippet_js(site_id)) static_image_tag = tag(:img, :width => 1, :height => 1, :src => "#{request.protocol}in.getclicky.com/#{site_id}ns.gif") content << content_tag(:noscript, content_tag(:div, static_image_tag, :class => 'clicky-tracker')) content end end |
#clicky_snippet_js(site_id) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/youth_tree/helpers/analytics_helper.rb', line 5 def clicky_snippet_js(site_id) value = <<-END_OF_JS var clicky = {log:function(){return;},goal:function(){return;}}; var clicky_site_id = #{site_id}; (function() { var s = document.createElement('script'); s.type = 'text/javascript'; s.async = true; s.src = (document.location.protocol + '//static.getclicky.com/js'); (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(s); })(); END_OF_JS value.gsub(/^\s{10}/, '') end |
#google_analytics ⇒ Object
31 32 33 34 35 |
# File 'lib/youth_tree/helpers/analytics_helper.rb', line 31 def google_analytics if Settings.google_analytics.identifier? javascript_tag(google_analytics_snippet_js(Settings.google_analytics.identifier)) end end |
#google_analytics_snippet_js(identifier) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/youth_tree/helpers/analytics_helper.rb', line 41 def google_analytics_snippet_js(identifier) value = <<-END_OF_JS var _gaq = _gaq || []; _gaq.push(['_setAccount', #{identifier.to_json}]); _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); })(); END_OF_JS value.gsub(/^\s{10}/, '') end |