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.7'.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, options = {}) ⇒ 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
108 109 110 |
# File 'lib/amplitude_api.rb', line 108 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
90 91 92 93 94 95 96 97 |
# File 'lib/amplitude_api.rb', line 90 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, 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
31 32 33 34 35 36 37 38 39 |
# File 'lib/amplitude_api.rb', line 31 def send_event(event_name, user, = {}) event = AmplitudeAPI::Event.new( user_id: user, event_type: event_name, event_properties: .fetch(:event_properties, {}), user_properties: .fetch(:user_properties, {}) ) track(event) end |
.send_identify(user_id, user_properties = {}) ⇒ Object
==== Identification related methods
75 76 77 78 |
# File 'lib/amplitude_api.rb', line 75 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
69 70 71 |
# File 'lib/amplitude_api.rb', line 69 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
51 52 53 54 55 56 57 58 |
# File 'lib/amplitude_api.rb', line 51 def track_body(*events) event_body = events.flatten.map(&:to_hash) { api_key: api_key, event: JSON.generate(event_body) } end |