feat(db): add widget_events table for lifecycle instrumentation#1
Merged
Merged
Conversation
Adds a raw event-stream table for embedded feedback widgets across platforms (web, iOS, future RN/Android). Captures lifecycle signals (init, identify, launcher_show, open, close) at write-time so a later aggregator job can roll engagement up by day and platform. Complements analytics_daily_stats, which tracks downstream post / vote / comment counts; widget_events captures the upstream impression and engagement signals those don't see. - New table with indexes on created_at, (event_type, created_at), (principal_id, created_at), (platform, created_at) - principal_id is nullable with ON DELETE SET NULL so deletions don't blow away historical engagement records - New TypeID prefix `widget_event` - Schema and migration added; no app-layer wiring in this PR Foundational for a follow-up sequence: ingestion endpoint, widget SDK wiring, and an admin analytics view.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a raw event-stream table for embedded feedback widgets so widget lifecycle signals (init, identify, launcher_show, open, close) can be captured at write-time and later rolled up by an aggregator job.
This is the foundational data-layer slice. No app-layer wiring is included in this PR — that comes next.
Why this and not
analytics_daily_statsanalytics_daily_statsalready tracks downstream activity (new posts / votes / comments, includingpostsBySource.widget). It doesn't see the upstream impression and engagement signals — how often the launcher renders, how often it opens, how many open sessions never result in a post. Those need a separate raw stream that an aggregator can summarize, which is what this table provides.Schema
Indexes:
created_at DESC— time-window scans(event_type, created_at DESC)— "opens in the last 24h" style queries(principal_id, created_at DESC)— per-user engagement lookup(platform, created_at DESC)— per-platform breakdownprincipal_idisON DELETE SET NULLso principal removals don't blow away historical engagement records.New TypeID prefix
widget_eventregistered inpackages/ids.Verification
bun run db:migrateagainst a fresh Postgres applies cleanly through 0066\d widget_eventsconfirms table + 4 indexes + FK toprincipalFollow-ups (separate PRs)
POST /api/analytics/widget-eventingestion endpoint (rate-limited, CORS-aware)packages/widget) to fire lifecycle events, gated by config flagHappy to split or merge follow-ups differently based on what's most useful.
Notes
drizzle/(e.g.,0064_post_mentions.sql,0029_feedback_indexes.sql)