behavior_analytics 0.1.0 → 2.0.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 +4 -4
- data/behavior_analytics.gemspec +3 -1
- data/db/migrate/002_enhance_behavior_events_v2.rb +46 -0
- data/lib/behavior_analytics/analytics/cohorts.rb +242 -0
- data/lib/behavior_analytics/analytics/engine.rb +15 -0
- data/lib/behavior_analytics/analytics/funnels.rb +176 -0
- data/lib/behavior_analytics/analytics/retention.rb +186 -0
- data/lib/behavior_analytics/debug/inspector.rb +82 -0
- data/lib/behavior_analytics/export/csv_exporter.rb +102 -0
- data/lib/behavior_analytics/export/json_exporter.rb +55 -0
- data/lib/behavior_analytics/hooks/callback.rb +50 -0
- data/lib/behavior_analytics/hooks/manager.rb +106 -0
- data/lib/behavior_analytics/hooks/webhook.rb +114 -0
- data/lib/behavior_analytics/integrations/rails/middleware.rb +99 -0
- data/lib/behavior_analytics/integrations/rails.rb +106 -0
- data/lib/behavior_analytics/jobs/active_event_job.rb +37 -0
- data/lib/behavior_analytics/jobs/delayed_event_job.rb +29 -0
- data/lib/behavior_analytics/jobs/sidekiq_event_job.rb +37 -0
- data/lib/behavior_analytics/observability/metrics.rb +112 -0
- data/lib/behavior_analytics/observability/tracer.rb +85 -0
- data/lib/behavior_analytics/processors/async_processor.rb +24 -0
- data/lib/behavior_analytics/processors/background_job_processor.rb +72 -0
- data/lib/behavior_analytics/query.rb +87 -2
- data/lib/behavior_analytics/replay/engine.rb +108 -0
- data/lib/behavior_analytics/replay/processor.rb +107 -0
- data/lib/behavior_analytics/reporting/generator.rb +125 -0
- data/lib/behavior_analytics/sampling/strategy.rb +54 -0
- data/lib/behavior_analytics/schema/definition.rb +71 -0
- data/lib/behavior_analytics/schema/validator.rb +113 -0
- data/lib/behavior_analytics/storage/active_record_adapter.rb +168 -8
- data/lib/behavior_analytics/storage/elasticsearch_adapter.rb +175 -0
- data/lib/behavior_analytics/storage/in_memory_adapter.rb +214 -2
- data/lib/behavior_analytics/storage/kafka_adapter.rb +112 -0
- data/lib/behavior_analytics/storage/redis_adapter.rb +175 -0
- data/lib/behavior_analytics/streaming/event_stream.rb +77 -0
- data/lib/behavior_analytics/throttling/limiter.rb +97 -0
- data/lib/behavior_analytics/tracker.rb +130 -4
- data/lib/behavior_analytics/version.rb +1 -1
- data/lib/behavior_analytics.rb +138 -2
- metadata +33 -3
data/lib/behavior_analytics.rb
CHANGED
|
@@ -8,28 +8,164 @@ require_relative "behavior_analytics/query"
|
|
|
8
8
|
require_relative "behavior_analytics/storage/adapter"
|
|
9
9
|
require_relative "behavior_analytics/storage/in_memory_adapter"
|
|
10
10
|
require_relative "behavior_analytics/storage/active_record_adapter"
|
|
11
|
+
|
|
12
|
+
begin
|
|
13
|
+
require_relative "behavior_analytics/storage/redis_adapter"
|
|
14
|
+
rescue LoadError
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
begin
|
|
18
|
+
require_relative "behavior_analytics/storage/elasticsearch_adapter"
|
|
19
|
+
rescue LoadError
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
begin
|
|
23
|
+
require_relative "behavior_analytics/storage/kafka_adapter"
|
|
24
|
+
rescue LoadError
|
|
25
|
+
end
|
|
11
26
|
require_relative "behavior_analytics/analytics/engine"
|
|
27
|
+
require_relative "behavior_analytics/analytics/funnels"
|
|
28
|
+
require_relative "behavior_analytics/analytics/cohorts"
|
|
29
|
+
require_relative "behavior_analytics/analytics/retention"
|
|
30
|
+
require_relative "behavior_analytics/hooks/manager"
|
|
31
|
+
require_relative "behavior_analytics/hooks/webhook"
|
|
32
|
+
require_relative "behavior_analytics/hooks/callback"
|
|
33
|
+
require_relative "behavior_analytics/replay/engine"
|
|
34
|
+
require_relative "behavior_analytics/replay/processor"
|
|
35
|
+
require_relative "behavior_analytics/sampling/strategy"
|
|
36
|
+
require_relative "behavior_analytics/throttling/limiter"
|
|
37
|
+
require_relative "behavior_analytics/schema/validator"
|
|
38
|
+
require_relative "behavior_analytics/schema/definition"
|
|
39
|
+
require_relative "behavior_analytics/export/csv_exporter"
|
|
40
|
+
require_relative "behavior_analytics/export/json_exporter"
|
|
41
|
+
require_relative "behavior_analytics/reporting/generator"
|
|
42
|
+
require_relative "behavior_analytics/observability/metrics"
|
|
43
|
+
require_relative "behavior_analytics/observability/tracer"
|
|
44
|
+
require_relative "behavior_analytics/debug/inspector"
|
|
45
|
+
require_relative "behavior_analytics/processors/async_processor"
|
|
46
|
+
require_relative "behavior_analytics/processors/background_job_processor"
|
|
47
|
+
require_relative "behavior_analytics/streaming/event_stream"
|
|
12
48
|
|
|
13
49
|
begin
|
|
14
50
|
require_relative "behavior_analytics/integrations/rails"
|
|
15
51
|
rescue LoadError
|
|
16
52
|
end
|
|
17
53
|
|
|
54
|
+
begin
|
|
55
|
+
require_relative "behavior_analytics/jobs/active_event_job"
|
|
56
|
+
rescue LoadError
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
begin
|
|
60
|
+
require_relative "behavior_analytics/jobs/sidekiq_event_job"
|
|
61
|
+
rescue LoadError
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
begin
|
|
65
|
+
require_relative "behavior_analytics/jobs/delayed_event_job"
|
|
66
|
+
rescue LoadError
|
|
67
|
+
end
|
|
68
|
+
|
|
18
69
|
module BehaviorAnalytics
|
|
19
|
-
class Error < StandardError
|
|
70
|
+
class Error < StandardError
|
|
71
|
+
attr_reader :context
|
|
72
|
+
|
|
73
|
+
def initialize(message, context: nil)
|
|
74
|
+
super(message)
|
|
75
|
+
@context = context
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
def to_s
|
|
79
|
+
base_message = super
|
|
80
|
+
if @context && BehaviorAnalytics.configuration.debug_mode
|
|
81
|
+
"#{base_message} (Context: #{@context.inspect})"
|
|
82
|
+
else
|
|
83
|
+
base_message
|
|
84
|
+
end
|
|
85
|
+
end
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
class ValidationError < Error; end
|
|
89
|
+
class ConfigurationError < Error; end
|
|
90
|
+
class StorageError < Error; end
|
|
20
91
|
|
|
21
92
|
class Configuration
|
|
22
|
-
attr_accessor :storage_adapter, :batch_size, :flush_interval, :context_resolver, :scoring_weights
|
|
93
|
+
attr_accessor :storage_adapter, :batch_size, :flush_interval, :context_resolver, :scoring_weights,
|
|
94
|
+
:async_processor, :use_async, :event_stream, :environment, :feature_flags,
|
|
95
|
+
:hooks_manager, :raise_on_hook_error, :sampling_strategy, :rate_limiter,
|
|
96
|
+
:schema_validator, :schema_registry, :tracking_whitelist, :tracking_blacklist,
|
|
97
|
+
:skip_bots, :controller_action_filters, :slow_query_threshold, :track_middleware_requests,
|
|
98
|
+
:metrics, :tracer, :debug_mode, :logger
|
|
23
99
|
|
|
24
100
|
def initialize
|
|
25
101
|
@batch_size = 100
|
|
26
102
|
@flush_interval = 300
|
|
103
|
+
@use_async = false
|
|
27
104
|
@scoring_weights = {
|
|
28
105
|
activity: 0.4,
|
|
29
106
|
unique_users: 0.3,
|
|
30
107
|
feature_diversity: 0.2,
|
|
31
108
|
time_in_trial: 0.1
|
|
32
109
|
}
|
|
110
|
+
@environment = ENV["RAILS_ENV"] || ENV["RACK_ENV"] || "development"
|
|
111
|
+
@feature_flags = {}
|
|
112
|
+
@event_stream = Streaming::EventStream.new
|
|
113
|
+
@hooks_manager = Hooks::Manager.new
|
|
114
|
+
@raise_on_hook_error = false
|
|
115
|
+
@schema_registry = Schema::Registry.new
|
|
116
|
+
@tracking_whitelist = nil
|
|
117
|
+
@tracking_blacklist = []
|
|
118
|
+
@skip_bots = true
|
|
119
|
+
@controller_action_filters = {}
|
|
120
|
+
@slow_query_threshold = nil
|
|
121
|
+
@track_middleware_requests = false
|
|
122
|
+
@metrics = Observability::Metrics.new
|
|
123
|
+
@tracer = nil
|
|
124
|
+
@debug_mode = @environment == "development"
|
|
125
|
+
@logger = nil
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
def debug(message, context: nil)
|
|
129
|
+
return unless @debug_mode
|
|
130
|
+
|
|
131
|
+
log_message = "[BehaviorAnalytics] #{message}"
|
|
132
|
+
log_message += " (Context: #{context.inspect})" if context
|
|
133
|
+
|
|
134
|
+
if @logger
|
|
135
|
+
@logger.debug(log_message)
|
|
136
|
+
elsif defined?(Rails) && Rails.logger
|
|
137
|
+
Rails.logger.debug(log_message)
|
|
138
|
+
else
|
|
139
|
+
puts log_message
|
|
140
|
+
end
|
|
141
|
+
end
|
|
142
|
+
|
|
143
|
+
def log_error(error, context: nil)
|
|
144
|
+
error_message = error.message
|
|
145
|
+
error_message += " (Context: #{context.inspect})" if context
|
|
146
|
+
|
|
147
|
+
if @logger
|
|
148
|
+
@logger.error("[BehaviorAnalytics] #{error_message}")
|
|
149
|
+
@logger.error(error.backtrace.join("\n")) if error.backtrace
|
|
150
|
+
elsif defined?(Rails) && Rails.logger
|
|
151
|
+
Rails.logger.error("[BehaviorAnalytics] #{error_message}")
|
|
152
|
+
Rails.logger.error(error.backtrace.join("\n")) if error.backtrace
|
|
153
|
+
else
|
|
154
|
+
puts "[BehaviorAnalytics ERROR] #{error_message}"
|
|
155
|
+
puts error.backtrace.join("\n") if error.backtrace
|
|
156
|
+
end
|
|
157
|
+
end
|
|
158
|
+
|
|
159
|
+
def feature_enabled?(feature)
|
|
160
|
+
@feature_flags.fetch(feature, false)
|
|
161
|
+
end
|
|
162
|
+
|
|
163
|
+
def enable_feature(feature)
|
|
164
|
+
@feature_flags[feature] = true
|
|
165
|
+
end
|
|
166
|
+
|
|
167
|
+
def disable_feature(feature)
|
|
168
|
+
@feature_flags[feature] = false
|
|
33
169
|
end
|
|
34
170
|
end
|
|
35
171
|
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: behavior_analytics
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 2.0.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- nerdawey
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-01-
|
|
11
|
+
date: 2026-01-25 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: activesupport
|
|
@@ -81,22 +81,52 @@ files:
|
|
|
81
81
|
- Rakefile
|
|
82
82
|
- behavior_analytics.gemspec
|
|
83
83
|
- db/migrate/001_create_behavior_events.rb
|
|
84
|
+
- db/migrate/002_enhance_behavior_events_v2.rb
|
|
84
85
|
- lib/behavior_analytics.rb
|
|
86
|
+
- lib/behavior_analytics/analytics/cohorts.rb
|
|
85
87
|
- lib/behavior_analytics/analytics/engine.rb
|
|
88
|
+
- lib/behavior_analytics/analytics/funnels.rb
|
|
89
|
+
- lib/behavior_analytics/analytics/retention.rb
|
|
86
90
|
- lib/behavior_analytics/context.rb
|
|
91
|
+
- lib/behavior_analytics/debug/inspector.rb
|
|
87
92
|
- lib/behavior_analytics/event.rb
|
|
93
|
+
- lib/behavior_analytics/export/csv_exporter.rb
|
|
94
|
+
- lib/behavior_analytics/export/json_exporter.rb
|
|
95
|
+
- lib/behavior_analytics/hooks/callback.rb
|
|
96
|
+
- lib/behavior_analytics/hooks/manager.rb
|
|
97
|
+
- lib/behavior_analytics/hooks/webhook.rb
|
|
88
98
|
- lib/behavior_analytics/integrations/rails.rb
|
|
99
|
+
- lib/behavior_analytics/integrations/rails/middleware.rb
|
|
100
|
+
- lib/behavior_analytics/jobs/active_event_job.rb
|
|
101
|
+
- lib/behavior_analytics/jobs/delayed_event_job.rb
|
|
102
|
+
- lib/behavior_analytics/jobs/sidekiq_event_job.rb
|
|
103
|
+
- lib/behavior_analytics/observability/metrics.rb
|
|
104
|
+
- lib/behavior_analytics/observability/tracer.rb
|
|
105
|
+
- lib/behavior_analytics/processors/async_processor.rb
|
|
106
|
+
- lib/behavior_analytics/processors/background_job_processor.rb
|
|
89
107
|
- lib/behavior_analytics/query.rb
|
|
108
|
+
- lib/behavior_analytics/replay/engine.rb
|
|
109
|
+
- lib/behavior_analytics/replay/processor.rb
|
|
110
|
+
- lib/behavior_analytics/reporting/generator.rb
|
|
111
|
+
- lib/behavior_analytics/sampling/strategy.rb
|
|
112
|
+
- lib/behavior_analytics/schema/definition.rb
|
|
113
|
+
- lib/behavior_analytics/schema/validator.rb
|
|
90
114
|
- lib/behavior_analytics/storage/active_record_adapter.rb
|
|
91
115
|
- lib/behavior_analytics/storage/adapter.rb
|
|
116
|
+
- lib/behavior_analytics/storage/elasticsearch_adapter.rb
|
|
92
117
|
- lib/behavior_analytics/storage/in_memory_adapter.rb
|
|
118
|
+
- lib/behavior_analytics/storage/kafka_adapter.rb
|
|
119
|
+
- lib/behavior_analytics/storage/redis_adapter.rb
|
|
120
|
+
- lib/behavior_analytics/streaming/event_stream.rb
|
|
121
|
+
- lib/behavior_analytics/throttling/limiter.rb
|
|
93
122
|
- lib/behavior_analytics/tracker.rb
|
|
94
123
|
- lib/behavior_analytics/version.rb
|
|
95
124
|
- lib/generators/behavior_analytics/install_generator.rb
|
|
96
125
|
- lib/generators/behavior_analytics/templates/create_behavior_events.rb
|
|
97
126
|
- sig/behavior_analytics.rbs
|
|
98
127
|
homepage: https://github.com/nerdawey/behavior_analytics
|
|
99
|
-
licenses:
|
|
128
|
+
licenses:
|
|
129
|
+
- MIT
|
|
100
130
|
metadata:
|
|
101
131
|
homepage_uri: https://github.com/nerdawey/behavior_analytics
|
|
102
132
|
source_code_uri: https://github.com/nerdawey/behavior_analytics
|