Skip to content

feat(insights): period-aware Tracked Prompts KPI card with plan quota - #471

Merged
gkhngyk merged 1 commit into
mainfrom
feature/tracked-prompts-kpi
Jul 18, 2026
Merged

gkhngyk merged 1 commit into
mainfrom
feature/tracked-prompts-kpi

Conversation

@gkhngyk

@gkhngyk gkhngyk commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

Summary

The Insights KPI row gave no hint of the denominator behind its numbers — how many tracked prompts actually produced the data — and the plan's prompt quota was invisible outside Settings.

This adds a Tracked Prompts card between Visibility Score and Mentions:

  • Period-aware main value: a new tracked_prompt_count RPC (migration 00024, SECURITY INVOKER per the 00014 convention, already applied to the hosted project) counts distinct prompts with results under the same filters as insights_aggregates — date range, model, region, topic, chatgpt-shopping excluded. The card recomputes with the date preset like its neighbors; a static account-state number in a filter-reactive row was explicitly rejected in Insights: period-aware Tracked Prompts KPI card with plan quota and upgrade link #457 (see the issue for the reasoning).
  • Quota sub-line ("181 / 200 prompts"): org-wide usage — the same count enforceLimit writes against — vs the effective limit from getOrgPlan, so Enterprise plan_overrides are respected. Unlimited plans show just the count, no fraction, never an Upgrade link.
  • Upgrade link at ≥90% usage → Settings, with stopPropagation; the card itself navigates to the Prompts page (same pattern as the Citations card).
  • KPI grid becomes grid-cols-2 sm:grid-cols-3 xl:grid-cols-5 for five cards.
  • Fetched inside getInsightsData's server-side Promise.all — no extra client round trip. Verified against production data: the RPC returns 87 distinct prompts for a brand with 13k results in its 30d window.

Related issue

Closes #457

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. Open Insights: a Tracked Prompts card sits between Visibility Score and Mentions, with a tooltip explaining the metric and the org-wide quota.
  2. Switch date presets (24h / 7d / 30d): the main value recomputes with the other cards; the quota sub-line stays constant.
  3. Apply a topic/model/region filter: the main value follows it.
  4. Click the card → Prompts page. At ≥90% quota usage an Upgrade link shows and goes to Settings without triggering the card click.
  5. On an unlimited plan (self-host/enterprise without override): no fraction, no Upgrade link.
  6. The grid renders cleanly at mobile / sm / xl widths.

Checklist

  • Branch follows the naming convention (feature/, fix/, chore/, docs/) — see CONTRIBUTING.md
  • Commits follow Conventional Commits
  • yarn lint passes (run from web/)
  • yarn typecheck passes (run from web/)
  • yarn format:check passes (run from web/)
  • Changes are focused — one concern per PR

The KPI row gave no hint of the denominator behind its numbers — how
many tracked prompts actually produced the data — and the plan's prompt
quota was invisible outside Settings.

Adds a Tracked Prompts card between Visibility Score and Mentions:

- The main value is period-aware: a new tracked_prompt_count RPC
  (migration 00024, SECURITY INVOKER) counts distinct prompts with
  results under the same filters as insights_aggregates, shopping
  excluded — so the card recomputes with the date preset like its
  neighbors instead of sitting as a static account-state number in a
  filter-reactive row.
- The sub-line shows org-wide quota usage (the same count enforceLimit
  writes against) vs the effective limit via getOrgPlan, so Enterprise
  plan_overrides are respected; unlimited plans show just the count.
- At >=90% usage an Upgrade link appears, navigating to Settings with
  stopPropagation; the card itself navigates to the Prompts page,
  mirroring the Citations card pattern.
- KPI grid goes grid-cols-2 / sm:grid-cols-3 / xl:grid-cols-5 for five
  cards.
- Fetched inside getInsightsData's server-side Promise.all — no extra
  client round trip.

Closes #457
@gkhngyk
gkhngyk merged commit 9a5bb6a into main Jul 18, 2026
5 checks passed
@gkhngyk
gkhngyk deleted the feature/tracked-prompts-kpi branch July 18, 2026 13:05
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.

Insights: period-aware Tracked Prompts KPI card with plan quota and upgrade link

1 participant