Skip to content

feat(shopping): sidebar entry + Shopping overview page - #144

Merged
gkhngyk merged 1 commit into
mainfrom
feat/shopping-overview-page
Jun 2, 2026
Merged

gkhngyk merged 1 commit into
mainfrom
feat/shopping-overview-page

Conversation

@gkhngyk

@gkhngyk gkhngyk commented Jun 1, 2026

Copy link
Copy Markdown
Contributor

Closes #104. First user-visible surface for the shopping-cards normalization that landed in #103.

What

Page contents

Filter bar — date preset (7d / 30d / 90d / all) + platform + region. Dropdowns are populated from getShoppingFilterOptions so they only list values that appear in this brand's data.

KPIs (4 cards):

  • Shopping card rate — prompts with ≥1 card / total prompts in the window.
  • Your products surfaced — count of matched_brand_role = 'own' cards.
  • Shopping share of voice — own / all cards in card-bearing prompts.
  • Top merchant — most frequent merchant_domain where role is own.

Charts:

  • Bar chart of card rate by platform.
  • 30-day line of own cards vs all cards.

Empty state when no cards exist yet — friendly explainer pointing at commercial-intent prompts.

Plan gating

  • Free / Starter: only the Shopping card rate KPI is unlocked. The other three KPI tiles render with a 🔒 and the two charts collapse to a Growth upgrade card.
  • Growth / Enterprise / self-hosted: full access.

Implemented via the existing useFeatureGate hook with the new shopping_analytics flag.

Data path

Server actions aggregate in JS because the row count is small. The card-rate denominator hits prompt_results directly (need to know about cards-free prompts too); the other metrics aggregate over the normalized prompt_result_shopping_cards table. Date filters route through expandDateToEndOfDay so today's data lands on the right side of the upper bound.

Org isolation is enforced at the DB layer — RLS on prompt_result_shopping_cards already restricts to the caller's organization; the action just filters by brand_id.

Test plan

  1. Sign in as Growth+ user → /dashboard/shopping renders all 4 KPI cards + both charts. With no cards in the DB yet, the empty state appears instead.
  2. Sign in as Starter → first KPI tile visible, other three locked, charts replaced by upgrade card.
  3. Run tracking against a commerce-intent prompt (Perplexity / AI Mode / Copilot) → cards populate; refresh → KPIs reflect.
  4. Region / platform / date filters change the result set as expected.

Out of scope

Closes #104.

Adds the first user-visible surface for the shopping-cards normalization
that landed in #103. Sidebar gets a 'Shopping' entry under Citations,
new route at /dashboard/shopping with:

- Top filter bar: date preset (7d/30d/90d/all) + platform + region,
  dropdowns populated from the brand's actual data (no values that
  don't appear get listed).
- Four KPI cards: shopping card rate, your products surfaced (`role=own`
  count), shopping share of voice (own / all cards in card-bearing
  prompts), top merchant by own-card frequency.
- Bar chart of card rate by platform.
- 30-day line chart of own cards vs all cards over time.
- Empty state for brands with zero shopping data.

New `shopping_analytics` feature flag in config/plans.ts. Free / Starter
see only the first KPI; the other three plus both charts gate to
Growth+ with an upgrade card. Self-host stays unrestricted.

Server actions live in web/src/lib/actions/shopping.ts and aggregate
in-process — the row counts the dashboard hits are small enough that
JS aggregation is cheaper than another RPC. Date-range filters route
through expandDateToEndOfDay so today's data lands on the right side
of the bound.

Also regenerates supabase types so prompt_result_shopping_cards is
known to the query builder (was missing after #103).
@gkhngyk
gkhngyk merged commit fbe52e2 into main Jun 2, 2026
3 checks passed

This branch was successfully deployed

1 active deployment
Preview — 050e069b Deployed Jun 1, 2026 by vercel[bot]
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.

feat(shopping): sidebar entry + Shopping overview page

1 participant