Module: Voidtools::Tracking
- Included in:
- Sinatra::ViewHelpers
- Defined in:
- lib/voidtools/sinatra/tracking.rb
Instance Method Summary collapse
-
#analytics(id, *domains) ⇒ Object
before the end of head tag.
-
#crazyegg ⇒ Object
before the end of body tag.
-
#gauges(id) ⇒ Object
before the end of body tag.
- #mixpanel ⇒ Object
- #track_run(&block) ⇒ Object
Instance Method Details
#analytics(id, *domains) ⇒ Object
before the end of head tag
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/voidtools/sinatra/tracking.rb', line 31 def analytics(id, *domains) # before the end of head tag # FIXME: try with multiple domains # TODO: test case track_run do out = " var _gaq = _gaq || [];\n _gaq.push(['_setAccount', '\#{id}']);FUN\n domains.each do |domain|\n out << \" _gaq.push(['_setDomainName', '.\#{domain}']);\"\n end\n <<-FUN\n _gaq.push(['_trackPageview']);\n\n (function() {\n var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;\n ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';\n var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);\n })();\n" end end |
#crazyegg ⇒ Object
before the end of body tag
59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/voidtools/sinatra/tracking.rb', line 59 def crazyegg # before the end of body tag track_run do " setTimeout(function(){var a=document.createElement(\"script\");\n var b=document.getElementsByTagName('script')[0];\n a.src=document.location.protocol+\"//dnn506yrbagrg.cloudfront.net/pages/scripts/0011/5433.js\";\n a.async=true;a.type=\"text/javascript\";b.parentNode.insertBefore(a,b)}, 1);\n" end end |
#gauges(id) ⇒ Object
before the end of body tag
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/voidtools/sinatra/tracking.rb', line 72 def gauges(id) # before the end of body tag track_run do " (function() {\n var t = document.createElement('script');\n t.type = 'text/javascript';\n t.async = true;\n t.id = 'gauges-tracker';\n t.setAttribute('data-site-id', '\#{id}');\n t.src = '//secure.gaug.es/track.js';\n var s = document.getElementsByTagName('script')[0];\n s.parentNode.insertBefore(t, s);\n })();\n" end end |
#mixpanel ⇒ Object
53 54 55 56 57 |
# File 'lib/voidtools/sinatra/tracking.rb', line 53 def mixpanel track_run do # ... end end |
#track_run(&block) ⇒ Object
23 24 25 26 27 28 29 |
# File 'lib/voidtools/sinatra/tracking.rb', line 23 def track_run(&block) if defined?(Rails) yield if Rails.env != "development" else yield if ENV["RACK_ENV"] != "development" end end |