-
[OPIK-5751] [BE][FE] feat: add analytics event tooling (#6251)
发布于
2026-04-15 10:57:53 +00:00 - [OPIK-5751] [BE][FE] feat: add analytics event tooling
Add foundational plumbing for product analytics tracking, independent
from existing OSS usage reporting.Backend:
- New OPIK_ANALYTICS_ENABLED env var (default: false) to control analytics
- New OPIK_ANALYTICS_ENVIRONMENT env var to tag events by deployment
- AnalyticsService with trackEvent() API that auto-injects environment
property and enforces opik_ event name prefix - Events flow through existing comet-stats → Segment → PostHog pipeline
Frontend:
- trackEvent() utility with safe no-op when PostHog isn't loaded
- OpikEvent const for follow-up tickets to register event names
- opik_ prefix enforcement on all custom events
- OPIK_ANALYTICS_ENVIRONMENT registered as PostHog super property
Implements OPIK-5751: PostHog Tooling
- docs: add analytics instrumentation skill
Adds a skill guide for future sessions to wire PostHog analytics events
on both frontend and backend, covering naming conventions, file
locations, and the opik_ prefix requirement.- fix(fe): use Segment instead of PostHog for custom analytics events
Route frontend custom events through Segment (same pipeline as backend)
so all opik_* events flow through a single path: Segment → PostHog.- trackEvent() now calls window.analytics.track() instead of posthog.capture()
- Environment property injected per-event instead of PostHog super property
- PostHog still handles pageviews, feature flags, and user identification
- fix(fe): move tracking utility from posthog/ to analytics/
The tracking utility uses Segment, not PostHog directly, so it belongs
in the analytics/ folder alongside the other Segment code.- fix(bi): address PR review feedback
- Extract StatsClient with shared HTTP transport for sending events to
comet-stats. Used by both BiEventService (usage reporting) and
AnalyticsService (product analytics). - Remove @NonNull from service interfaces (validation belongs to the
implementation, not the contract). - Add log message when analytics is disabled for operator visibility.
- Use BiEvent.builder() instead of constructor.
- Align analytics block in test config with prod config (same comments
and fields, just no env var substitution).
下载附件