Class: Rakwik::Tracker

Inherits:
Object
  • Object
show all
Includes:
Rack::Response::Helpers
Defined in:
lib/rakwik/tracker.rb

Constant Summary collapse

DEFAULT =
{
  :track_404 => true
}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app, options = {}) ⇒ Tracker

Returns a new instance of Tracker.



15
16
17
18
19
# File 'lib/rakwik/tracker.rb', line 15

def initialize(app, options = {})
  @app, @options = app, DEFAULT.merge(options)
  missing = [:piwik_url, :site_id, :token_auth].detect{ |e| @options[e].nil? }
  raise "Missing config value: :#{missing}" if missing
end

Instance Attribute Details

#statusObject

Returns the value of attribute status.



9
10
11
# File 'lib/rakwik/tracker.rb', line 9

def status
  @status
end

Class Method Details

.user_agentObject



29
30
31
# File 'lib/rakwik/tracker.rb', line 29

def self.user_agent
  "Rakwik Tracker #{Rakwik::VERSION}"
end

Instance Method Details

#call(env) ⇒ Object



21
22
23
24
25
26
27
# File 'lib/rakwik/tracker.rb', line 21

def call(env)
  start = Time.now
  @status, @headers, @body = @app.call(env)
  env['rakwik.duration'] = (Time.now - start)*1000
  track Rack::Request.new(env) if track?
  [@status, @headers, @body]
end