Sha256: 131aa8febdba6823ae424cef4aa6fe8cbd8ee5d3fb4dacd683e0b8483b9d30df

Contents?: true

Size: 1.3 KB

Versions: 8

Compression:

Stored size: 1.3 KB

Contents

require "domainatrix"

module Concen
  class VisitsController < ApplicationController

    def visit_recorder_js
      if cookies[:visitor_id].blank?
        cookies[:visitor_id] = {:value => ActiveSupport::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 = "#{Rails.root}/public/concen/images/record-visit.gif"
      send_file image_path, :type => "image/gif", :disposition => "inline"
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
concen-0.1.7 app/controllers/concen/visits_controller.rb
concen-0.1.6 app/controllers/concen/visits_controller.rb
concen-0.1.5 app/controllers/concen/visits_controller.rb
concen-0.1.4 app/controllers/concen/visits_controller.rb
concen-0.1.3 app/controllers/concen/visits_controller.rb
concen-0.1.2 app/controllers/concen/visits_controller.rb
concen-0.1.1 app/controllers/concen/visits_controller.rb
concen-0.1 app/controllers/concen/visits_controller.rb