Module: Aptabase

Defined in:
lib/aptabase.rb,
lib/aptabase/event.rb,
lib/aptabase/client.rb,
lib/aptabase/errors.rb,
lib/aptabase/railtie.rb,
lib/aptabase/session.rb,
lib/aptabase/version.rb,
lib/aptabase/transport.rb,
lib/aptabase/system_properties.rb,
lib/generators/aptabase/install_generator.rb

Overview

Module-level singleton API, the most common way to use the SDK:

Aptabase.init("A-EU-1234567890", app_version: "1.2.3")
Aptabase.track("app_started")
Aptabase.track("purchase", { "product_id" => "abc123" })

For multiple apps or explicit lifecycle control, use Aptabase::Client directly.

Defined Under Namespace

Modules: Generators Classes: Client, ConfigurationError, Error, Event, NetworkError, Railtie, Session, SystemProperties, Transport, ValidationError

Constant Summary collapse

VERSION =
"0.1.0"

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.clientObject (readonly)

Returns the value of attribute client.



20
21
22
# File 'lib/aptabase.rb', line 20

def client
  @client
end

.default_loggerObject

Logger used when ‘init` is not given an explicit one. Set to Rails.logger automatically by the railtie in Rails apps.



24
25
26
# File 'lib/aptabase.rb', line 24

def default_logger
  @default_logger
end

Class Method Details

.flushObject

Synchronously send all queued events.



48
49
50
51
# File 'lib/aptabase.rb', line 48

def flush
  @client&.flush
  nil
end

.init(app_key, **options) ⇒ Object

Initialize the global client. Replaces (and stops) any previous one. Queued events are flushed automatically when the process exits.



28
29
30
31
32
33
34
# File 'lib/aptabase.rb', line 28

def init(app_key, **options)
  @client&.stop
  options[:logger] = default_logger if default_logger && !options.key?(:logger)
  @client = Client.new(app_key, **options)
  register_at_exit
  @client
end

.stopObject

Stop the global client, flushing any remaining events.



54
55
56
57
# File 'lib/aptabase.rb', line 54

def stop
  @client&.stop
  @client = nil
end

.track(event_name, props = nil) ⇒ Object

Track an event on the global client. Warns (once) and discards the event if ‘Aptabase.init` has not been called.



38
39
40
41
42
43
44
45
# File 'lib/aptabase.rb', line 38

def track(event_name, props = nil)
  client = @client
  if client.nil?
    warn_not_initialized
    return
  end
  client.track(event_name, props)
end