path-reporting 0.1.3 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +4 -0
- data/Gemfile.lock +1 -1
- data/README.md +2 -2
- data/lib/path/reporting/analytics/amplitude.rb +11 -3
- data/lib/path/reporting/analytics/configuration.rb +1 -1
- data/lib/path/reporting/analytics/console.rb +1 -1
- data/lib/path/reporting/analytics.rb +12 -13
- data/lib/path/reporting/configuration.rb +1 -0
- data/lib/path/reporting/types/trigger.rb +16 -16
- data/lib/path/reporting/types/user_type.rb +14 -14
- data/lib/path/reporting/version.rb +1 -1
- data/lib/path/reporting.rb +3 -3
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 65674aaa398a650317c350551a9687bc580927ca8c69be1aec45c5888e2135a0
|
4
|
+
data.tar.gz: 387f6fe0f5ea344dfa3bda38bdc9caa01ca24f4d99eb56fba464624e54f137bc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 310a25c14394ac6f910b751ae09ff8aa6d9a49c048fe36724ce4cb42395f7191c550cc223add47ffcda3c4e2c91c2a70d2480b7e7d50e093ff5c92f7eaec7d71
|
7
|
+
data.tar.gz: bfe1442c36f0ea3822d9294ac156183b944be879ef39baec1cbca8598e820cca6a1a8f4fb58190843d8d00e7ba94890023e0e8d9471a67ae35550502bc3343a0
|
data/.rubocop.yml
CHANGED
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -42,8 +42,8 @@ Path::Reporting.analytics.record(
|
|
42
42
|
product_area: Constants::ANALYTICS_PRODUCT_AREA_MATCHING,
|
43
43
|
name: 'Preferred provider multiple valid matches',
|
44
44
|
user: @contact.analytics_friendly_hash,
|
45
|
-
user_type: Path::Reporting::UserType
|
46
|
-
trigger: Path::Reporting::Trigger
|
45
|
+
user_type: Path::Reporting::UserType::PATIENT,
|
46
|
+
trigger: Path::Reporting::Trigger::PAGE_VIEW,
|
47
47
|
metadata: analytics_metadata,
|
48
48
|
)
|
49
49
|
```
|
@@ -57,6 +57,8 @@ module Path
|
|
57
57
|
class Analytics
|
58
58
|
# Amplitude analytics is our primary analytics channel for production
|
59
59
|
class Amplitude
|
60
|
+
attr_reader :config
|
61
|
+
|
60
62
|
# Setup and configure AmplitudeAPI with the given configuration
|
61
63
|
# @param config [AmplitudeAPI::Config] the configuration for AmplitudeAPI
|
62
64
|
# @see https://www.rubydoc.info/gems/amplitude-api/AmplitudeAPI/Config AmplitudeAPI::Config Documentation
|
@@ -64,7 +66,7 @@ module Path
|
|
64
66
|
def initialize(config)
|
65
67
|
@config = config
|
66
68
|
|
67
|
-
config.amplitude_config.each do |key, value|
|
69
|
+
config.analytics.amplitude_config.each do |key, value|
|
68
70
|
AmplitudeAPI.config.instance_variable_set("@#{key}", value)
|
69
71
|
end
|
70
72
|
end
|
@@ -81,9 +83,10 @@ module Path
|
|
81
83
|
metadata = metadata.dup
|
82
84
|
user[:user_type] = user_type
|
83
85
|
metadata[:trigger] = trigger
|
86
|
+
metadata[:system_name] = config.system_name
|
84
87
|
|
85
88
|
event_props = {
|
86
|
-
user_id: user[:id].to_s,
|
89
|
+
user_id: (user[:id] || user["id"]).to_s,
|
87
90
|
user_properties: scrub_pii(user),
|
88
91
|
event_type: name,
|
89
92
|
event_properties: scrub_pii(metadata)
|
@@ -92,7 +95,10 @@ module Path
|
|
92
95
|
event_props[key] = metadata[key] if metadata.key? key
|
93
96
|
end
|
94
97
|
|
95
|
-
AmplitudeAPI.track AmplitudeAPI::Event.new event_props
|
98
|
+
response = AmplitudeAPI.track AmplitudeAPI::Event.new event_props
|
99
|
+
raise Error, response.body unless response.success?
|
100
|
+
|
101
|
+
response
|
96
102
|
end
|
97
103
|
|
98
104
|
# Scrub known PII keys from a hash
|
@@ -117,6 +123,8 @@ module Path
|
|
117
123
|
|
118
124
|
data
|
119
125
|
end
|
126
|
+
|
127
|
+
class Error < StandardError; end
|
120
128
|
end
|
121
129
|
end
|
122
130
|
end
|
@@ -44,7 +44,7 @@ module Path
|
|
44
44
|
# @return [Hash] amplitude configuration options as passed along to the amplitude-api gem
|
45
45
|
# @see https://www.rubydoc.info/gems/amplitude-api/AmplitudeAPI/Config AmplitudeAPI::Config
|
46
46
|
def amplitude_config=(conf)
|
47
|
-
@amplitude_enabled = !conf.nil?
|
47
|
+
@amplitude_enabled = !(conf.nil? || conf.empty?)
|
48
48
|
@amplitude_config = conf
|
49
49
|
end
|
50
50
|
|
@@ -10,7 +10,7 @@ module Path
|
|
10
10
|
# @param config [Analytics::Configuration] the configuration for the reporter
|
11
11
|
# @see Analytics::Configuration
|
12
12
|
def initialize(config)
|
13
|
-
@config = config
|
13
|
+
@config = config.analytics
|
14
14
|
end
|
15
15
|
|
16
16
|
# Log the analytics event to the configured logger
|
@@ -36,14 +36,14 @@ module Path
|
|
36
36
|
# @private
|
37
37
|
def setup_amplitude
|
38
38
|
# Amplitude reporting for metrics
|
39
|
-
return Path::Reporting::Analytics::Amplitude.new @config if @config.amplitude_enabled?
|
39
|
+
return Path::Reporting::Analytics::Amplitude.new @config if @config.analytics.amplitude_enabled?
|
40
40
|
|
41
41
|
nil
|
42
42
|
end
|
43
43
|
|
44
44
|
# @private
|
45
45
|
def setup_console
|
46
|
-
return Path::Reporting::Analytics::Console.new @config if @config.console_enabled?
|
46
|
+
return Path::Reporting::Analytics::Console.new @config if @config.analytics.console_enabled?
|
47
47
|
|
48
48
|
nil
|
49
49
|
end
|
@@ -122,7 +122,7 @@ module Path
|
|
122
122
|
# product_area: Constants::ANALYTICS_PRODUCT_AREA_MATCHING,
|
123
123
|
# name: 'Preferred provider multiple valid matches',
|
124
124
|
# user: @contact.analytics_friendly_hash,
|
125
|
-
# user_type: PathReporting::UserType
|
125
|
+
# user_type: PathReporting::UserType::PATIENT,
|
126
126
|
# trigger: PathReporting::Trigger.PAGE_VIEW,
|
127
127
|
# metadata: analytics_metadata,
|
128
128
|
# )
|
@@ -132,12 +132,12 @@ module Path
|
|
132
132
|
# product_area: Constants::ANALYTICS_PRODUCT_AREA_MATCHING,
|
133
133
|
# name: 'No preferred provider',
|
134
134
|
# user: @contact.analytics_friendly_hash,
|
135
|
-
# user_type: PathReporting::UserType
|
135
|
+
# user_type: PathReporting::UserType::PATIENT,
|
136
136
|
# trigger: PathReporting::Trigger.PAGE_VIEW,
|
137
137
|
# )
|
138
138
|
#
|
139
139
|
# analytics_reported.each do |status|
|
140
|
-
# Rails.logger.warn("#{status.reporter} failed") unless status
|
140
|
+
# Rails.logger.warn("#{status.reporter} failed") unless status[:result].nil?
|
141
141
|
# end
|
142
142
|
#
|
143
143
|
# @raise [StandardError] if no user is provided or user does not have id
|
@@ -146,8 +146,8 @@ module Path
|
|
146
146
|
#
|
147
147
|
# @return [Array] An array of result hashes with two keys:
|
148
148
|
#
|
149
|
-
# -
|
150
|
-
# -
|
149
|
+
# - `:reporter` [String] the analytics reporter the result is for
|
150
|
+
# - `:result` [nil | StandardError] what the result of running this
|
151
151
|
# reporter was. If it did not run, it will always be `nil`
|
152
152
|
#
|
153
153
|
# @see https://docs.google.com/document/d/1axnk1EkKCb__sxtvMomrPNup3wsviDOAefQWwXU3Z3U/edit# Analytics Guide
|
@@ -158,13 +158,13 @@ module Path
|
|
158
158
|
product_area:,
|
159
159
|
name:,
|
160
160
|
user:,
|
161
|
-
user_type: UserType
|
162
|
-
trigger: Trigger
|
161
|
+
user_type: UserType::PATIENT,
|
162
|
+
trigger: Trigger::INTERACTION,
|
163
163
|
metadata: {}
|
164
164
|
)
|
165
|
-
throw Error("No user provided when reporting analytics") if !user || !user[:id]
|
166
|
-
throw Error("Invalid UserType #{user_type}") unless UserType.valid?(user_type)
|
167
|
-
throw Error("Invalid Trigger #{trigger}") unless Trigger.valid?(trigger)
|
165
|
+
throw Error.new("No user hash provided when reporting analytics") if !user.is_a?(Hash) || !(user[:id] || user["id"])
|
166
|
+
throw Error.new("Invalid UserType #{user_type}") unless UserType.valid?(user_type)
|
167
|
+
throw Error.new("Invalid Trigger #{trigger}") unless Trigger.valid?(trigger)
|
168
168
|
|
169
169
|
clients.map do |reporter, client|
|
170
170
|
{
|
@@ -185,7 +185,6 @@ module Path
|
|
185
185
|
# @private
|
186
186
|
def send_event_to_client(client, event)
|
187
187
|
client&.record(**event)
|
188
|
-
nil
|
189
188
|
rescue StandardError => e
|
190
189
|
e
|
191
190
|
end
|
@@ -9,6 +9,7 @@ module Path
|
|
9
9
|
# @return [Analytics::Configuration] the configuration for analytics reporting
|
10
10
|
class Configuration
|
11
11
|
attr_reader :analytics
|
12
|
+
attr_accessor :system_name
|
12
13
|
|
13
14
|
# Create a new configuration. Sub configuration's will be used by the
|
14
15
|
# various reporting sections.
|
@@ -4,22 +4,22 @@ module Path
|
|
4
4
|
module Reporting
|
5
5
|
# The trigger or cause of reporting events
|
6
6
|
class Trigger
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
AUTOMATION = "Automation"
|
7
|
+
# Interaction: When a direct intentional user action is the cause of
|
8
|
+
# this event that is not a simple navigation. E.g. Submitted form or
|
9
|
+
# changed password
|
10
|
+
INTERACTION = "Interaction"
|
11
|
+
# Page view: When the event was an indirect result of viewing something.
|
12
|
+
# E.g. auto-assigning a provider or appointment because the user has an
|
13
|
+
# existing provider already
|
14
|
+
# @note Because of usage limits, we do not want to record page views
|
15
|
+
# as a separate action, this is only for indirect consequences that
|
16
|
+
# result in a change in something either for the user or for our
|
17
|
+
# systems
|
18
|
+
PAGE_VIEW = "Page view"
|
19
|
+
# Automation: Some automation or tool was the cause of this event
|
20
|
+
AUTOMATION = "Automation"
|
22
21
|
|
22
|
+
class << self
|
23
23
|
# @private
|
24
24
|
def triggers
|
25
25
|
[
|
@@ -32,7 +32,7 @@ module Path
|
|
32
32
|
# Check if a given item is a valid Trigger
|
33
33
|
# @param maybe_trigger [Any] item to check
|
34
34
|
def valid?(maybe_trigger)
|
35
|
-
triggers.
|
35
|
+
triggers.include? maybe_trigger
|
36
36
|
end
|
37
37
|
end
|
38
38
|
end
|
@@ -4,20 +4,20 @@ module Path
|
|
4
4
|
module Reporting
|
5
5
|
# User types that data may be recorded for or on
|
6
6
|
class UserType
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
SYSTEM = "System"
|
7
|
+
# Patient or potential patient
|
8
|
+
PATIENT = "Patient"
|
9
|
+
# Provider, which can be any sub-type (e.g. therapist)
|
10
|
+
PROVIDER = "Provider"
|
11
|
+
# Insurer, not currently in-use
|
12
|
+
INSURER = "Insurer"
|
13
|
+
# Operator or any internal non-developer
|
14
|
+
OPERATOR = "Operator"
|
15
|
+
# Developer; mostly relevant for backfills or manual intervention
|
16
|
+
DEVELOPER = "Developer"
|
17
|
+
# System, either first-party or third-party
|
18
|
+
SYSTEM = "System"
|
20
19
|
|
20
|
+
class << self
|
21
21
|
# @private
|
22
22
|
def types
|
23
23
|
[
|
@@ -33,7 +33,7 @@ module Path
|
|
33
33
|
# Check if a given item is a valid UserType
|
34
34
|
# @param maybe_type [Any] item to check
|
35
35
|
def valid?(maybe_type)
|
36
|
-
types.
|
36
|
+
types.include? maybe_type
|
37
37
|
end
|
38
38
|
end
|
39
39
|
end
|
data/lib/path/reporting.rb
CHANGED
@@ -43,7 +43,7 @@ module Path
|
|
43
43
|
@config = Configuration.new
|
44
44
|
yield(@config) if block_given?
|
45
45
|
|
46
|
-
@analytics = Path::Reporting::Analytics.new @config
|
46
|
+
@analytics = Path::Reporting::Analytics.new @config
|
47
47
|
self
|
48
48
|
end
|
49
49
|
|
@@ -52,7 +52,7 @@ module Path
|
|
52
52
|
def analytics
|
53
53
|
raise Error, "Must call init on Path::Reporting library before using" unless @initialized
|
54
54
|
|
55
|
-
@
|
55
|
+
@analytics
|
56
56
|
end
|
57
57
|
|
58
58
|
# Resets the module to an uninitialized state. Mostly used for testing
|
@@ -60,7 +60,7 @@ module Path
|
|
60
60
|
def reset!
|
61
61
|
@initialized = false
|
62
62
|
@config = nil
|
63
|
-
@
|
63
|
+
@analytics = nil
|
64
64
|
self
|
65
65
|
end
|
66
66
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: path-reporting
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alexis Hushbeck
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-05-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: amplitude-api
|