Commit bf0ffb7
committed
refactor(common): consolidate analytics (Commit 2.8)
Consolidates analytics utilities into a dedicated directory structure:
- common/src/analytics/index.ts: Unified re-exports
- common/src/analytics/core.ts: PostHog client factory, types
- common/src/analytics/dispatcher.ts: Cross-platform event dispatcher with buffering
- common/src/analytics/log-helpers.ts: Log data conversion, PII filtering
- common/src/analytics/track-event.ts: Server-side tracking with lazy client init
Key features:
- PII filtering with allowlist/blocklist approach
- MAX_BUFFER_SIZE=100 prevents unbounded memory growth
- Lazy PostHog client initialization in production only
- resetAnalyticsClient() helper exported for testing
Comprehensive unit tests added:
- track-event.test.ts: 16 tests for trackEvent, flushAnalytics, resetAnalyticsClient
- Tests cover lazy init, error handling, env gating, edge cases (empty userId)1 parent f3a68e3 commit bf0ffb7
File tree
12 files changed
+872
-12
lines changed- cli/src/utils
- __tests__
- common/src
- analytics
- __tests__
- util/__tests__
- web/src/util
12 files changed
+872
-12
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
5 | | - | |
| 5 | + | |
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
6 | | - | |
| 6 | + | |
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
17 | | - | |
| 17 | + | |
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
7 | | - | |
| 7 | + | |
8 | 8 | | |
9 | | - | |
| 9 | + | |
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
| |||
0 commit comments