Module: Workarea::CurrentTracking
Instance Method Summary
collapse
#cache_page, #http_caching?
Instance Method Details
#current_metrics ⇒ Object
18
19
20
|
# File 'app/controllers/workarea/current_tracking.rb', line 18
def current_metrics
current_visit.metrics
end
|
#current_referrer ⇒ Object
22
23
24
|
# File 'app/controllers/workarea/current_tracking.rb', line 22
def current_referrer
current_visit.referrer
end
|
#current_visit ⇒ Object
14
15
16
|
# File 'app/controllers/workarea/current_tracking.rb', line 14
def current_visit
request.env['workarea.visit']
end
|
#ensure_current_metrics ⇒ Object
This method is mostly for tests, but could surface in an implementation. Since Rails doesn’t set and load a session until needed, an initial request won’t have a session ID for ‘current_visit` to check when loading metrics. This ensures there will be one.
41
42
43
44
45
46
47
|
# File 'app/controllers/workarea/current_tracking.rb', line 41
def ensure_current_metrics
return if current_metrics_id.present? || http_caching?
session.delete(:foo)
self.current_metrics_id = session.id.cookie_value
end
|
#update_tracking!(email: current_user&.email) ⇒ Object
26
27
28
29
30
31
32
33
34
35
|
# File 'app/controllers/workarea/current_tracking.rb', line 26
def update_tracking!(email: current_user&.email)
if email.blank?
cookies.delete(:email)
elsif email != cookies.signed[:email]
Metrics::User.find_or_initialize_by(id: email).merge!(current_visit&.metrics)
cookies.permanent.signed[:email] = email
end
request.env['workarea.visit'] = Visit.new(request.env)
end
|