module Amplitude
Constants
- API_URI
Public Class Methods
api_key(options = {})
click to toggle source
# File lib/amplitude.rb, line 31 def api_key(options = {}) options.fetch(:api_key, Amplitude.config.api_key) end
async_enabled?()
click to toggle source
# File lib/amplitude.rb, line 55 def async_enabled? defined?(ActiveJob) end
config()
click to toggle source
# File lib/amplitude.rb, line 23 def config Amplitude::Config.instance end
configure() { |config| ... }
click to toggle source
# File lib/amplitude.rb, line 27 def configure yield config end
create_event(data)
click to toggle source
# File lib/amplitude.rb, line 35 def create_event(data) data.is_a?(Event) ? data : Event.new(data) end
queue(data, options = {})
click to toggle source
# File lib/amplitude.rb, line 50 def queue(data, options = {}) raise AsyncError unless async_enabled? Amplitude::Jobs::Default.perform_later(create_event(data).to_json, options) end
track(data, options = {})
click to toggle source
# File lib/amplitude.rb, line 39 def track(data, options = {}) raise APIKeyError unless (key = api_key(options)) HTTParty.post(API_URI, body: { api_key: key, event: create_event(data).to_json }) end
track!(data, options = {})
click to toggle source
# File lib/amplitude.rb, line 44 def track!(data, options = {}) response = track(data, options) raise APIError, response unless response.success? response end