path-reporting 0.1.5 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9cf8b0c5159e89a7fde5da0bf0c2d4912f05f03d62fa5c66e2f5f48143916f36
4
- data.tar.gz: ee8d74820b4f6c194813448700c0eb66c4d72b3b84d8431955c7a297c4db01f0
3
+ metadata.gz: 65674aaa398a650317c350551a9687bc580927ca8c69be1aec45c5888e2135a0
4
+ data.tar.gz: 387f6fe0f5ea344dfa3bda38bdc9caa01ca24f4d99eb56fba464624e54f137bc
5
5
  SHA512:
6
- metadata.gz: '0528361202c2f3750e68181a3203a63c43c7c731710f9bd03814da1416bd46861650337df5f56351b774e0226a4eebb83e9de13119303c6b76822e5f374747c6'
7
- data.tar.gz: ecee15c13b20cbfbabdc9040212bd392ef28ceb8c24dd0cac7e4e7394c16f85f39e5a602543a30fe5b005ef90757c444bbe33480d5fdea3903d5b6260489a835
6
+ metadata.gz: 310a25c14394ac6f910b751ae09ff8aa6d9a49c048fe36724ce4cb42395f7191c550cc223add47ffcda3c4e2c91c2a70d2480b7e7d50e093ff5c92f7eaec7d71
7
+ data.tar.gz: bfe1442c36f0ea3822d9294ac156183b944be879ef39baec1cbca8598e820cca6a1a8f4fb58190843d8d00e7ba94890023e0e8d9471a67ae35550502bc3343a0
data/.rubocop.yml CHANGED
@@ -23,6 +23,10 @@ Metrics/MethodLength:
23
23
  # is difficult to break up reasonably and keep it easy to understand
24
24
  - scrub_pii
25
25
 
26
+ Metrics/AbcSize:
27
+ IgnoredMethods:
28
+ - record
29
+
26
30
  Metrics/ParameterLists:
27
31
  Max: 7
28
32
 
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- path-reporting (0.1.5)
4
+ path-reporting (0.2.0)
5
5
  amplitude-api
6
6
 
7
7
  GEM
@@ -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.result.nil?
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
- # - `reporter` [String] the analytics reporter the result is for
150
- # - `result` [nil | StandardError] what the result of running this
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
- 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.
@@ -3,6 +3,6 @@
3
3
  module Path
4
4
  module Reporting
5
5
  # Current version of the module
6
- VERSION = "0.1.5"
6
+ VERSION = "0.2.0"
7
7
  end
8
8
  end
@@ -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.analytics
46
+ @analytics = Path::Reporting::Analytics.new @config
47
47
  self
48
48
  end
49
49
 
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.5
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-04-29 00:00:00.000000000 Z
11
+ date: 2022-05-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: amplitude-api