Skip to content

Link members' app use to their account in product analytics - #396

Merged
tnkuehne merged 2 commits into
app-user-activityfrom
app-user-alias
Nov 25, 2026
Merged

tnkuehne merged 2 commits into
app-user-activityfrom
app-user-alias

Conversation

@tnkuehne

@tnkuehne tnkuehne commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

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.

RetriggerView in GreptileConfidence Score: 5/5

The PR appears safe to merge; both previous findings are fixed.

Summary

Links members' app identities to their control-plane account in product analytics.

  • App activity now joins the member’s account in product analytics.

Diagram

%%{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]
Loading

Reviews (2) · Last reviewed commit: "Forward app identity links on Cloudflare..." · Reviewed by Greptile

A member who also uses apps appeared twice: as user:<id> from the
control plane and as app-user:<hash> from app sign-in.

On sign-in, the control plane now aliases the person's app identities
to their account: the identity apps issue when they sign in through
Widefleet, and the company identity of each organization whose company
sign-in the person has an account with. Company identities come from
the person's accounts, so the first company sign-in links its identity
even though the membership is added afterwards. The runtime and the
control plane derive the analytics ID with the same contract function.
@tnkuehne
tnkuehne added this pull request to stack #397 November 25, 2026 14:27
The Cloudflare request observer did not forward alias, so hosted
sign-ins never linked app identities. Linking now reads the identities
lazily, so installations without analytics run no extra queries at
sign-in.
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Updated (UTC)
✅ Deployment successful!
View logs
widefleet-docs 31b229a Nov 25 2026, 02:34 PM

@tnkuehne
tnkuehne merged commit e1c8ed2 into main Nov 25, 2026
16 of 17 checks passed
@tnkuehne
tnkuehne deleted the app-user-alias branch November 25, 2026 14:55
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