Class: Path::Reporting::Analytics
- Inherits:
-
Object
- Object
- Path::Reporting::Analytics
- Defined in:
- lib/path/reporting/analytics.rb,
lib/path/reporting/analytics/console.rb,
lib/path/reporting/analytics/amplitude.rb,
lib/path/reporting/analytics/configuration.rb
Overview
Our primary class for reporting analytics data. Once configured, this class can report analytics to any and all enabled and configured reporters.
This class is not a singleton, but is exposed via the analytics property once the Reporting module is initialized
Defined Under Namespace
Classes: Amplitude, Configuration, Console
Instance Method Summary collapse
-
#initialize(config) ⇒ Analytics
constructor
Create a new analytics reporter with the given configuration.
-
#record(name:, user:, product_code: "", product_area: "", user_type: UserType::PATIENT, trigger: Trigger::INTERACTION, metadata: {}, use_raw_event_name: false) ⇒ Array
Record analytics data to our enabled analytics channel.
Constructor Details
#initialize(config) ⇒ Analytics
Create a new analytics reporter with the given configuration
19 20 21 |
# File 'lib/path/reporting/analytics.rb', line 19 def initialize(config) @config = config end |
Instance Method Details
#record(name:, user:, product_code: "", product_area: "", user_type: UserType::PATIENT, trigger: Trigger::INTERACTION, metadata: {}, use_raw_event_name: false) ⇒ Array
No patient PII or PHI is allowed in our analytics data. By default we will attempt to strip this out of user data as well as metadata, but this is imperfect and should not be relied on. Instead, proactively exclude that data before it gets here.
The product_code
, product_area
, and name
parameters will
be formatted for easier searching automatically. Feel free to use
regular text formatting here. E.g. "Self Scheduling" or "Hold booked"
Record analytics data to our enabled analytics channel
This is the primary (and at the moment only) way to report analytics data in our systems. Every configured analytics reporter will record the event with the data given here.
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 |
# File 'lib/path/reporting/analytics.rb', line 158 def record( name:, user:, product_code: "", product_area: "", user_type: UserType::PATIENT, trigger: Trigger::INTERACTION, metadata: {}, use_raw_event_name: false ) raise Error, "No user hash provided when reporting analytics" if !user.is_a?(Hash) || !(user[:id] || user["id"] || user[:device_id] || user["device_id"]) raise Error, "Invalid UserType #{user_type}" unless UserType.valid?(user_type) raise Error, "Invalid Trigger #{trigger}" unless Trigger.valid?(trigger) full_name = use_raw_event_name ? name : format_event_name(product_code: product_code, product_area: product_area, name: name) clients.map do |reporter, client| { reporter: reporter.to_s, result: send_event_to_client(client, { name: full_name, user: user, user_type: user_type, metadata: , trigger: trigger }) } end end |