class RedisAnalytics::Tracker

Public Class Methods

new(app) click to toggle source
# File lib/redis_analytics/tracker.rb, line 5
def initialize(app)
  @app = app
end

Public Instance Methods

call(env) click to toggle source
# File lib/redis_analytics/tracker.rb, line 9
def call(env)
  dup.call!(env)
end
call!(env) click to toggle source
# File lib/redis_analytics/tracker.rb, line 13
def call!(env)
  @env = env
  @request  = Rack::Request.new(env)
  status, headers, body = @app.call(env)
  @response = Rack::Response.new(body, status, headers)
  record if should_record?
  @response.finish
end
record() click to toggle source
# File lib/redis_analytics/tracker.rb, line 36
def record
  v = Visit.new(@request, @response)
  @response = v.record
  @response.set_cookie(RedisAnalytics.current_visit_cookie_name, v.updated_current_visit_info)
  @response.set_cookie(RedisAnalytics.first_visit_cookie_name, v.updated_first_visit_info)
end
should_record?() click to toggle source
# File lib/redis_analytics/tracker.rb, line 22
def should_record?
  dashboard_path = Rails.application.routes.named_routes[:redis_analytics].path rescue nil
  return false if dashboard_path =~ @request.path
  return false unless @response.ok?
  return false unless @response.content_type =~ /^text\/html/
  RedisAnalytics.path_filters.each do |filter|
    return false if filter.matches?(@request.path)
  end
  RedisAnalytics.filters.each do |filter|
    return false if filter.matches?(@request, @response)
  end
  return true
end