Skip to content

feat(prompts): Query Fan-out tab — observed engine sub-queries with times-searched + one-click track #333

Closed

Description

@gkhngyk

Summary

Add a Query Fan-out tab to the prompts page (/dashboard/prompts), between Prompts and Insights, that surfaces the observed query fan-out — the sub-queries AI answer engines actually ran (from #332) — and lets the user promote any of them into a tracked prompt in one click.

Placement is a tab on the existing prompts page (not a new left-nav item): fan-out is conceptually a lens on prompts.

Depends on

#332 (captures prompt_results.search_queries as [{ query, engine?, source_platform }]). This issue is read-only over that data + a small intent classifier + the existing prompt-add flow. No schema change is needed for the Sourced prompts column below — prompt_results.search_queries already lives on a row that carries prompt_id, so the originating prompt is inherently linked.

Core principle — observed only

The fan-out list is 100% what the engines returned — we never generate/predict sub-queries. The only derived layer is an intent tag (see below), clearly a label on top of observed text.

What the tab shows (v1)

A prompt-filtered, brand-wide table of the observed fan-out for the selected window:

Sub-query (observed) Engine / source Times searched Sourced prompts Intent Action
"best running shoes 2026" Copilot 34 "running shoes for flat feet" +2 best-top + / Tracked ✓
  • Times searched = across the window and all engines/runs, how many tracked answers issued this sub-query (count distinct answers whose search_queries contains it). This is the default sort and our observed "demand" signal — we deliberately do not use Google Ads volume (these are long-tail natural-language queries that return ~0; the engines' own search frequency is the on-topic signal).
  • Engine / source chip = which engine(s) surfaced it. Copilot is the primary source; Perplexity secondary (web queries); ChatGPT is usually empty — the chip makes this transparent.
  • Sourced prompts = the distinct tracked prompts of yours whose answers ran this sub-query. A single fan-out sub-query commonly surfaces across several of your prompts, so this shows its origin — which prompt(s) the engine fanned out from. Users will want to see the prompts a fan-out was shown under. Derived from the same aggregation (prompt_results.prompt_id → prompt text); render as the first prompt's text + a +N overflow, with a popover/expander listing all of them, each linking to its prompt (e.g. /dashboard/prompts/[id] or the Insights prompt view). No extra query shape — it falls straight out of the read aggregation.
  • Intent = the same 7-value taxonomy as the Insights "intent" column (comparison, how-to, what-is, best-top, vs-review, recommendation, problem-solving), via a new lightweight classifyPromptIntent(text) — see below.
  • Action = a + to track this sub-query as a prompt (the loop: observed fan-out → track → measure its own visibility). If a prompt with that text already exists, show Tracked ✓ linking to it (dedup — mirror the "add as competitor" + pattern on the citations Domains table).

Intent classification

  • Add classifyPromptIntent(text) to server/src/lib/intent-extraction.js: shares the same intent enum as intentKeywordSchema (one taxonomy, no drift with the Insights column) but does not extract keywords and does no volume work — intent only, a cheaper call.
  • Applied to distinct sub-query strings, deduped + cached (many answers repeat the same sub-query → classify each unique string once), on-demand (not per tracking ingest) to control LLM cost.
  • Nothing here touches volume / DataForSEO.

The "+" (promote to tracked prompt)

  • Reuse the existing prompt-add path (savePromptSet / the prompt creation used by the Insights Suggestions card + prompt_suggestions).
  • Enforce the plan's prompt limit (maxPrompts via the existing enforceLimit guard) — promoting spends daily Cloro + LLM budget.
  • After adding, the sub-query is a normal tracked prompt and gets its own visibility/mention/citation over time (cleaner per-query attribution than the answer-level fan-out).

Explicit non-goals (v1)

  • No Google Ads volume / competition for the sub-queries (dropped — long-tail, ~0; Times searched replaces it).
  • No competitor / citation coverage on the fan-out.
  • No answer-level "were we cited on this sub-query" co-occurrence badge (the fan-out array carries no per-sub-query citations; the real signal comes only after promoting via +).
  • No LLM-generated fan-out — observed only.

Files to touch

  • server/src/lib/intent-extraction.js — add classifyPromptIntent(text) (shared enum, intent-only).
  • A read action (e.g. web/src/lib/actions/tracking.ts or a new fanout.ts) — aggregate prompt_results.search_queries into distinct sub-queries with times_searched, engines, per-string intent (cached), and the set of sourced prompts (distinct prompt_id + prompt text) each sub-query came from; mark which sub-queries already exist as prompts.
  • web/src/app/[locale]/(dashboard)/dashboard/prompts/page.tsx — new Query Fan-out tab between Prompts and Insights; the table (incl. the Sourced prompts column with links to the origin prompts) + +/Tracked action; reuse the existing prompt-add + maxPrompts guard.

How to test

  1. Brand with tracked prompts and a few Copilot/Perplexity runs (so search_queries is populated) → Prompts → Query Fan-out: a list of observed sub-queries with Times searched, engine chips, intent, and the Sourced prompts they came from, sorted by most-searched.
  2. A sub-query that surfaced under multiple of your prompts shows all of them in Sourced prompts (first + +N, expandable), each linking to that prompt.
  3. A sub-query already tracked as a prompt shows Tracked ✓ (not +); a new one shows +.
  4. Click + → the sub-query is added as a tracked prompt (respects maxPrompts); the row flips to Tracked ✓.
  5. ChatGPT-only brands show a sparse/empty fan-out (transparent via engine chips) — no crash.
  6. No Google volume / DataForSEO call fires from this tab.

Notes

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions