path-reporting 0.1.5 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +14 -0
- data/Gemfile.lock +1 -1
- 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 +8 -9
- data/lib/path/reporting/configuration.rb +1 -0
- data/lib/path/reporting/version.rb +1 -1
- data/lib/path/reporting.rb +1 -1
- 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: a6b7ebe13598a8981a1ad44c41c264457600e8f417d5a694765a60dd7c5e3ec6
|
4
|
+
data.tar.gz: 233fe988e98f6477e898b321696c6c7785653357ef0f6340cf2a7a08ae172c29
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8a1ed8ab2ea99100b6fed608e422b019e56232653fe8d660689a4bd78950239d8070a1b0e37a7438e377506ec19409b465d3b58bbef47e81e2c6933a9191a84d
|
7
|
+
data.tar.gz: 91d43eedcf86a956d6e18ad816ce7a8155e8cea30dfea156aec0f6097c6dbd1d0a5c584b503917b70d929cc66e5138a1ba2b753c47d28cd566ffb653c66031eb
|
data/.rubocop.yml
CHANGED
@@ -23,6 +23,20 @@ Metrics/MethodLength:
|
|
23
23
|
# is difficult to break up reasonably and keep it easy to understand
|
24
24
|
- scrub_pii
|
25
25
|
|
26
|
+
Metrics/CyclomaticComplexity:
|
27
|
+
IgnoredMethods:
|
28
|
+
# `record` is too complex mostly due to safety checks and not core logic
|
29
|
+
- record
|
30
|
+
|
31
|
+
Metrics/PerceivedComplexity:
|
32
|
+
IgnoredMethods:
|
33
|
+
# `record` is too complex mostly due to safety checks and not core logic
|
34
|
+
- record
|
35
|
+
|
36
|
+
Metrics/AbcSize:
|
37
|
+
IgnoredMethods:
|
38
|
+
- record
|
39
|
+
|
26
40
|
Metrics/ParameterLists:
|
27
41
|
Max: 7
|
28
42
|
|
data/Gemfile.lock
CHANGED
@@ -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
|
@@ -137,7 +137,7 @@ module Path
|
|
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
|
@@ -162,9 +162,9 @@ module Path
|
|
162
162
|
trigger: Trigger::INTERACTION,
|
163
163
|
metadata: {}
|
164
164
|
)
|
165
|
-
|
166
|
-
|
167
|
-
|
165
|
+
raise Error, "No user hash provided when reporting analytics" if !user.is_a?(Hash) || !(user[:id] || user["id"] || user[:device_id] || user["device_id"])
|
166
|
+
raise Error, "Invalid UserType #{user_type}" unless UserType.valid?(user_type)
|
167
|
+
raise Error, "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.
|
data/lib/path/reporting.rb
CHANGED
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.1
|
4
|
+
version: 0.2.1
|
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-09-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: amplitude-api
|