Skip to content

feat(web): add PostHog events for user creation and Ask GitHub login wall#933

Merged
msukkari merged 8 commits intomainfrom
michael/add-user-created-posthog-event
Feb 24, 2026
Merged

feat(web): add PostHog events for user creation and Ask GitHub login wall#933
msukkari merged 8 commits intomainfrom
michael/add-user-created-posthog-event

Conversation

@msukkari
Copy link
Contributor

@msukkari msukkari commented Feb 24, 2026

Summary

  • Adds a new wa_user_created PostHog event that fires in the NextAuth onCreateUser handler when a user successfully signs up
  • Adds a new wa_askgh_login_wall_prompted PostHog event that fires when an unauthenticated user attempts to ask a question on Ask GitHub and is shown the login modal
  • Adds debug logging to server-side PostHog event capture
  • These events enable a complete visitor-to-sign-up conversion funnel: page visit → attempted question (login wall) → signed up → asked a question

Test plan

  • Verify wa_user_created event appears in PostHog after a new user signs up
  • Verify wa_askgh_login_wall_prompted event appears in PostHog when an unauthenticated user tries to submit a question on an Ask GitHub page
  • Verify existing sign-up and Ask GitHub flows are unaffected

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features

    • Added Bitbucket Cloud OAuth SSO support
    • Enabled permission syncing for Bitbucket Cloud accounts
  • Chores

    • Expanded analytics: capture user sign-ups, Ask GitHub login prompts, repository indexing, and additional chat UI interactions (details toggle, copy answer, TOC toggle, repo tracking)
    • Added additional event logging for debugging and diagnostics

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 24, 2026

Note

Reviews paused

It 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 reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

Walkthrough

Adds 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

Cohort / File(s) Summary
Analytics Event Definitions
packages/web/src/lib/posthogEvents.ts
Adds wa_user_created: { userId: string }, wa_askgh_login_wall_prompted: {}, and wa_askgh_repo_indexed: { repoName: string } to the event map.
User creation instrumentation
packages/web/src/lib/authUtils.ts
Dynamically imports PostHog and captures wa_user_created after signup; adds early return when org has no capacity.
Unauthenticated AskGH instrumentation
packages/web/src/app/[domain]/askgh/[owner]/[repo]/components/landingPage.tsx
Emits wa_askgh_login_wall_prompted when unauthenticated users submit an AskGH query before persisting pending message and opening login modal.
Repo indexing instrumentation
packages/web/src/app/[domain]/askgh/[owner]/[repo]/components/repoIndexedGuard.tsx
Emits wa_askgh_repo_indexed when a repo transitions to indexed, alongside existing notification logic.
PostHog initialization & logging
packages/web/src/lib/posthog.ts
Introduces logger via createLogger('posthog') and logs event name/properties at debug level before capturing events.
Changelog
CHANGELOG.md
Documents new events and chat UI telemetry additions; mentions Bitbucket Cloud provider and permission syncing entries.

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
Loading
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
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested reviewers

  • brendan-kellam
🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately captures the main changes: adding PostHog events for user creation and Ask GitHub login wall prompt tracking.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch michael/add-user-created-posthog-event

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@msukkari msukkari force-pushed the michael/add-user-created-posthog-event branch 2 times, most recently from fa31d25 to 114cba7 Compare February 24, 2026 22:17
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_created silently 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 why onCreateUser is 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 placing wa_user_created near 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.

ℹ️ Review info

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 649671b and 114cba7.

📒 Files selected for processing (3)
  • CHANGELOG.md
  • packages/web/src/lib/authUtils.ts
  • packages/web/src/lib/posthogEvents.ts

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>
@msukkari msukkari force-pushed the michael/add-user-created-posthog-event branch from 114cba7 to 66f1879 Compare February 24, 2026 22:28
msukkari and others added 3 commits February 24, 2026 15:11
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>
@msukkari msukkari changed the title feat: add wa_user_created PostHog event on successful sign-up feat(web): add PostHog events for user creation and Ask GitHub login wall Feb 24, 2026
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between 66f1879 and dc55a27.

📒 Files selected for processing (3)
  • packages/web/src/app/[domain]/askgh/[owner]/[repo]/components/landingPage.tsx
  • packages/web/src/lib/posthog.ts
  • packages/web/src/lib/posthogEvents.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/web/src/lib/posthogEvents.ts

msukkari and others added 2 commits February 24, 2026 15:23
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>
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between 064f9b1 and 532feb5.

📒 Files selected for processing (2)
  • packages/web/src/app/[domain]/askgh/[owner]/[repo]/components/repoIndexedGuard.tsx
  • packages/web/src/lib/posthogEvents.ts

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@msukkari msukkari merged commit cb29189 into main Feb 24, 2026
10 checks passed
@msukkari msukkari deleted the michael/add-user-created-posthog-event branch February 24, 2026 23:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant