Skip to content

feat(analytics): instrument OHE first-install onboarding in PostHog (OHE-3657) - #1103

Merged
hieptl merged 2 commits into
mainfrom
hiep/ohe-3657-posthog-instrument-first-time-user-onboarding-with-posthog
Nov 2, 2026
Merged

hieptl merged 2 commits into
mainfrom
hiep/ohe-3657-posthog-instrument-first-time-user-onboarding-with-posthog

Conversation

@hieptl

@hieptl hieptl commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

HUMAN:

  • A human has tested these changes.

AGENT:


Why

Self-hosted Enterprise (OHE) installs currently send nothing to PostHog, so the product team cannot see whether a Docker Compose evaluator registers, finishes the install wizard, or creates an automation. This adds the server-side events for that funnel and a deliberate switch to turn them on for self-hosted installs. The event table was approved by the product owner in OHE-3854 (https://linear.app/all-hands-ai/issue/OHE-3854/provide-a-table-of-event-names-properties-that-well-track).

Summary

  • user signed up gains is_super_admin and is_instance_setup_user, and self-hosted installs send it as ohe_user_signed_up (Cloud keeps the current name). A new ohe_instance_setup_completed event fires when the first Super Admin finishes the /install wizard and records the company and organization names on the event, the person profile and the org group.
  • Every event carries a new license_key_configured property (from LICENSE_KEY_CONFIGURED, default false), and SaasAppLifespanService keeps analytics off for self-hosted installs unless ENABLE_POSTHOG_ANALYTICS is set, instead of discarding the key unconditionally.
  • Docker Compose turns the switch on and shares POSTHOG_CLIENT_KEY with the automation server (labelled self_hosted); EVENTS.md documents the additions.

Issue Number

OHE-3657: https://linear.app/all-hands-ai/issue/OHE-3657/posthog-instrument-first-time-user-onboarding-with-posthog-events

How to Test

  1. uv run pytest tests/unit/test_analytics_service.py tests/unit/test_saas_lifespan.py tests/unit/server/routes/test_auth_onboarding.py tests/unit/server/routes/test_instance_admin.py. The new tests cover the event and properties, the opt-in switch, the license flag, the TOS flags for the first Super Admin versus a regular user, and the setup-state transition (including not re-reporting a finished wizard).
  2. End to end with the compose stack: put POSTHOG_CLIENT_KEY=<project key> in .env, run docker compose up --wait, open http://localhost:9043, sign up as the first Super Admin, accept the terms, complete /install (company, organization), then create an automation in /canvas. In PostHog the person (user UUID) should show email, company_name and org_name, with events ohe_user_signed_up (is_instance_setup_user: true), ohe_instance_setup_completed (the names) and ohe_automation_created (automation_name, is_first_automation_in_org: true), all with deployment_kind: local.
  3. Opt-out: set ENABLE_POSTHOG_ANALYTICS=false (or an empty key) and confirm the app, worker and automation server make no /capture requests.

I ran step 1 (104 + 123 tests passing) plus ruff, mypy on the changed files and docker compose config. Step 2 still needs the project key (see Notes).

Video/Screenshots

Server-side events only; nothing changes in the UI.

Type

  • Bug fix
  • Feature
  • Refactor
  • Breaking change
  • Docs / chore

Notes

  • Rollout: cloud behavior is unchanged, including event names: only self-hosted installs use the ohe_ names from the approved table, so the SaaS dashboards that key on user signed up and automation_created are unaffected. Helm installs stay off (the switch defaults to off). The compose stack opts in but ships no key; until POSTHOG_CLIENT_KEY is supplied nothing is sent.
  • Companion PRs: OpenHands/automation feat(telemetry): name automations and flag the first one per org (OHE-3657) automation#667 (automation name and first-in-org flag, AUTOMATION_TELEMETRY_DEPLOYMENT_MODE, ohe_automation_created on self-hosted) and OpenHands/docs docs(enterprise): describe Docker Compose telemetry and how to turn it off (OHE-3657) docs#1057 (compose telemetry note). The compose wiring here expects the automation release that includes the override.
  • Open questions before this leaves draft:
    1. is_super_admin as a person property: the existing TOS test pins set_person_properties to {email, signed_up_at}. It can be set through $set on the signup capture instead, or that test can be changed.
    2. Which PostHog project key ("Agent Canvas" project) to ship in docker-compose.yml.

Enterprise server image for this PR:

ghcr.io/openhands/enterprise-server:sha-4086391

…OHE-3657)

