Class: AmplitudeAPI::Event
- Inherits:
-
Object
- Object
- AmplitudeAPI::Event
- Defined in:
- lib/amplitude_api/event.rb
Overview
AmplitudeAPI::Event
Instance Attribute Summary collapse
-
#device_id ⇒ String
The device_id to be sent to Amplitude.
-
#event_properties ⇒ String
The event_properties to be attached to the Amplitude Event.
-
#event_type ⇒ String
The event_type to be sent to Amplitude.
-
#insert_id ⇒ String
The unique identifier to be sent to Amplitude.
-
#ip ⇒ String
IP address of the user.
-
#price ⇒ String
(required for revenue data) price of the item purchased.
-
#product_id ⇒ String
An identifier for the product.
-
#quantity ⇒ String
(required for revenue data, defaults to 1 if not specified) quantity of the item purchased.
-
#revenue_type ⇒ String
Type of revenue.
-
#time ⇒ Time
Time that the event occurred (defaults to now).
-
#user_id ⇒ String
The user_id to be sent to Amplitude.
-
#user_properties ⇒ String
The user_properties to be passed for the user.
Instance Method Summary collapse
-
#==(other) ⇒ true, false
Compares +to_hash+ for equality.
-
#add_optional_properties(serialized_event) ⇒ Hash
A serialized Event with optional properties.
-
#initialize(attributes = {}) ⇒ Event
constructor
Create a new Event.
-
#to_hash ⇒ Hash
Used for serialization and comparison.
Constructor Details
#initialize(attributes = {}) ⇒ Event
Create a new Event
59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/amplitude_api/event.rb', line 59 def initialize(attributes = {}) self.user_id = getopt(attributes, :user_id, '') self.device_id = getopt(attributes, :device_id, nil) self.event_type = getopt(attributes, :event_type, '') self.event_properties = getopt(attributes, :event_properties, {}) self.user_properties = getopt(attributes, :user_properties, {}) self.time = getopt(attributes, :time) self.ip = getopt(attributes, :ip, '') self.insert_id = getopt(attributes, :insert_id) validate_revenue_arguments(attributes) end |
Instance Attribute Details
#device_id ⇒ String
Returns the device_id to be sent to Amplitude.
9 10 11 |
# File 'lib/amplitude_api/event.rb', line 9 def device_id @device_id end |
#event_properties ⇒ String
Returns the event_properties to be attached to the Amplitude Event.
15 16 17 |
# File 'lib/amplitude_api/event.rb', line 15 def event_properties @event_properties end |
#event_type ⇒ String
Returns the event_type to be sent to Amplitude.
12 13 14 |
# File 'lib/amplitude_api/event.rb', line 12 def event_type @event_type end |
#insert_id ⇒ String
Returns the unique identifier to be sent to Amplitude.
28 29 30 |
# File 'lib/amplitude_api/event.rb', line 28 def insert_id @insert_id end |
#ip ⇒ String
Returns IP address of the user.
24 25 26 |
# File 'lib/amplitude_api/event.rb', line 24 def ip @ip end |
#price ⇒ String
Returns (required for revenue data) price of the item purchased.
32 33 34 |
# File 'lib/amplitude_api/event.rb', line 32 def price @price end |
#product_id ⇒ String
Returns an identifier for the product. (Note: you must send a price and quantity with this field).
40 41 42 |
# File 'lib/amplitude_api/event.rb', line 40 def product_id @product_id end |
#quantity ⇒ String
Returns (required for revenue data, defaults to 1 if not specified) quantity of the item purchased.
36 37 38 |
# File 'lib/amplitude_api/event.rb', line 36 def quantity @quantity end |
#revenue_type ⇒ String
Returns type of revenue. (Note: you must send a price and quantity with this field).
44 45 46 |
# File 'lib/amplitude_api/event.rb', line 44 def revenue_type @revenue_type end |
#time ⇒ Time
Returns Time that the event occurred (defaults to now).
21 22 23 |
# File 'lib/amplitude_api/event.rb', line 21 def time @time end |
#user_id ⇒ String
Returns the user_id to be sent to Amplitude.
6 7 8 |
# File 'lib/amplitude_api/event.rb', line 6 def user_id @user_id end |
#user_properties ⇒ String
Returns the user_properties to be passed for the user.
18 19 20 |
# File 'lib/amplitude_api/event.rb', line 18 def user_properties @user_properties end |
Instance Method Details
#==(other) ⇒ true, false
Compares +to_hash+ for equality
105 106 107 108 109 110 111 |
# File 'lib/amplitude_api/event.rb', line 105 def ==(other) if other.respond_to?(:to_hash) to_hash == other.to_hash else false end end |
#add_optional_properties(serialized_event) ⇒ Hash
Returns A serialized Event with optional properties.
94 95 96 97 98 99 100 |
# File 'lib/amplitude_api/event.rb', line 94 def add_optional_properties(serialized_event) serialized_event[:device_id] = device_id if device_id serialized_event[:time] = formatted_time if time serialized_event[:ip] = ip if ip serialized_event[:insert_id] = insert_id if insert_id serialized_event end |
#to_hash ⇒ Hash
Used for serialization and comparison
83 84 85 86 87 88 89 90 91 |
# File 'lib/amplitude_api/event.rb', line 83 def to_hash serialized_event = {} serialized_event[:event_type] = event_type serialized_event[:user_id] = user_id serialized_event[:event_properties] = event_properties serialized_event[:user_properties] = user_properties serialized_event = add_optional_properties(serialized_event) serialized_event.merge(revenue_hash) end |