Sha256: 46c2b6defa9ef0a3b362daba457a710bf6c5102145c27704c2a75c88f52f30a8

Contents?: true

Size: 1.31 KB

Versions: 2

Compression:

Stored size: 1.31 KB

Contents

require "domainatrix"

module Concen
  class VisitsController < Concen::ApplicationController
    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

    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
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
concen-0.2.9 app/controllers/concen/visits_controller.rb
concen-0.2.8 app/controllers/concen/visits_controller.rb