Class: Goldencobra::Tracking

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/goldencobra/tracking.rb

Class Method Summary collapse

Class Method Details

.analytics(request, location = nil) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'app/models/goldencobra/tracking.rb', line 40

def self.analytics(request, location=nil)
  if Goldencobra::Setting.for_key("goldencobra.analytics.active") == "true"
    self.create! do |t|
      t.utm_source = request.params["utm_source"]
      t.utm_medium = request.params["utm_medium"]
      t.utm_term = request.params["utm_term"]
      t.utm_content = request.params["utm_content"]
      t.utm_campaign = request.params["utm_campaign"]
      t.url_paremeters = request.params.except(:utf8) if request.params.present?
      t.language = request.env["HTTP_ACCEPT_LANGUAGE"]
      t.user_agent = request.env["HTTP_USER_AGENT"]
      if request.session_options[:id].present?
        t.session_id = request.session_options[:id]
      else
        t.session_id = "FB" + Digest::MD5.hexdigest("#{request.env['REMOTE_ADDR']}#{Time.now.to_f}")
      end
      t.referer = request.referer
      t.url = request.url
      t.ip = request.env['REMOTE_ADDR']
      t.location = location.try(:city)
    end
  end
end