Class: Concen::VisitsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/concen/visits_controller.rb

Instance Method Summary collapse

Instance Method Details

#recordObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'app/controllers/concen/visits_controller.rb', line 12

def record
  current_time = Time.now.utc
  current_hour = Time.utc(current_time.year, current_time.month, current_time.day, current_time.hour)
  Visit::Page.collection.update(
    {:url => params[:u], :hour => current_hour},
    {"$inc" => {:count => 1}, "$set" => {:title => params[:t]}},
    :upsert => true, :safe => false
  )
  begin
    referral_url = params[:r]
    referral = Domainatrix.parse(referral_url)
    referral_domain = referral.domain + "." + referral.public_suffix
  rescue
    referral_url = nil
    referral_domain = nil
  end
  Visit::Referral.collection.update(
    {:url => referral_url, :hour => current_hour},
    {"$inc" => {:count => 1}, "$set" => {:domain => referral_domain}},
    :upsert => true, :safe => false
  )
  image_path = "#{Concen::Engine.root}/app/assets/images/concen/record-visit.gif"
  send_file image_path, :type => "image/gif", :disposition => "inline"
end

#visit_recorder_jsObject



5
6
7
8
9
10
# File 'app/controllers/concen/visits_controller.rb', line 5

def visit_recorder_js
  if cookies[:visitor_id].blank?
    cookies[:visitor_id] = {:value => SecureRandom.uuid, :expires => 20.years.from_now}
  end
  render :layout => false, :mime_type => "text/javascript"
end