114 lines
4.6 KiB
Markdown
114 lines
4.6 KiB
Markdown
# Tasks: enterprise-analytics-browser
|
||
|
||
**Change ID**: enterprise-analytics-browser
|
||
**Package**: `@suaveplan/analytics-browser`
|
||
**Target path**: `packages/observability/monitor/analytics-browser`
|
||
|
||
---
|
||
|
||
## 0. Pre-flight
|
||
|
||
- [x] 0.1 `git worktree list` + `git status` per worktree.
|
||
- [x] 0.2 Worktree HEAD fast-forwarded to `b22864397b…` (genesis baseline).
|
||
- [x] 0.3 Confirmed package set in `MANIFEST.md` (regenerated post-merge).
|
||
|
||
## 1. Scaffold
|
||
|
||
- [x] Create directory tree per `design.md`.
|
||
- [x] `package.json` v0.1.0, `"browser"` field, `"sideEffects": false`, subpath exports.
|
||
- [x] `tsconfig.lib.json`, `vite.config.ts`, `vitest.config.ts` (happy-dom, pool: forks, istanbul 100/100/100/100).
|
||
|
||
## 2. Error codes (`src/error-codes/`)
|
||
|
||
- [x] `error-codes.ts` — `ANALYTICS_BROWSER_CODES` (8) + `AnalyticsBrowserError`.
|
||
- [x] `error-codes.test.ts`, `error-codes.md`, `index.ts`.
|
||
|
||
## 3. Types (`src/types/`)
|
||
|
||
- [x] `analytics.types.ts` — `AnalyticsEvent`, `TrackerOptions`, `Transport`, `AnalyticsEventMap`, `StorageBackend`, `SessionInfo`, `SessionOptions`, `BatchTransportOptions`, `BeaconTransportOptions`, `ScrubRule`, `ScrubStrategy`, `ConsentPolicy`, `Sampler`, `DropReason`.
|
||
- [x] `analytics.types.md`.
|
||
|
||
## 4. Constants (`src/constants/`)
|
||
|
||
- [x] `DEFAULT_TRACKER_OPTIONS`, `DEFAULT_BATCH_OPTIONS`, `DEFAULT_BEACON_OPTIONS`, `DEFAULT_SESSION_TIMEOUT_MS`.
|
||
|
||
## 5. ID generator (`src/internal/id/`)
|
||
|
||
- [x] `id.ts` — `generateId()` using `crypto.getRandomValues`.
|
||
- [x] `id.test.ts`, `id.md`, `index.ts`.
|
||
|
||
## 6. Schema (`src/schema/`)
|
||
|
||
- [x] `analytics-event-schema.ts` — `AnalyticsEventSchema` + `validateAnalyticsEvent`.
|
||
- [x] `analytics-event-schema.test.ts`, `analytics-event-schema.md`, `index.ts`.
|
||
|
||
## 7. Consent (`src/consent/`)
|
||
|
||
- [x] `consent.ts` — `ConsentPolicy`, `AllowAllPolicy`, `DoNotTrackPolicy`.
|
||
- [x] `consent.test.ts`, `consent.md`, `index.ts`.
|
||
|
||
## 8. PII (`src/pii/`)
|
||
|
||
- [x] `pii.ts` — `scrubPII` with `redact` / `hash` / `drop` strategies (dotted paths).
|
||
- [x] `pii.test.ts`, `pii.md`, `index.ts`.
|
||
|
||
## 9. Sampling (`src/sampling/`)
|
||
|
||
- [x] `sampling.ts` — `Sampler`, `HeadSampler` with per-event overrides.
|
||
- [x] `sampling.test.ts`, `sampling.md`, `index.ts`.
|
||
|
||
## 10. Storage backends (`src/storage/`)
|
||
|
||
- [x] `storage.ts` — `StorageBackend` interface, `MemoryStorageBackend`, `WebStorageBackend` (`maxBytes` + `QUEUE_FULL`).
|
||
- [x] `storage.test.ts`, `storage.md`, `index.ts`.
|
||
|
||
## 11. Session (`src/session/`)
|
||
|
||
- [x] `session.ts` — `SessionManager` (id / pageviews / duration / referrer / inactivity / renew / end).
|
||
- [x] `session.test.ts`, `session.md`, `index.ts`.
|
||
|
||
## 12. Transports (`src/transport/`)
|
||
|
||
- [x] `batch.ts` — `BatchTransport` (AbortController + `timeoutMs` + exponential backoff + 4xx short-circuit).
|
||
- [x] `beacon.ts` — `BeaconTransport` (`sendBeacon` + `fetch keepalive` fallback).
|
||
- [x] `batch.test.ts`, `batch.md`, `beacon.test.ts`, `beacon.md`, `index.ts`.
|
||
|
||
## 13. Tracker (`src/tracker/`)
|
||
|
||
- [x] `tracker.ts` — `AnalyticsTracker` consuming `EventBus<AnalyticsEventMap>`; consent → sampling → PII → enqueue + storage round-trip; auto-flush via injectable `TimersLike`; `restore()`; `identify`; `setProperties`; `setSessionId`; `flush()`; `shutdown()`.
|
||
- [x] `tracker.test.ts`, `tracker.md`, `index.ts`.
|
||
|
||
## 14. Telemetry (`src/telemetry/`)
|
||
|
||
- [x] `telemetry.ts` — `eventsTrackedCounter`, `eventsFlushedCounter`, `eventsDroppedCounter`, `batchSizeHistogram`, `flushLatencyHistogram` + `record*` helpers.
|
||
- [x] `telemetry.test.ts`, `telemetry.md`, `index.ts`.
|
||
|
||
## 15. Barrel (`src/index.ts`)
|
||
|
||
- [x] Explicit named re-exports — no `export *` per §6a.
|
||
|
||
## 16. Tests setup + integration
|
||
|
||
- [x] `tests/setup/polyfills.ts` — web-crypto + OTel `InMemoryMetricExporter`.
|
||
- [x] `tests/integration.test.ts` — tracker → batch transport → in-process endpoint; "no `node:` imports in src/".
|
||
|
||
## 17. Docs
|
||
|
||
- [x] `README.md` — overview, subpath table, consent / PII / sampling / storage guides, migration notes from upstream `EventEmitter` → `EventBus`.
|
||
|
||
## 18. Verify
|
||
|
||
- [x] `bunx turbo lint typecheck test build --filter=@suaveplan/analytics-browser` — green.
|
||
- [x] `bunx turbo test:coverage --filter=@suaveplan/analytics-browser` — 100/100/100/100.
|
||
- [x] `bun scripts/folder-reorg/generate-manifest.ts` (refresh `MANIFEST.md`).
|
||
- [x] No `@ts-expect-error`, `any`, `console.log`, `vi.mock`, `vi.stubGlobal` in src/.
|
||
|
||
## 19. Fold + archive
|
||
|
||
- [x] Fold `specs/analytics-browser/spec.md` into `openspec/specs/analytics-browser/spec.md`.
|
||
- [x] Move folder to `openspec/archive/2026-05-25-enterprise-analytics-browser/`.
|
||
|
||
## 20. STATUS
|
||
|
||
- [x] Flip `@suaveplan/analytics-browser` `–` → `✅` in `STATUS.md`; bump migrated count 283 → 284, pending 210 → 209.
|