Class: Rudder::Analytics::Client
- Inherits:
-
Object
- Object
- Rudder::Analytics::Client
- Defined in:
- lib/rudder/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(opts = {}) ⇒ 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).
-
#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(opts = {}) ⇒ Client
Returns a new instance of Client.
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/rudder/analytics/client.rb', line 24 def initialize(opts = {}) symbolize_keys!(opts) @queue = Queue.new @write_key = opts[:write_key] @data_plane_url = opts[:data_plane_url] @max_queue_size = opts[:max_queue_size] || Defaults::Queue::MAX_SIZE @worker_mutex = Mutex.new @worker = Worker.new(@queue, @data_plane_url, @write_key, opts) @worker_thread = nil uri = URI(opts[:data_plane_url]) @host = uri.host @port = uri.port check_write_key! at_exit { @worker_thread && @worker_thread[:should_exit] = true } end |
Instance Method Details
#alias(attrs) ⇒ Object
Aliases a user from one id to another
106 107 108 109 |
# File 'lib/rudder/analytics/client.rb', line 106 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
49 50 51 52 53 54 |
# File 'lib/rudder/analytics/client.rb', line 49 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.
120 121 122 123 |
# File 'lib/rudder/analytics/client.rb', line 120 def group(attrs) symbolize_keys! attrs enqueue(FieldParser.parse_for_group(attrs)) end |
#identify(attrs) ⇒ Object
Identifies a user
92 93 94 95 96 |
# File 'lib/rudder/analytics/client.rb', line 92 def identify(attrs) printf("\nInside Identifyu \n") symbolize_keys! attrs enqueue(FieldParser.parse_for_identify(attrs)) end |
#page(attrs) ⇒ Object
Records a page view
134 135 136 137 |
# File 'lib/rudder/analytics/client.rb', line 134 def page(attrs) symbolize_keys! attrs enqueue(FieldParser.parse_for_page(attrs)) end |
#queued_messages ⇒ Fixnum
Returns number of messages in the queue.
153 154 155 |
# File 'lib/rudder/analytics/client.rb', line 153 def @queue.length end |
#screen(attrs) ⇒ Object
Records a screen view (for a mobile app)
147 148 149 150 |
# File 'lib/rudder/analytics/client.rb', line 147 def screen(attrs) symbolize_keys! attrs enqueue(FieldParser.parse_for_screen(attrs)) end |
#track(attrs) ⇒ Object
Tracks an event
79 80 81 82 |
# File 'lib/rudder/analytics/client.rb', line 79 def track(attrs) symbolize_keys! attrs enqueue(FieldParser.parse_for_track(attrs)) end |