Class: Rox::Core::Analytics::Client
- Inherits:
-
Object
- Object
- Rox::Core::Analytics::Client
- Defined in:
- lib/rox/core/analytics/client.rb
Constant Summary
Constants included from Utils
Utils::UTC_OFFSET_WITHOUT_COLON, Utils::UTC_OFFSET_WITH_COLON
Instance Method Summary collapse
-
#alias(attrs) ⇒ Object
Aliases a user from one id to another.
-
#flush ⇒ Object
Synchronously waits until the worker has flushed the queue.
-
#group(attrs) ⇒ Object
Associates a user identity with a group.
-
#identify(attrs) ⇒ Object
Identifies a user.
-
#initialize(device_properties) ⇒ Client
constructor
A new instance of Client.
-
#page(attrs) ⇒ Object
Records a page view.
-
#queued_messages ⇒ Fixnum
Number of messages in the queue.
-
#screen(attrs) ⇒ Object
Records a screen view (for a mobile app).
- #test_queue ⇒ Object
-
#track(attrs) ⇒ Object
Tracks an event.
Methods included from Logging
Methods included from Utils
#date_in_iso8601, #datetime_in_iso8601, #formatted_offset, #isoify_dates, #isoify_dates!, #seconds_to_utc_offset, #stringify_keys, #symbolize_keys, #symbolize_keys!, #time_in_iso8601, #uid
Constructor Details
#initialize(device_properties) ⇒ Client
Returns a new instance of Client.
18 19 20 21 22 23 24 25 26 |
# File 'lib/rox/core/analytics/client.rb', line 18 def initialize(device_properties) @queue = Queue.new @max_queue_size = Defaults::Queue::MAX_SIZE @worker_mutex = Mutex.new @worker = Worker.new(@queue, device_properties) @worker_thread = nil at_exit { @worker_thread && @worker_thread[:should_exit] = true } end |
Instance Method Details
#alias(attrs) ⇒ Object
Aliases a user from one id to another
88 89 90 91 |
# File 'lib/rox/core/analytics/client.rb', line 88 def alias(attrs) symbolize_keys! attrs enqueue(FieldParser.parse_for_alias(attrs)) end |
#flush ⇒ Object
Synchronously waits until the worker has flushed the queue.
Use only for scripts which are not long-running, and will specifically exit
32 33 34 35 36 37 |
# File 'lib/rox/core/analytics/client.rb', line 32 def flush while !@queue.empty? || @worker.is_requesting? ensure_worker_running sleep(0.1) end end |
#group(attrs) ⇒ Object
Associates a user identity with a group.
102 103 104 105 |
# File 'lib/rox/core/analytics/client.rb', line 102 def group(attrs) symbolize_keys! attrs enqueue(FieldParser.parse_for_group(attrs)) end |
#identify(attrs) ⇒ Object
Identifies a user
75 76 77 78 |
# File 'lib/rox/core/analytics/client.rb', line 75 def identify(attrs) symbolize_keys! attrs enqueue(FieldParser.parse_for_identify(attrs)) end |
#page(attrs) ⇒ Object
Records a page view
116 117 118 119 |
# File 'lib/rox/core/analytics/client.rb', line 116 def page(attrs) symbolize_keys! attrs enqueue(FieldParser.parse_for_page(attrs)) end |
#queued_messages ⇒ Fixnum
Returns number of messages in the queue.
135 136 137 |
# File 'lib/rox/core/analytics/client.rb', line 135 def @queue.length end |
#screen(attrs) ⇒ Object
Records a screen view (for a mobile app)
129 130 131 132 |
# File 'lib/rox/core/analytics/client.rb', line 129 def screen(attrs) symbolize_keys! attrs enqueue(FieldParser.parse_for_screen(attrs)) end |
#test_queue ⇒ Object
139 140 141 142 143 144 145 |
# File 'lib/rox/core/analytics/client.rb', line 139 def test_queue unless @test raise 'Test queue only available when setting :test to true.' end @test_queue ||= TestQueue.new end |
#track(attrs) ⇒ Object
Tracks an event
62 63 64 65 |
# File 'lib/rox/core/analytics/client.rb', line 62 def track(attrs) symbolize_keys! attrs enqueue(attrs) end |