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.5'.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, properties = {}) ⇒ Typhoeus::Response
Send a single event immediately to the AmplitudeAPI.
-
.send_identify(user_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
105 106 107 |
# File 'lib/amplitude_api.rb', line 105 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
87 88 89 90 91 92 93 94 |
# File 'lib/amplitude_api.rb', line 87 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, properties = {}) ⇒ Typhoeus::Response
Send a single event immediately to the AmplitudeAPI
and can contain any other property to be stored on the Event
29 30 31 32 33 34 35 36 |
# File 'lib/amplitude_api.rb', line 29 def send_event(event_name, user, properties = {}) event = AmplitudeAPI::Event.new( user_id: user, event_type: event_name, event_properties: properties ) track(event) end |
.send_identify(user_id, user_properties = {}) ⇒ Object
==== Identification related methods
72 73 74 75 |
# File 'lib/amplitude_api.rb', line 72 def send_identify(user_id, user_properties = {}) identification = AmplitudeAPI::Identification.new(user_id: user_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
66 67 68 |
# File 'lib/amplitude_api.rb', line 66 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
48 49 50 51 52 53 54 55 |
# File 'lib/amplitude_api.rb', line 48 def track_body(*events) event_body = events.flatten.map(&:to_hash) { api_key: api_key, event: JSON.generate(event_body) } end |