Repository navigation
Count people who use apps in product analytics - #395
Merged
Merged
Conversation
App users sign in through the organization's company sign-in and never open the control plane, so product analytics had no record of them. The app runtime now reports an app_user_active event when a person signs in to an app, when an expired app session is renewed, when a host token starts an embedded session and when an MCP token is issued or refreshed. Sessions renew with the identity provider's token lifetime, so active people produce one event per renewal rather than one per request. The person is identified by a hash of the provider's issuer and subject, with name and email as person properties, and grouped by organization. Renewals name the app that triggered them. Events are sent only when the runtime has a PostHog project token, as for MCP analytics. Delivery runs in the background and failures never affect sign-in or app requests.
Deploying with
|
| Status | Name | Latest Commit | Updated (UTC) |
|---|---|---|---|
| ✅ Deployment successful! View logs |
widefleet-docs | e1db561 | Nov 25 2026, 02:13 PM |
tnkuehne
added a commit
that referenced
this pull request
Nov 25, 2026
## Problem With #395, a member who also uses apps appears as two people in product analytics: `user:<id>` from the control plane and `app-user:<hash>` from app sign-in. ## Change - `appUserDistinctId` in `@platform/contracts` derives the app user ID from issuer and subject. The runtime and the control plane use it, so both produce the same ID. - On every control-plane sign-in, the server sends `$create_alias` from `user:<id>` for each of the person's app identities: - the identity apps issue when they sign in through Widefleet (`<PLATFORM_URL>/api/auth`, user ID) - the company identity of each organization whose company sign-in the person has an account with, as `createAppUserIdentity` already derives it, including Entra's object ID - Company identities come from the person's company accounts, not memberships. Company sign-in adds the membership after the session, so the first company sign-in would otherwise link nothing. - Linking is awaited in the session hook so it is captured before the request's analytics drain. Failures never affect sign-in. App use before a person's next control-plane sign-in merges into their account when the alias arrives. ## Verification - `pnpm check` - App identity integration test: the first company sign-in links the Widefleet identity and the company identity, and the linked ID equals the one derived from the identity app sign-in issues - Server analytics test: the alias is delivered as `$create_alias` with `distinct_id: user:<id>` - Not verified against PostHog itself yet: whether a person already created by `app_user_active` events merges into the account. That needs a separate test project. Stacked on #395. <!-- greptile_comment --> <!-- greptile_summary --> <h2><a href="https://app.greptile.com/api/retrigger?id=119518203&sig=3c7b76ee994909a694ac18759cf6b7d78e8047ef758f26757b4eb04d02d2c896"><picture><source media="(prefers-color-scheme: dark)" srcset="https://greptile-static-assets.s3.amazonaws.com/badges/RetriggerDark.svg?v=2"><source media="(prefers-color-scheme: light)" srcset="https://greptile-static-assets.s3.amazonaws.com/badges/Retrigger.svg?v=2"><img alt="Retrigger" src="https://greptile-static-assets.s3.amazonaws.com/badges/Retrigger.svg?v=2" align="right"></picture></a><a href="https://app.greptile.com/-/switch-tenant?tenant=mendra&next=%2Fwidefleet%2Fwidefleet%2Fpull%2F396&utm_source=greptile_review&utm_medium=github&utm_campaign=view_in_greptile"><picture><source media="(prefers-color-scheme: dark)" srcset="https://greptile-static-assets.s3.amazonaws.com/badges/ViewInGreptileDark.svg?v=2"><source media="(prefers-color-scheme: light)" srcset="https://greptile-static-assets.s3.amazonaws.com/badges/ViewInGreptile.svg?v=2"><img alt="View in Greptile" src="https://greptile-static-assets.s3.amazonaws.com/badges/ViewInGreptile.svg?v=2" align="right"></picture></a>Confidence Score: 5/5</h2> <!-- greptile-impact-verdict --> The PR appears safe to merge; both previous findings are fixed. <details open><summary><h3>Summary</h3></summary> Links members' app identities to their control-plane account in product analytics. - App activity now joins the member’s account in product analytics. </details> <details open><summary><h3>Diagram</h3></summary> ```mermaid %%{init: {'theme': 'neutral'}}%% flowchart TD A[Control-plane sign-in] --> B[Await observer alias] B --> C{Analytics enabled?} C -->|No| D[Skip identity lookups] C -->|Yes| E[Read app identity IDs] E --> F[Queue aliases for user account] F --> G[Drain analytics after request] ``` </details> <!-- greptile_confidence_score:5 --> <sub>Reviews (2) · Last reviewed commit: ["Forward app identity links on Cloudflare..."](31b229a) · [Reviewed by Greptile](https://www.greptile.com/?utm_source=greptile_review&utm_medium=github&utm_campaign=review_public&utm_content=widefleet/widefleet)</sub> <!-- /greptile_comment -->
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.
Problem
People who use an app sign in through the organization's company sign-in and never open the control plane. Product analytics only identified control-plane visitors, so app users were not counted at all. App MCP analytics is attributed to the organization, not to a person.
Change
The app runtime reports
app_user_activeat the points where a person proves their identity, not on every request:sign_inrenewalapp_idembedded_sign_inmcp_sign_in/mcp_renewalBrowser sessions renew with the identity provider's token lifetime and MCP access tokens last at most five minutes, so an active person produces one event per renewal. PostHog then counts unique people per day or week directly.
distinct_idisapp-user:plus a SHA-256 of the provider's issuer and subject, the same for browser and MCP use. Name and email are person properties, and the organization is the group.createAuthProxyaccepts an optionalobservecallback andcreateAuthHandleradds the organization and app. The auth proxy stays independent of analytics. Observer failures never change responses.POSTHOG_PROJECT_TOKEN, as for MCP analytics, and delivery runs in the background.Verification
pnpm check

Confidence Score: 5/5
This PR appears safe to merge.Summary
Adds
app_user_activeevents when people sign in or renew their identity through browser, embedded, and MCP flows.No actionable issues found. Reviewed source and test coverage; tests were not run.
Diagram
%%{init: {'theme': 'neutral'}}%% flowchart TD B[Browser sign-in or renewal] --> P[Auth proxy observer] E[Embedded sign-in] --> P P --> H[Add organization and optional app] H --> A[appUserAnalytics] M[MCP token issuance or refresh] --> A A --> C{PostHog token configured?} C -->|No| S[Skip analytics] C -->|Yes| I[Hash issuer and account ID] I --> D[Send event in background]Reviews (1) · Last reviewed commit: "Count people who use apps in product ana..." · Reviewed by Greptile