Skip to content

Track workflow search context#972

Open
benceruleanlu wants to merge 2 commits into
mainfrom
bl/gtm-139-workflow-search-telemetry
Open

Track workflow search context#972
benceruleanlu wants to merge 2 commits into
mainfrom
bl/gtm-139-workflow-search-telemetry

Conversation

@benceruleanlu

@benceruleanlu benceruleanlu commented Jun 26, 2026

Copy link
Copy Markdown
Member

Summary:

  • Enrich hub:search_performed with result_count, surface, and filters_applied.
  • Keep telemetry on the existing 200ms debounced search path.
  • Watch derived filter values so in-place badge additions rerun scoped search telemetry.
  • Add unit coverage for payload shape and zero-result searches.

Tests:

  • pnpm run test -- tests/unit/posthog.test.ts
  • pnpm run check
  • pnpm exec eslint src/lib/posthog.ts tests/unit/posthog.test.ts --max-warnings 0
  • pnpm exec prettier --check src/lib/posthog.ts src/components/hub/SearchPopover.vue tests/unit/posthog.test.ts
  • git diff --check

Notes:

  • Full pnpm run lint and pnpm run format:check still fail on unrelated pre-existing files in the fresh clone.

Fixes GTM-139

@coderabbitai

coderabbitai Bot commented Jun 26, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Search badge changes now recompute a normalized type:value filter list, drive the debounced search watcher, and send structured search-performed events with query, result count, and applied filters. PostHog typing and unit tests were updated for the new payload.

Changes

Search tracking update

Layer / File(s) Summary
Filter sync and debounced trigger
site/src/components/hub/SearchPopover.vue
activeFilters normalizes badge values into type:value strings, and the debounced watcher now reacts to that computed list.
Structured search event payload
site/src/components/hub/SearchPopover.vue, site/src/lib/posthog.ts
SearchPopover now passes the query, result count, and applied filters to trackSearchPerformed; the helper accepts the structured payload and emits hub:search_performed with query, result_count, surface, and filters_applied.
Tracking unit tests
site/tests/unit/posthog.test.ts
The Vitest suite mocks PostHog and checks normal, zero-result, and whitespace-only search tracking behavior.

Sequence Diagram(s)

sequenceDiagram
  participant SearchPopover
  participant trackSearchPerformed
  participant posthog as posthog-js
  SearchPopover->>trackSearchPerformed: query, resultCount, filtersApplied
  trackSearchPerformed->>posthog: capture hub:search_performed
Loading
🚥 Pre-merge checks | ✅ 2
✅ Passed checks (2 passed)
Check name Status Explanation
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.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch bl/gtm-139-workflow-search-telemetry
✨ Simplify code
  • Create PR with simplified code
  • Commit simplified code in branch bl/gtm-139-workflow-search-telemetry

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@github-actions

Copy link
Copy Markdown
Contributor

🧹 Lint & Format Results

Check Status
ESLint ✅ success
Prettier ✅ success

Generated by Site CI workflow

@github-actions

Copy link
Copy Markdown
Contributor

🔍 SEO Audit Results

Check Status
Sitemap Validation ✅ passed
SEO Audit ✅ passed
Internal Links ❓ skipped
📊 SEO Audit Details

Could not parse SEO output

🔗 Link Check Details

broken internal links out of checked


Generated by Site CI workflow

@benceruleanlu benceruleanlu force-pushed the bl/gtm-139-workflow-search-telemetry branch 4 times, most recently from adf6ec1 to 45abb64 Compare June 26, 2026 01:16
@benceruleanlu benceruleanlu force-pushed the bl/gtm-139-workflow-search-telemetry branch from 45abb64 to 919dcf3 Compare June 26, 2026 01:29
@benceruleanlu benceruleanlu marked this pull request as ready for review June 26, 2026 01:29

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@site/src/components/hub/SearchPopover.vue`:
- Around line 201-212: The search completion handling in SearchPopover is
vulnerable to stale async results overriding newer queries. Add a per-request
token/snapshot around the search flow in the search handler that calls
searchIndex, and before assigning searchResults or calling trackSearchPerformed,
verify the response still matches the latest request. Use the existing search
state in SearchPopover to ignore older completions so only the newest
query/filter combination updates results and result_count.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 91935dd2-cdda-4088-83ff-b3e261c62fe0

📥 Commits

Reviewing files that changed from the base of the PR and between 32a4ddf and 6014410.

📒 Files selected for processing (3)
  • site/src/components/hub/SearchPopover.vue
  • site/src/lib/posthog.ts
  • site/tests/unit/posthog.test.ts

Comment on lines +201 to +212
const filtersApplied = [...activeFilters.value];
try {
searchResults.value = await searchIndex(trimmed, {
const results = await searchIndex(trimmed, {
allowedNames: badgeFilteredNames.value ?? undefined,
});
trackSearchPerformed(trimmed);
searchResults.value = results;
const resultCount = results.workflows.length + matchedCreators.value.length;
trackSearchPerformed({
query: trimmed,
resultCount,
filtersApplied,
});

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

Guard against stale search completions.

Line 207 reads matchedCreators.value.length after await searchIndex(...), and this block also writes searchResults.value after the await. If an older debounced search resolves after a newer one, the popover can show stale workflows and the emitted result_count can belong to the wrong query/filter set — old results win the race and muddy the trace. Capture a request token/snapshot and ignore stale completions before assigning or tracking.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@site/src/components/hub/SearchPopover.vue` around lines 201 - 212, The search
completion handling in SearchPopover is vulnerable to stale async results
overriding newer queries. Add a per-request token/snapshot around the search
flow in the search handler that calls searchIndex, and before assigning
searchResults or calling trackSearchPerformed, verify the response still matches
the latest request. Use the existing search state in SearchPopover to ignore
older completions so only the newest query/filter combination updates results
and result_count.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 60144103ae

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

});
trackSearchPerformed(trimmed);
searchResults.value = results;
const resultCount = results.workflows.length + matchedCreators.value.length;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Count creators from the searched query

When the first search is still loading /workflows/search-index.json (or any search resolves slowly) and the user edits or clears the query before it resolves, matchedCreators.value has already recomputed from the current searchQuery, not the trimmed query being reported. That sends hub:search_performed with workflow results for one query plus a creator count for another, so the new result_count telemetry is inaccurate for common fast-typing/clear-search flows; capture the creator count for trimmed before the await or derive it from the same search results.

Useful? React with 👍 / 👎.

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.

2 participants