Class: Ahoy::Tracker
- Inherits:
-
Object
- Object
- Ahoy::Tracker
- Defined in:
- lib/ahoy/tracker.rb
Instance Attribute Summary collapse
-
#controller ⇒ Object
readonly
Returns the value of attribute controller.
-
#request ⇒ Object
readonly
Returns the value of attribute request.
Instance Method Summary collapse
- #authenticate(user) ⇒ Object
-
#initialize(options = {}) ⇒ Tracker
constructor
A new instance of Tracker.
- #new_visit? ⇒ Boolean
- #new_visitor? ⇒ Boolean
- #set_visit_cookie ⇒ Object
- #set_visitor_cookie ⇒ Object
- #track(name, properties = {}, options = {}) ⇒ Object
- #track_visit(options = {}) ⇒ Object
- #user ⇒ Object
- #visit ⇒ Object
- #visit_id ⇒ Object
-
#visit_properties ⇒ Object
TODO better name.
- #visit_token ⇒ Object
- #visitor_id ⇒ Object
- #visitor_token ⇒ Object
Constructor Details
Instance Attribute Details
#controller ⇒ Object (readonly)
Returns the value of attribute controller.
3 4 5 |
# File 'lib/ahoy/tracker.rb', line 3 def controller @controller end |
#request ⇒ Object (readonly)
Returns the value of attribute request.
3 4 5 |
# File 'lib/ahoy/tracker.rb', line 3 def request @request end |
Instance Method Details
#authenticate(user) ⇒ Object
51 52 53 54 55 56 57 58 59 60 |
# File 'lib/ahoy/tracker.rb', line 51 def authenticate(user) if exclude? debug "Authentication excluded" else @store.authenticate(user) end true rescue => e report_exception(e) end |
#new_visit? ⇒ Boolean
74 75 76 |
# File 'lib/ahoy/tracker.rb', line 74 def new_visit? !existing_visit_token end |
#new_visitor? ⇒ Boolean
78 79 80 |
# File 'lib/ahoy/tracker.rb', line 78 def new_visitor? !existing_visitor_token end |
#set_visit_cookie ⇒ Object
82 83 84 |
# File 'lib/ahoy/tracker.rb', line 82 def ("ahoy_visit", visit_id, Ahoy.visit_duration) end |
#set_visitor_cookie ⇒ Object
86 87 88 89 90 |
# File 'lib/ahoy/tracker.rb', line 86 def if new_visitor? ("ahoy_visitor", visitor_id, Ahoy.visitor_duration) end end |
#track(name, properties = {}, options = {}) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/ahoy/tracker.rb', line 12 def track(name, properties = {}, = {}) if exclude? debug "Event excluded" elsif missing_params? debug "Missing required parameters" else = .dup [:time] = trusted_time([:time]) [:id] = ensure_uuid([:id] || generate_id) @store.track_event(name, properties, ) end true rescue => e report_exception(e) end |
#track_visit(options = {}) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/ahoy/tracker.rb', line 30 def track_visit( = {}) if exclude? debug "Visit excluded" elsif missing_params? debug "Missing required parameters" else if [:defer] ("ahoy_track", true, nil, false) else = .dup [:started_at] ||= Time.zone.now @store.track_visit() end end true rescue => e report_exception(e) end |
#user ⇒ Object
92 93 94 |
# File 'lib/ahoy/tracker.rb', line 92 def user @user ||= @store.user end |
#visit ⇒ Object
62 63 64 |
# File 'lib/ahoy/tracker.rb', line 62 def visit @visit ||= @store.visit end |
#visit_id ⇒ Object
66 67 68 |
# File 'lib/ahoy/tracker.rb', line 66 def visit_id @visit_id ||= ensure_uuid(visit_token_helper) end |
#visit_properties ⇒ Object
TODO better name
97 98 99 |
# File 'lib/ahoy/tracker.rb', line 97 def visit_properties @visit_properties ||= Ahoy::VisitProperties.new(request, api: api?) end |
#visit_token ⇒ Object
101 102 103 |
# File 'lib/ahoy/tracker.rb', line 101 def visit_token @visit_token ||= ensure_token(visit_token_helper) end |
#visitor_id ⇒ Object
70 71 72 |
# File 'lib/ahoy/tracker.rb', line 70 def visitor_id @visitor_id ||= ensure_uuid(visitor_token_helper) end |
#visitor_token ⇒ Object
105 106 107 |
# File 'lib/ahoy/tracker.rb', line 105 def visitor_token @visitor_token ||= ensure_token(visitor_token_helper) end |