Class: Land::Trackers::UserTracker
- Inherits:
-
Land::Tracker
- Object
- Land::Tracker
- Land::Trackers::UserTracker
- Defined in:
- lib/land/trackers/user_tracker.rb
Constant Summary
Constants inherited from Land::Tracker
Land::Tracker::ATTRIBUTION_KEYS, Land::Tracker::KEYS, Land::Tracker::TRACKED_PARAMS, Land::Tracker::TRACKING_KEYS, Land::Tracker::TRACKING_PARAMS, Land::Tracker::TRACKING_PARAMS_TRANSFORM, Land::Tracker::UUID_REGEX, Land::Tracker::UUID_REGEX_V4
Instance Attribute Summary collapse
-
#pageview ⇒ Object
readonly
Returns the value of attribute pageview.
Attributes inherited from Land::Tracker
#controller, #events, #status, #visit
Instance Method Summary collapse
- #identify(identifier) ⇒ Object
- #load ⇒ Object
- #record_pageview ⇒ Object
- #save ⇒ Object
- #track ⇒ Object
Methods inherited from Land::Tracker
#create_event, for, #initialize
Constructor Details
This class inherits a constructor from Land::Tracker
Instance Attribute Details
#pageview ⇒ Object (readonly)
Returns the value of attribute pageview.
6 7 8 |
# File 'lib/land/trackers/user_tracker.rb', line 6 def pageview @pageview end |
Instance Method Details
#identify(identifier) ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/land/trackers/user_tracker.rb', line 63 def identify(identifier) visit = @visit || Visit.find(@visit_id) owner = Owner[identifier] visit.owner = owner visit.save! begin Ownership.where(cookie_id: @cookie_id, owner_id: owner).first_or_create rescue ActiveRecord::RecordNotUnique retry end end |
#load ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/land/trackers/user_tracker.rb', line 14 def load hash = session[:land] || {} @cookie_id = [:land] # KEYS is used to compact the key name in the session to save space @visit_id = hash[KEYS[:visit_id]] @last_visit_time = hash[KEYS[:visit_time]].try :to_time @user_agent_hash = hash[KEYS[:user_agent_hash]] @attribution_hash = hash[KEYS[:attribution_hash]] @referer_hash = hash[KEYS[:referer_hash]] end |
#record_pageview ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/land/trackers/user_tracker.rb', line 27 def record_pageview current_time = Time.now @pageview = Pageview.create do |p| p.path = request.path.to_s p.http_method = request.method p.mime_type = request.media_type || request.format.to_s p.query_string = untracked_params.to_query p.request_id = request.uuid p.click_id = tracking_params['click_id'] p.http_status = status || response.status p.visit_id = @visit_id p.created_at = current_time p.response_time = (current_time - @start_time) * 1000 end end |
#save ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/land/trackers/user_tracker.rb', line 49 def save record_pageview events.each { |e| e.pageview = pageview; e.save! } session[:land] = { KEYS[:visit_id] => @visit_id, KEYS[:visit_time] => Time.current, KEYS[:user_agent_hash] => user_agent_hash, KEYS[:attribution_hash] => attribution_changed? ? attribution_hash : @attribution_hash, KEYS[:referer_hash] => referer_changed? ? referer_hash : @referer_hash } end |
#track ⇒ Object
8 9 10 11 12 |
# File 'lib/land/trackers/user_tracker.rb', line 8 def track load record_visit end |