Self-hosted Enterprise installs currently send nothing to PostHog, so the
product team cannot see whether a Docker Compose evaluator registers,
finishes the install wizard, or creates an automation. This adds the
server-side events for that funnel and a deliberate switch to turn them
on for self-hosted installs.

- `user signed up` now carries `is_super_admin` and
  `is_instance_setup_user`, computed in `accept_tos` from the user's super
  role and `instance_settings.setup_user_id`, so the first Super Admin's
  registration can be told apart from later signups.
- New `ohe_instance_setup_completed` event, fired when
  `PATCH /api/admin/setup-state` flips `wizard_completed` to true. It
  records `company_name`, `org_name` and `has_company_logo`, sets the same
  company/org names on the person profile, and updates the `org` group
  with `setup_completed_at`.
- New `license_key_configured` common property on every event, read from
  `LICENSE_KEY_CONFIGURED`. It defaults to false because the app has no
  license concept yet.
- `SaasAppLifespanService` keeps analytics off for `self_hosted` unless
  `ENABLE_POSTHOG_ANALYTICS` is set, instead of unconditionally discarding
  the key. Cloud behavior is unchanged.
- Docker Compose turns the switch on and shares `POSTHOG_CLIENT_KEY` with
  the automation server (`AUTOMATION_POSTHOG_API_KEY`), labelled
  `self_hosted`, so automation events join the same funnel. The key itself
  is still supplied by the operator.
- EVENTS.md documents the new event, properties and the switch.

Tests cover the new properties and event, the opt-in switch, the license
flag, the TOS flags for the first Super Admin versus a regular user, and
the setup-state transition (including not re-reporting a finished
wizard).
@github-actions

github-actions Bot commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

Coverage report

Click to see where and how coverage changed

FileStatementsMissingCoverageCoverage
(new stmts)
Lines missing
  openhands/analytics
  __init__.py
  analytics_constants.py
  analytics_service.py
  server/app_lifespan
  saas_app_lifespan_service.py
  server/routes
  auth.py
  instance_admin.py 1083, 1135-1136
Project Total  

This report was generated by python-coverage-comment-action

@hieptl
hieptl marked this pull request as ready for review November 2, 2026 07:58
…-3657)

The product owner asked for every OHE onboarding event to use an
`ohe_`-prefixed snake_case name. `ohe_instance_setup_completed` already
did, but self-hosted sign-ups still went out as `user signed up`.

- `track_user_signed_up` sends `ohe_user_signed_up` when the app runs as
  self-hosted Enterprise (SaaS app mode with `deployment_kind: local`).
  Cloud keeps `user signed up`, so existing SaaS dashboards are
  unaffected. Properties are unchanged.
- EVENTS.md notes the self-hosted name.

@tofarr tofarr left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🍰

@hieptl
hieptl merged commit 44051b5 into main Nov 2, 2026
24 checks passed
@hieptl
hieptl deleted the hiep/ohe-3657-posthog-instrument-first-time-user-onboarding-with-posthog branch November 2, 2026 13:30
@openhands-release-bot openhands-release-bot Bot added the released: 1.83.0 Shipped in 1.83.0 label Nov 2, 2026
@openhands-release-bot

Copy link
Copy Markdown
Contributor

🚀 Released in 1.83.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

released: 1.83.0 Shipped in 1.83.0 type: feat A new feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants