Skip to content

feat(prompts): show average position and trend in the Positions column - #1017

Merged
gkhngyk merged 4 commits into
ansvisor:mainfrom
cihan-gyk:feature/prompts-position-trend
Oct 15, 2026
Merged

gkhngyk merged 4 commits into
ansvisor:mainfrom
cihan-gyk:feature/prompts-position-trend

Conversation

@cihan-gyk

@cihan-gyk cihan-gyk commented Oct 13, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

PROMPT-007. The Tracked Prompts table's Positions column now tells you where the brand stands without opening the panel:

  • Average position (e.g. #2.9): the mean mention position over answers that mention the brand, on the platforms the plan includes. It is the same number the Positions panel shows; checked in the browser.

  • Trend arrow: the change against the previous period of the same length, ending where the selected range starts.

    • 7d compares with the 7 days before.
    • A custom 1–10 Oct range compares with 21–30 Sep.
    • A green ↑ means the brand moved up, a red ↓ means it moved down.
    • With no change, or no data in the previous period, there is no arrow.

    The panel has no period comparison, so this is the only place the trend shows.

  • Hover breakdown: hovering the value lists each platform's state and average, e.g. "ChatGPT: named further down (chore(seo): block search indexing on the app subdomain #3.0)".

  • Detail button: the See button is now a compact chart icon ("See positions" on hover) right next to the value, so the cell fits under its header. It opens the same panel.

  • Sortable: the first click sorts ascending, so fix(tracking): keep job active until webhook results drain #1 is on top. Prompts without a position go last.

  • "Late or missing" quick filter: shows only prompts named late, or not mentioned, on at least one platform.

Empty states:

Case Cell
Mentioned #3.7 + arrow (if changed) + chart button
Cited only, never mentioned — + chart button (the panel shows citation ranks)
Neither, or no runs in the range —

Long values (e.g. #28.5 ↑12.5) fit the fixed-width slot without touching the button; checked at 1024px.

Data

New migration 00123_prompt_position_summaries.sql adds the RPC prompt_position_summaries(brand, from, to, region):

  • It is a single GROUP BY returning per-prompt, per-platform sums and counts, not averages, so platforms combine exactly.
  • It is SECURITY INVOKER, so RLS applies.
  • Like the other analytical surfaces, it excludes chatgpt-shopping and respects the location filter.

getPromptsPageData calls it for the current and previous windows inside its existing Promise.all, so the page still loads in one round trip. The cell is computed by the pure helper web/src/lib/prompt-position-summary.ts, which has tests. supabase/schema.sql is regenerated.

Related issue

PROMPT-007 (internal product task)

Type of change

  • feat — New feature
  • fix — Bug fix
  • chore — Maintenance / dependencies
  • docs — Documentation only
  • refactor — Code change that neither fixes a bug nor adds a feature
  • test — Adding or updating tests

How to test

  1. Apply the migration and open Prompts → Tracked Prompts with a 30d range.
    • The demo seed stores no mention_position, so to see values, temporarily set mention_position and mentioned_entity_count on some demo prompt_results.
  2. The Positions column shows #x.x, plus a trend arrow when the previous period differs. Hover the value for the per-platform breakdown.
  3. Click the chart button: the panel's "Avg. position" and each platform's Avg. match the table.
  4. Click the Positions header: rows sort fix(tracking): keep job active until webhook results drain #1 first. Click it again to reverse.
  5. Toggle Late or missing: only prompts late or missing on a platform remain. The button shows as filled while it is on.
  6. Switch between 7d / 30d / 90d / Custom: the value and arrow recompute for each range.
  7. Check in dark mode and at 1024px width.

Checklist

  • Branch follows the naming convention (feature/, fix/, chore/, docs/) — see CONTRIBUTING.md
  • Commits follow Conventional Commits
  • yarn lint passes (run from web/): 0 errors; the 7 warnings are in files this PR doesn't touch
  • yarn typecheck passes (run from web/)
  • yarn format:check passes (run from web/)
  • Changes are focused — one concern per PR

Also run:

  • yarn test: 473/473 passed
  • yarn build: passed
  • npm run version:check: passed
  • bash supabase/build-schema.sh: run, and the regenerated schema.sql is included

🤖 Generated with Claude Code

…Positions column

Adds a prompt_position_summaries RPC (per-prompt, per-platform position sums)
and uses it for the current and previous period. The Positions column now
shows the average mention position (matching the Positions panel), its
change against the previous period of the same length, and one dot per
plan-included platform. The column is sortable and a "Late or missing"
quick filter narrows the table to prompts that need work.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@github-actions github-actions Bot added the needs-migration Adds or edits a migration — apply it to the hosted database label Oct 13, 2026
Drop the per-platform dots in favour of a hover breakdown on the value,
turn See into a compact chart icon button, and give the value a fixed
width so the trend never pushes the button and the cell sits under its
header.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@cihan-gyk cihan-gyk changed the title feat(prompts): show average position, trend and platform dots in the Positions column feat(prompts): show average position and trend in the Positions column Oct 13, 2026
@cihan-gyk

Copy link
Copy Markdown
Collaborator Author

@gkhngyk PROMPT-007 is ready for review: the Positions column now shows the average position (same number as the Positions panel) with a trend arrow against the previous period of the same length, is sortable, and has a "Late or missing" quick filter. Hover the value for a per-platform breakdown. Note: the demo seed has no mention_position, so see "How to test" for seeding a few values. Checked in light/dark and at 1024px.

@gkhngyk gkhngyk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks, the column is useful, and the query holds up. On our largest brand (about 218k results in 180 days), the function took about 2.7 s for a 90-day window as an authenticated user, under the 8 s limit. Three things before merge:

  1. A failure here takes down the whole Prompts page. getPositionRows is awaited inside getPromptsPageData's Promise.all without a catch. A timeout, or the web deploying before 00123 is applied, fails the whole table. Degrade like volumes and the location quota do: catch and return empty positions, so the column shows —.
  2. "Missing" should match the Improve tab. #1011 now treats a platform where the brand appears in fewer than half the runs as not mentioned (MIN_MENTION_RATE). Here missing means never mentioned, so a platform at #1 in 8 of 120 answers reads as early. The "Late or missing" filter then skips a prompt that the Improve tab calls not mentioned on the same platform. Please apply the same rule in dotState.
  3. Merge main in. The chart button calls setPositionsFor, which #1010 replaced with openPositionsPanel(p.id). getPromptsPageData now also loads the location quota (#1009). Then re-run build-schema.sh.

Smaller: for the current window, this scans the same rows as prompt_visibility_summaries. Folding the position sums into that function later would save one scan.

cihan-gyk and others added 2 commits October 15, 2026 20:26
…ition-trend

# Conflicts:
#	supabase/schema.sql
#	web/src/app/[locale]/(dashboard)/dashboard/prompts/page.tsx
#	web/src/lib/actions/prompt.ts
…entioned platforms as missing

- getPromptsPageData catches a failed position query like volumes and the
  location quota: the Positions column shows — instead of failing the table.
- A platform where the brand appears in fewer than half the runs is missing,
  as on the Improve tab (MIN_MENTION_RATE, mirrored from the server), so
  "Late or missing" includes it. Its hover shows the mention rate instead of
  its average position.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@cihan-gyk

Copy link
Copy Markdown
Collaborator Author

Thanks for the review! All three points are addressed:

  1. The page no longer fails when the position query does. getPositionRows is now caught in getPromptsPageData, the same way volumes and the location quota are. If it fails, it logs the error and returns empty rows, so every Positions cell shows — and the rest of the table still loads. New getPromptsPageData tests in actions/prompt.test.ts check that a timed-out RPC still returns the prompts with empty cells.
  2. "Missing" now matches the Improve tab. dotState treats a platform where the brand appears in fewer than MIN_MENTION_RATE (0.5) of the runs as missing, so "Late or missing" now includes those prompts. The constant is mirrored in web/src/lib/prompt-improve.ts, with a keep-in-sync note on both sides, as visibility-score does. Hovering such a platform shows "not mentioned · mentioned in 8 of 120 runs", as the Improve tab does, instead of its fix(tracking): keep job active until webhook results drain #1 average. The cell's average is unchanged, so it still matches the Positions panel. Tests cover fix(tracking): keep job active until webhook results drain #1 in 8 of 120 runs (missing) and exactly half the runs (still mentioned).
  3. main is merged (098bedd). The chart button calls openPositionsPanel(p.id), and getPromptsPageData loads the location quota. build-schema.sh leaves schema.sql unchanged.

On the smaller note: agreed. Folding the position sums into prompt_visibility_summaries would save a scan, so I'll do that in a separate follow-up PR.

FYI, unrelated to this PR: npm run version:check fails on main itself, because the docker-compose images are still tagged 0.2.0 while the packages are at 0.3.0.

@gkhngyk gkhngyk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks, all three addressed. Migration 00123 is applied to production.

@gkhngyk
gkhngyk merged commit 78886c7 into ansvisor:main Oct 15, 2026
5 checks passed
gkhngyk pushed a commit that referenced this pull request Oct 16, 2026
… behind first (#1098)

Clicking "Late or missing" on Tracked Prompts seemed to do nothing. It
filtered, but nearly every prompt with answers is late or missing on at
least one platform (on production, 202 of the 202 answered in 24h), and the
list kept its order, so the first page stayed the same and only the row
count at the bottom changed.

The definition stays (#1017). The button now says how many prompts it
leaves ("Late or missing · 202", after search and work status), and while
it is on the list starts with the prompts furthest behind:
- late or missing on the most platforms;
- then missing on more of them;
- then the worse average position, a prompt never ranked counting as
  furthest back;
- then the more visible.

A column picked before is set aside and comes back when the filter is
turned off, unless a header is clicked in between; a header click starts
at its usual direction. The order is announced in a screen-reader caption,
and the button's text moves to en.json.

Co-authored-by: Cihan <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-migration Adds or edits a migration — apply it to the hosted database

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants