Skip to content

fix(analytics): make persons searchable by username in PostHog#2221

Merged
Hugo0 merged 1 commit into
devfrom
fix/posthog-person-name-searchable
Jun 12, 2026
Merged

fix(analytics): make persons searchable by username in PostHog#2221
Hugo0 merged 1 commit into
devfrom
fix/posthog-person-name-searchable

Conversation

@Hugo0

@Hugo0 Hugo0 commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

Why

Konrad couldn't find any user by username in PostHog's Persons page. Root cause: PostHog's persons free-text search is hardcoded (PersonStrategy.filter_conditions) to match only properties.email, properties.name, person UUID, and distinct_id. We only set username on identify — and 0 of 2,658 persons have email/name — so search-by-username never worked for anyone. (Usernames display in the list because the display-name config includes username; display and search are separate code paths, which is the trap.)

What

Duplicate username into name in the posthog.identify $set payload. name ranks before username in PostHog's display-name defaults and carries the same value, so nothing visibly changes — but the search box now matches.

Backfill

Existing persons were backfilled (1,830 $set events via mono/ops/scripts/posthog/backfill-person-name.mjs), so this isn't waiting on user logins. Re-running the script is a no-op for already-backfilled persons; worth one re-run after this reaches prod to catch persons created in between.

Testing

  • npm test: 72/72 suites green
  • npm run typecheck: no hits on changed file
  • prettier: clean

@vercel

vercel Bot commented Jun 12, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
peanut-wallet Ready Ready Preview, Comment Jun 12, 2026 3:26pm

Request Review

@coderabbitai

coderabbitai Bot commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: d3402c5b-2f90-4c75-b9fa-af652efedf17

📥 Commits

Reviewing files that changed from the base of the PR and between 3ab1534 and a320071.

📒 Files selected for processing (1)
  • src/context/authContext.tsx

Walkthrough

PostHog's identify call within AuthProvider is extended to include a name property alongside the existing username field. The documentation comment describing PostHog's searchable properties is updated to reflect the enriched payload.

Changes

PostHog Analytics Enrichment

Layer / File(s) Summary
PostHog identify enrichment
src/context/authContext.tsx
PostHog identification payload extended to include user name field; documentation comment updated to reflect searchable fields.

🎯 1 (Trivial) | ⏱️ ~5 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The PR title matches the primary analytics change in the commit messages and PR objectives (making persons searchable by username in PostHog via the identify call), but the changeset also includes a significant capability-gate ordering fix affecting three files. The title addresses only one of two commits.
Description check ✅ Passed The PR description provides comprehensive context about the analytics change (PostHog searchability issue, the solution of duplicating username to name, and backfill strategy) and aligns with the objectives. It explains the why, what, and testing approach related to the described changes.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

ESLint install timed out. The project may have too many dependencies for the sandbox.


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

PostHog's Persons-page free-text search is hardcoded server-side to
properties.email / properties.name / person id / distinct_id — it never
reads username, so no Peanut user was findable by username (0 of 2,658
persons have email or name set). Duplicate username into name on
identify so the search box works. Existing persons were backfilled via
ops/scripts/posthog/backfill-person-name.mjs (mono).
@Hugo0 Hugo0 force-pushed the fix/posthog-person-name-searchable branch from 87e2cf0 to a320071 Compare June 12, 2026 15:21
@github-actions

Copy link
Copy Markdown
Contributor

Code-analysis diff

Painscore total: 5808.95 → 5809.11 (+0.16)
Findings: 0 net (+6 new, -6 resolved)

🆕 New findings (6)

  • medium high-mdd — src/context/authContext.tsx:62 — AuthProvider: MDD 76.4 (uses across many lines from declarations)
  • medium complexity — src/context/authContext.tsx — CC 25, MI 55.95, SLOC 182
  • medium hotspot — src/context/authContext.tsx — 24 commits, +212/-163 lines since 6 months ago
  • medium high-mdd — src/context/authContext.tsx:185 — : MDD 22.0 (uses across many lines from declarations)
  • low high-dlt — src/context/authContext.tsx:185 — : DLT 21 (calls 21 distinct functions — high context load)
  • low high-mdd — src/context/authContext.tsx:119 — addAccount: MDD 16.0 (uses across many lines from declarations)

✅ Resolved (6)

  • src/context/authContext.tsx:62 — AuthProvider: MDD 75.4 (uses across many lines from declarations)
  • src/context/authContext.tsx — CC 25, MI 56.05, SLOC 181
  • src/context/authContext.tsx — 23 commits, +208/-162 lines since 6 months ago
  • src/context/authContext.tsx:182 — : MDD 22.0 (uses across many lines from declarations)
  • src/context/authContext.tsx:182 — : DLT 21 (calls 21 distinct functions — high context load)
  • src/context/authContext.tsx:116 — addAccount: MDD 16.0 (uses across many lines from declarations)

@github-actions

Copy link
Copy Markdown
Contributor

🧪 UI test report — ✅ all green

Suites

  • unit: 1429 ran, 0 failed, 0 skipped, 20.6s

📊 Coverage (unit)

metric %
statements 51.4%
branches 33.6%
functions 39.3%
lines 51.4%
⏱ 10 slowest test cases
time test
0.4s src/app/actions/__tests__/api-headers-extended.test.ts › should not include apiKey in updateUserById body
0.3s src/app/actions/__tests__/api-headers.test.ts › should include Content-Type in updateUserById
0.3s src/components/Card/share-asset/__tests__/shareAssetLayout.test.ts › every stamp stays within canvas at any count
0.1s src/components/Global/GeneralRecipientInput/__tests__/GeneralRecipientInput.test.tsx › should handle valid 9-digit US account
0.1s src/components/Global/GeneralRecipientInput/__tests__/GeneralRecipientInput.test.tsx › should handle unresolvable ENS name
0.1s src/components/Global/GeneralRecipientInput/__tests__/GeneralRecipientInput.test.tsx › should handle valid UK IBAN with spaces
0.1s src/components/Global/GeneralRecipientInput/__tests__/GeneralRecipientInput.test.tsx › should handle minimum length (6 digits) US account
0.1s src/components/Global/GeneralRecipientInput/__tests__/GeneralRecipientInput.test.tsx › should handle valid US account with spaces
0.1s src/components/Global/GeneralRecipientInput/__tests__/GeneralRecipientInput.test.tsx › should handle invalid ETH address (missing 0x prefix)
0.1s src/components/Global/GeneralRecipientInput/__tests__/GeneralRecipientInput.test.tsx › should handle too long for US account
📍 Inline annotations are in the **Unit test report** check above. Coverage artifact: `coverage-unit`. Generated by `.github/workflows/tests.yml`.

@Hugo0 Hugo0 merged commit 76f43ed into dev Jun 12, 2026
16 of 20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant