Class: AmplitudeAPI
- Inherits:
-
Object
- Object
- AmplitudeAPI
- Defined in:
- lib/amplitude_api.rb,
lib/amplitude_api/event.rb,
lib/amplitude_api/version.rb,
lib/amplitude_api/identification.rb
Overview
AmplitudeAPI
Defined Under Namespace
Classes: Event, Identification
Constant Summary collapse
- TRACK_URI_STRING =
'https://api.amplitude.com/httpapi'.freeze
- IDENTIFY_URI_STRING =
'https://api.amplitude.com/identify'.freeze
- USER_WITH_NO_ACCOUNT =
"user who doesn't have an account".freeze
- VERSION =
'0.0.9'.freeze
Class Attribute Summary collapse
-
.api_key ⇒ String
An Amplitude API Key.
Class Method Summary collapse
-
.identify(*identifications) ⇒ Typhoeus::Response
Send one or more Identifications to the Amplitude Identify API.
-
.identify_body(*identifications) ⇒ Hash
Converts a series of AmplitudeAPI::Identification objects into a body suitable for the Amplitude Identify API.
-
.send_event(event_name, user, device, options = {}) ⇒ Typhoeus::Response
Send a single event immediately to the AmplitudeAPI.
-
.send_identify(user_id, device_id, user_properties = {}) ⇒ Object
==== Identification related methods.
-
.track(*events) ⇒ Typhoeus::Response
Send one or more Events to the Amplitude API.
-
.track_body(*events) ⇒ Hash
Converts a series of AmplitudeAPI::Event objects into a body suitable for the Amplitude API.
Class Attribute Details
.api_key ⇒ String
Returns an Amplitude API Key.
17 18 19 |
# File 'lib/amplitude_api.rb', line 17 def api_key @api_key end |
Class Method Details
.identify(identification) ⇒ Typhoeus::Response .identify([identifications]) ⇒ Typhoeus::Response
Send one or more Identifications to the Amplitude Identify API
114 115 116 |
# File 'lib/amplitude_api.rb', line 114 def identify(*identifications) Typhoeus.post(IDENTIFY_URI_STRING, body: identify_body(identifications)) end |
.identify_body(identification) ⇒ Hash .identify_body([identifications]) ⇒ Hash
Converts a series of AmplitudeAPI::Identification objects into a body suitable for the Amplitude Identify API
96 97 98 99 100 101 102 103 |
# File 'lib/amplitude_api.rb', line 96 def identify_body(*identifications) identification_body = identifications.flatten.map(&:to_hash) { api_key: api_key, identification: JSON.generate(identification_body) } end |
.send_event(event_name, user, device, options = {}) ⇒ Typhoeus::Response
Send a single event immediately to the AmplitudeAPI
and can contain any other property to be stored on the Event and contains user properties to be associated with the user
32 33 34 35 36 37 38 39 40 41 |
# File 'lib/amplitude_api.rb', line 32 def send_event(event_name, user, device, = {}) event = AmplitudeAPI::Event.new( user_id: user, device_id: device, event_type: event_name, event_properties: .fetch(:event_properties, {}), user_properties: .fetch(:user_properties, {}) ) track(event) end |
.send_identify(user_id, device_id, user_properties = {}) ⇒ Object
==== Identification related methods
77 78 79 80 81 82 83 84 |
# File 'lib/amplitude_api.rb', line 77 def send_identify(user_id, device_id, user_properties = {}) identification = AmplitudeAPI::Identification.new( user_id: user_id, device_id: device_id, user_properties: user_properties ) identify(identification) end |
.track(event) ⇒ Typhoeus::Response .track([events]) ⇒ Typhoeus::Response
Send one or more Events to the Amplitude API
71 72 73 |
# File 'lib/amplitude_api.rb', line 71 def track(*events) Typhoeus.post(TRACK_URI_STRING, body: track_body(events)) end |
.track_body(event) ⇒ Hash .track_body([events]) ⇒ Hash
Converts a series of AmplitudeAPI::Event objects into a body suitable for the Amplitude API
53 54 55 56 57 58 59 60 |
# File 'lib/amplitude_api.rb', line 53 def track_body(*events) event_body = events.flatten.map(&:to_hash) { api_key: api_key, event: JSON.generate(event_body) } end |