Class: Path::Reporting::Analytics::Amplitude
- Inherits:
-
Object
- Object
- Path::Reporting::Analytics::Amplitude
- Defined in:
- lib/path/reporting/analytics/amplitude.rb
Overview
Amplitude analytics is our primary analytics channel for production
Defined Under Namespace
Classes: Error
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
Instance Method Summary collapse
-
#initialize(config) ⇒ Amplitude
constructor
Setup and configure AmplitudeAPI with the given configuration.
-
#record(name:, user:, user_type:, trigger:, metadata: {}) ⇒ Object
Record the metadata to Amplitude.
Constructor Details
#initialize(config) ⇒ Amplitude
Setup and configure AmplitudeAPI with the given configuration
66 67 68 69 70 71 72 |
# File 'lib/path/reporting/analytics/amplitude.rb', line 66 def initialize(config) @config = config config.analytics.amplitude_config.each do |key, value| AmplitudeAPI.config.instance_variable_set("@#{key}", value) end end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
60 61 62 |
# File 'lib/path/reporting/analytics/amplitude.rb', line 60 def config @config end |
Instance Method Details
#record(name:, user:, user_type:, trigger:, metadata: {}) ⇒ Object
Record the metadata to Amplitude
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/path/reporting/analytics/amplitude.rb', line 81 def record(name:, user:, user_type:, trigger:, metadata: {}) user = user.dup = .dup user[:user_type] = user_type [:trigger] = trigger [:system_name] = config.system_name event_props = { user_properties: scrub_pii(user), event_type: name, event_properties: scrub_pii() } event_props[:user_id] = (user[:id] || user["id"]).to_s unless (user[:id] || user["id"]).nil? event_props[:device_id] = (user[:device_id] || user["device_id"]).to_s unless (user[:device_id] || user["device_id"]).nil? API_METADATA_TO_ELEVATE.each do |key| event_props[key] = [key] if .key? key end response = AmplitudeAPI.track AmplitudeAPI::Event.new event_props raise Error, response.body unless response.success? response end |