Skip to content

fix(analytics): identify PostHog users server-side on signup and onboarding#3179

Open
rafavalls wants to merge 5 commits intomainfrom
rafavalls/debug-chat-failures
Open

fix(analytics): identify PostHog users server-side on signup and onboarding#3179
rafavalls wants to merge 5 commits intomainfrom
rafavalls/debug-chat-failures

Conversation

@rafavalls
Copy link
Copy Markdown
Collaborator

@rafavalls rafavalls commented Apr 24, 2026

What is this contribution about?

PostHog was not receiving user name/email for server-side events because posthog.identify() was never called server-side. Users appeared as unrecognized IDs (e.g. VWPJPnX0DXgPDMIo5J6CBNTbLOPI6XVS) instead of their actual name/email in PostHog dashboards.

Two fixes:

  • Added posthog.identify() in the user.create database hook so every new user gets their name + email linked to their PostHog profile at the moment of signup
  • Added name to the existing posthog.identify() call in the /domain-setup onboarding route, which only had email before

Screenshots/Demonstration

N/A — analytics-only change, no UI impact.

How to Test

  1. Sign up a new user
  2. In PostHog, find the person by their user ID — they should now show with name and email instead of a raw ID
  3. Expected outcome: person profile displays email and name properties

Review Checklist

  • PR title is clear and descriptive
  • Changes are tested and working
  • Documentation is updated (if needed)
  • No breaking changes

Summary by cubic

Identify PostHog users on signup, onboarding, and every stream run, and group-identify organizations for accurate attribution. Automation-triggered chats/tools are attributed to automation personas, with richer event context and no duplicate cancel events.

  • Bug Fixes

    • Call posthog.identify() in the user.create hook and add name to the /domain-setup identify payload.
    • Refresh user/org profiles each run with posthog.identify() and posthog.groupIdentify() to self-heal legacy data.
    • Skip server chat_message_stopped on user cancel to prevent duplicates; emit chat_message_aborted only for non-user aborts.
  • New Features

    • Attribute automation chats/tools to automation_<id> and posthog.identify() the automation (name, owner user, org). Add richer event context (trigger_id, is_automation, automation_id/name, user_id, user_agent, virtual_mcp_name, abort_reason) and broaden credit/quota error detection.

Written for commit e8983b7. Summary will update on new commits. Review in cubic

…arding

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@github-actions
Copy link
Copy Markdown
Contributor

🧪 Benchmark

Should we run the Virtual MCP strategy benchmark for this PR?

React with 👍 to run the benchmark.

Reaction Action
👍 Run quick benchmark (10 & 128 tools)

Benchmark will run on the next push after you react.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 24, 2026

Release Options

Suggested: Patch (2.281.5) — based on fix: prefix

React with an emoji to override the release type:

Reaction Type Next Version
👍 Prerelease 2.281.4-alpha.2
🎉 Patch 2.281.5
❤️ Minor 2.282.0
🚀 Major 3.0.0

Current version: 2.281.4-alpha.1

Note: If multiple reactions exist, the smallest bump wins. If no reactions, the suggested bump is used (default: patch).

rafavalls and others added 3 commits April 25, 2026 09:56
…ostHog

Use `automation_<id>` as PostHog distinctId for chat and tool events
triggered by automations, so they show up under the automation persona
instead of the owner user. Also propagates automation metadata
(id, name, trigger_id, user_agent) to all captured events and fixes
abort event naming to distinguish user-cancelled from server-aborted runs.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
… self-heal

Add posthog.identify() for the user and posthog.groupIdentify() for the
organization on every streamCore run. This refreshes the person/group
profile each session so legacy users and orgs that predate the
signup/creation hooks get backfilled automatically.

Also drop the redundant `organization_name` / `organization_slug` event
properties — PostHog resolves them via the organization group. Carry
`virtual_mcp_name` on chat/tool events since virtual MCPs are not a
PostHog group type.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Frontend already emits chat_message_stopped when the user clicks the
stop button (apps/mesh/src/web/components/chat/input.tsx). The server
side was firing the same event for abortReason="cancelled", producing
two events per user cancel. Now we skip the server event for user
cancels and only fire chat_message_aborted for genuine non-user aborts
(tab close, registry race, force-fail, reaped, ghost).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@rafavalls rafavalls changed the title fix(analytics): identify PostHog users server-side on signup and onboarding fix(analytics): improve PostHog attribution for automations and fix missing user profiles Apr 25, 2026
@rafavalls rafavalls changed the title fix(analytics): improve PostHog attribution for automations and fix missing user profiles fix(analytics): identify PostHog users server-side on signup and onboarding Apr 28, 2026
Accept main's refactored createMemory (lookup-only, no thread creation)
and drop the extra fields passed from stream-core that are no longer needed.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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