Module: Voidtools::Tracking

Included in:
Sinatra::ViewHelpers
Defined in:
lib/voidtools/sinatra/tracking.rb

Instance Method Summary collapse

Instance Method Details

#analytics(id, *domains) ⇒ Object

before the end of head tag



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/voidtools/sinatra/tracking.rb', line 30

def analytics(id, *domains) # before the end of head tag
  # FIXME: try with multiple domains
  # TODO: test case
  track_run do
    out = <<-FUN
    var _gaq = _gaq || [];
    _gaq.push(['_setAccount', '#{id}']);FUN
    domains.each do |domain|
      out << "      _gaq.push(['_setDomainName', '.#{domain}']);"
    end
    <<-FUN
    _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);
    })();
FUN
  end
end

#crazyeggObject

before the end of body tag



58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/voidtools/sinatra/tracking.rb', line 58

def crazyegg # before the end of body tag

  track_run do   
    <<-FUN 
    setTimeout(function(){var a=document.createElement("script");
    var b=document.getElementsByTagName('script')[0];
    a.src=document.location.protocol+"//dnn506yrbagrg.cloudfront.net/pages/scripts/0011/5433.js";
    a.async=true;a.type="text/javascript";b.parentNode.insertBefore(a,b)}, 1);
FUN
  end

end

#gauges(id) ⇒ Object

before the end of body tag



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/voidtools/sinatra/tracking.rb', line 71

def gauges(id) # before the end of body tag
  track_run do
    <<-FUN 
    (function() {
        var t   = document.createElement('script');
        t.type  = 'text/javascript';
        t.async = true;
        t.id    = 'gauges-tracker';
        t.setAttribute('data-site-id', '#{id}');
        t.src = '//secure.gaug.es/track.js';
        var s = document.getElementsByTagName('script')[0];
        s.parentNode.insertBefore(t, s);
      })();
FUN
  end
end

#mixpanelObject



52
53
54
55
56
# File 'lib/voidtools/sinatra/tracking.rb', line 52

def mixpanel
  track_run do
    # ...
  end
end

#track_run(&block) ⇒ Object



22
23
24
25
26
27
28
# File 'lib/voidtools/sinatra/tracking.rb', line 22

def track_run(&block)
  if defined?(Rails)
    yield if Rails.env != "development"
  else
    yield if ENV["RACK_ENV"] != "development"
  end
end