feat(web): add PostHog events for user creation and Ask GitHub login wall#933
feat(web): add PostHog events for user creation and Ask GitHub login wall#933
Conversation
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
WalkthroughAdds PostHog events (wa_user_created, wa_askgh_login_wall_prompted, wa_askgh_repo_indexed), emits them from sign-up, unauthenticated AskGH submit, and repo-index-complete flows; adds debug logging around PostHog captures and a small early-return in org capacity handling; documents events in CHANGELOG. Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant WebApp
participant PostHog
User->>WebApp: Submit sign-up
WebApp->>WebApp: Create user record
WebApp->>WebApp: Check org capacity (may early return)
WebApp->>PostHog: Dynamic import & captureEvent("wa_user_created", { userId })
PostHog-->>WebApp: Ack
WebApp-->>User: Sign-up complete
sequenceDiagram
participant Visitor
participant WebApp
participant PostHog
Visitor->>WebApp: Submit AskGH query (unauthenticated)
WebApp->>PostHog: captureEvent("wa_askgh_login_wall_prompted", {})
WebApp->>WebApp: Persist pending message & open login modal
WebApp-->>Visitor: Prompt to log in
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested reviewers
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
fa31d25 to
114cba7
Compare
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
packages/web/src/lib/authUtils.ts (1)
113-116:⚠️ Potential issue | 🟡 Minor
wa_user_createdsilently skipped when org is at capacity.When
!hasAvailability, the function returns early at line 115 without emitting the event. At this point the user record was already created by NextAuth (that's whyonCreateUseris being called), so the sign-up did occur — the user just wasn't admitted to the org. If the goal is to track all successful account creations for a conversion funnel, the event should fire here too (or be moved before the capacity check).🐛 Proposed fix
if (!hasAvailability) { logger.warn(`onCreateUser: org ${SINGLE_TENANT_ORG_ID} has reached max capacity. User ${user.id} was not added to the org.`); + await captureEvent('wa_user_created', { userId: user.id }).catch((e) => logger.warn('Failed to capture wa_user_created event', e)); return; }Then remove the standalone call at line 127, or keep it only for the non-early-return paths (depending on whether you want a single emit point).
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/web/src/lib/authUtils.ts` around lines 113 - 116, The onCreateUser flow currently returns early when !hasAvailability and thus never emits the wa_user_created event even though NextAuth already created the user; update the onCreateUser handler to emit wa_user_created before the early return (include same payload used elsewhere so sign-ups are tracked even when a user isn't admitted to the org), and then remove or guard the later standalone wa_user_created emit so the event is only emitted once per creation; references: function onCreateUser, constant SINGLE_TENANT_ORG_ID, variable hasAvailability, and the wa_user_created event emission point.
🧹 Nitpick comments (1)
packages/web/src/lib/posthogEvents.ts (1)
230-232: Consider placingwa_user_creatednear the other auth-related events.The new event is inserted between the chat-event cluster and the demo-event cluster. For discoverability, placing it near the
wa_login_*group (lines 102–109) or in a dedicated//////////////////////////////////////////////////////////////////auth section would improve consistency.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/web/src/lib/posthogEvents.ts` around lines 230 - 232, Move the wa_user_created event definition next to the other auth-related events (e.g., near the wa_login_* group or into a dedicated auth section) so it is grouped with authentication telemetry; update its position in the posthogEvents export (the object containing wa_login_* and related auth events) and ensure any nearby comment separators (e.g., the demo/chat clusters) are adjusted to keep clusters consistent and discoverable.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Outside diff comments:
In `@packages/web/src/lib/authUtils.ts`:
- Around line 113-116: The onCreateUser flow currently returns early when
!hasAvailability and thus never emits the wa_user_created event even though
NextAuth already created the user; update the onCreateUser handler to emit
wa_user_created before the early return (include same payload used elsewhere so
sign-ups are tracked even when a user isn't admitted to the org), and then
remove or guard the later standalone wa_user_created emit so the event is only
emitted once per creation; references: function onCreateUser, constant
SINGLE_TENANT_ORG_ID, variable hasAvailability, and the wa_user_created event
emission point.
---
Nitpick comments:
In `@packages/web/src/lib/posthogEvents.ts`:
- Around line 230-232: Move the wa_user_created event definition next to the
other auth-related events (e.g., near the wa_login_* group or into a dedicated
auth section) so it is grouped with authentication telemetry; update its
position in the posthogEvents export (the object containing wa_login_* and
related auth events) and ensure any nearby comment separators (e.g., the
demo/chat clusters) are adjusted to keep clusters consistent and discoverable.
Fire a `wa_user_created` telemetry event in the NextAuth `onCreateUser` handler so we can track successful sign-ups in PostHog, closing a gap in the visitor-to-sign-up conversion funnel. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
114cba7 to
66f1879
Compare
Fire a `wa_user_created` telemetry event in the NextAuth `onCreateUser` handler so we can track successful sign-ups in PostHog, closing a gap in the visitor-to-sign-up conversion funnel. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…wall - Add `wa_user_created` event fired on successful user sign-up - Add `wa_askgh_login_wall_prompted` event fired when an unauthenticated user attempts to ask a question on Ask GitHub and is shown the login modal - Add debug logging to server-side PostHog event capture Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In
`@packages/web/src/app/`[domain]/askgh/[owner]/[repo]/components/landingPage.tsx:
- Line 59: Wrap the telemetry call so a thrown error from
captureEvent/posthog.capture cannot interrupt the auth flow: surround the
existing captureEvent('wa_askgh_login_wall_prompted', {}) call with a try/catch,
call console.error or processLogger in the catch, and allow the subsequent
sessionStorage persistence and modal open logic to always run (i.e., do not
rethrow). Refer to the captureEvent/posthog.capture call and the code that
writes to sessionStorage and opens the login modal so you update the right spot.
In `@packages/web/src/lib/posthog.ts`:
- Around line 98-99: Remove PII from the debug log call by stopping inclusion of
distinctId and the spread properties; update the logger.debug invocation that
currently uses logger.debug(`Capturing event: ${event}`, { distinctId, host,
...properties }) to only log non-identifying fields (for example event and host)
or a sanitized summary, ensuring distinctId and ...properties (which can contain
userId from wa_user_created) are omitted or redacted; locate the logger.debug
line and variables distinctId, properties, host, event and change the second
argument to exclude distinctId and properties.
ℹ️ Review info
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
packages/web/src/app/[domain]/askgh/[owner]/[repo]/components/landingPage.tsxpackages/web/src/lib/posthog.tspackages/web/src/lib/posthogEvents.ts
🚧 Files skipped from review as they are similar to previous changes (1)
- packages/web/src/lib/posthogEvents.ts
packages/web/src/app/[domain]/askgh/[owner]/[repo]/components/landingPage.tsx
Show resolved
Hide resolved
Fires when a repo completes indexing on Ask GitHub, capturing the repo name. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…_indexed backend_repo_first_indexed already fires server-side in repoIndexManager.ts when a repo is first indexed, which is more reliable than client-side tracking. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@packages/web/src/lib/posthogEvents.ts`:
- Around line 230-237: The schema currently includes raw identifiers in events
(wa_user_created.userId and wa_askgh_repo_indexed.repoName); change these
properties to opaque/minimized values before sending—e.g., replace userId and
repoName with deterministic hashed IDs or non-PII buckets/flags and update the
schema types in posthogEvents (wa_user_created and wa_askgh_repo_indexed)
accordingly; implement and call a hashing/normalization helper (consistent
algorithm like SHA‑256 or HMAC with a service secret) where events are
constructed to ensure values are irreversible and strip any raw identifiers from
payloads.
ℹ️ Review info
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
packages/web/src/app/[domain]/askgh/[owner]/[repo]/components/repoIndexedGuard.tsxpackages/web/src/lib/posthogEvents.ts
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Summary
wa_user_createdPostHog event that fires in the NextAuthonCreateUserhandler when a user successfully signs upwa_askgh_login_wall_promptedPostHog event that fires when an unauthenticated user attempts to ask a question on Ask GitHub and is shown the login modalTest plan
wa_user_createdevent appears in PostHog after a new user signs upwa_askgh_login_wall_promptedevent appears in PostHog when an unauthenticated user tries to submit a question on an Ask GitHub page🤖 Generated with Claude Code
Summary by CodeRabbit
New Features
Chores