Skip to content

feat(shopping): show the AI shelf for each shopping question, with the brand's place and its sales from AI (Product Visibility, part 3) - #1638

Merged
gkhngyk merged 17 commits into
ansvisor:mainfrom
cihan-gyk:feature/product-visibility-shelf
Oct 28, 2026
Merged

gkhngyk merged 17 commits into
ansvisor:mainfrom
cihan-gyk:feature/product-visibility-shelf

Conversation

@cihan-gyk

Copy link
Copy Markdown
Collaborator

Summary

Product Visibility, part 3 of 14: the Shelf, the page's overview now (ECOM-006, the mockup's SHELF). For each shopping question it shows the products AI put on the shelf, in order, and where the brand stands.

Stacked on #1637. This PR's own change is its commits after #1637's: 2de7f7f.

Where you see it: Product Visibility › Shelf, the first tab (/dashboard/shopping). On Growth, Enterprise and self-hosted; other plans see the upgrade card.

Four numbers:

  • AI shelf share: the brand's share of the product slots in AI answers.
  • Products on the shelf: its catalog products shown (00360), "41 of 320"; without a catalog, distinct titles.
  • AI revenue · 30d: orders from AI visits and their value, against the 30 days before.
    • From the tracking snippet and the Shopify pixel (ai_traffic_events).
    • Without a source, Connect to see sales links to AI Traffic.
  • Top AI channel: by AI orders, else by the brand's slots.

Below them:

The Shelf reads on its own: when it fails, it says so and the other tabs still work. ChatGPT Shopping gets its name in the platform labels.

Removed on purpose (B13). The Shelf replaces three things:

  • the Card-eligible prompts tab: its table, search, appearances drawer and CSV export;
  • the KPI grid above the tabs: shopping card rate, trigger rate, your products surfaced, shopping share of voice, top merchant;
  • the 22 en.json keys they used.

Why:

  • In the spec and the mockup, the Shelf replaces the Overview. The tabs are Shelf · Categories · Products · Readiness; there's no prompts tab.
  • Each card-eligible prompt is now a Shelf row, with the shelf itself.
  • The grid gives way to the mockup's four numbers.

What stays: the card rate by platform, under Trends. Reports still show the shopping card presence (getShoppingKpis).

Who notices:

  • Starter saw the shopping card rate in that grid. It now sees the upgrade card on every tab. On the cloud its menu item is locked, so only a direct link reached the page.
  • The CSV export has no replacement here.

Related issue

No issue: ECOM-006 in Drive › E-commerce › ECOM-spec.md. The screens' tasks were only in epic #1190, closed as not planned.

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. cd web && yarn vitest run src/lib/shopping/shelf.test.ts src/lib/actions/shopping-shelf.test.ts "src/app/[locale]/(dashboard)/dashboard/shopping/_shelf.test.tsx"
  2. With 00360 applied, open Product Visibility › Shelf for a brand with shopping answers:
    • the four numbers, then Where AI sends shoppers, then a row per question and channel;
    • a channel chip filters the rows and the page; a price band narrows them;
    • the Prompts tab is gone.

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

Checks:

  • At the top of the chain (part 14): server/ npm test (3,383 tests), web/ vitest (4,451 tests) and yarn build.
  • At this branch's tip: yarn typecheck, and the tests, eslint and prettier of the files it changes.

For you, @gkhngyk:

  • Product decision: the removals above. If the CSV or the card-eligible list should stay, it can come back in its own PR.
  • Follow-ups (not here):
    • getCardEligiblePrompts (web/src/lib/actions/shopping.ts) is no longer called: remove it, or bring the tab back.
    • B14: after a failed Shelf read, the numbers and rows stay skeletons under its message, with no retry. After a brand or filter change, the AI revenue number shows the previous read until the new one comes.
    • B25: the price bands ("Under $50") don't look at the currency, and a cut-off KPI value has no tooltip.

🤖 Generated with Claude Code

cihan-gyk and others added 8 commits October 27, 2026 18:33
…popup and the Shelf and Products tabs (product visibility, part 1)

The first step to the Products screens in Drive › E-commerce (ECOM-spec,
ECOM-mockup): the page says what it's for, "Which of your products AI
recommends, why, and what it sells.", with "Why Ansvisor Product
Visibility?" beside the title. That opens the four steps from the AI
shelf to the sale, and offers Connect Google Analytics while GA isn't
connected (ECOM-010).

Under the title, the data sources (ECOM-009), as on AI Traffic:
- the product catalog (its products and last sync, Manage, or Connect);
- Google Analytics and Search Console, each with what it adds here;
- a Marketplaces & feeds row: Merchant Center connects as a catalog
  source, and the marketplaces show Soon until they have a connector.

The tabs read Shelf, Prompts, Products and Competitors, the one open in
the URL (?tab=products). The sidebar item is new. AI Traffic's Google
source card is shared, with an optional line for while it isn't
connected.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…oduct it shows (product visibility, part 2)

Product Visibility's Shelf, Products and Categories (ECOM-005…008)
count a brand's products on the AI shelf, so each product card that is
the brand's own now records which catalog product it shows
(prompt_result_shopping_cards.catalog_product_id, and catalog_match for
how it was found; 00360).

lib/catalog/card-match.js matches in order:
- by the marketplace listing a card links (ASIN, eBay item id), to a
  variant's marketplace_item_id;
- by a GTIN the card carries, without its padding;
- by its link, to a product's or variant's page, with or without its
  query;
- else by its title: at least 0.6 of the words in common (Dice) and
  0.1 clear of the next product, the brand's name and filler words
  aside.

A key two products share matches neither.

Cards are matched as they're written, against the brand's catalog read
at most every 10 minutes. If the catalog can't be read, the cards go in
without matches. If the API runs before 00360, they go in without the
new columns rather than not at all.

After the daily catalog sweep, each brand whose catalog synced in the
last day has its own cards of the last 90 days matched again. Only the
matches that changed are written, 500 a call, through
set_shopping_card_matches (service role only).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…e brand's place and its sales from AI (product visibility, part 3)

The Shelf tab (ECOM-006, Drive › E-commerce › ECOM-mockup) is
Product Visibility's overview now.

Four numbers:
- AI shelf share: the brand's share of the product slots in AI
  answers;
- Products on the shelf: its catalog products shown (00360), "41 of
  320", else distinct titles;
- AI revenue · 30d: orders from AI visits and their value against the
  30 days before, from the tracking snippet and the Shopify pixel
  (ai_traffic_events). Without a source, "Connect to see sales" links
  to AI Traffic;
- Top AI channel: by AI orders, else by the brand's slots.

Then where AI sends shoppers and resellers cheaper than the brand, as
before. Then one row per shopping question and channel: its latest
shelf in order, with photos, prices, ratings and merchant icons. The
brand's products are ringed ("2 · You", "via Amazon"), and each row
says "You: #2 · 1 of 2 shelves this week" or "You're not on this
shelf". The shelves the brand isn't on come first.

Filters:
- channel chips, which set the page's platform filter;
- a price band, from the shelf's middle price.

The platform card rate and trend charts stay below, under Trends.

The old KPI row and the Card-eligible prompts tab give way to the
Shelf. The Shelf reads on its own, so a failure there leaves the other
tabs working and says so. ChatGPT Shopping gets its name in the
platform labels.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…a product's delete (00360)

`on delete set null` looks up a deleted catalog product's cards by the
product alone, which the (brand_id, catalog_product_id) index can't serve:
each delete would scan the cards. A partial index on catalog_product_id
covers it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…loop, and read every GTIN key in the sweep

A 50,000-product catalog took about 90 s to match 20,000 cards, in one
synchronous run. Now about 1 s, the longest hold under 70 ms:

- A word in more than 5% of the titles (and more than 500) finds no
  products to compare; it still counts in a title's score. A title of
  common words only is found by its rarest one. A product not compared
  can't come within the margin of the best: when one could (it would share
  only the card's common words), no title match is made. So every title
  match is one the full comparison makes too; a few it made are not.
  A catalog of 500 titles or fewer is matched exactly as before.
- matchCards matches 500 cards at a time, with a turn of the event loop
  between (the bot-log parser's nextTurn).
- The kept catalogs are capped at 200,000 products in all, not 50 brands;
  the brand read least recently goes first, and a read keeps a brand.
- The daily sweep reads a card's GTIN under gtin, gtin13, gtin12, gtin14,
  ean and upc, as matching at write time does, not under gtin alone.

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 28, 2026
@cihan-gyk

Copy link
Copy Markdown
Collaborator Author

Merged main forward (8356ba3) through the stack; no new conflicts on this branch. Typecheck and lint pass on the chain tip.

…ing cards to the catalog

A card's link has its trailing slashes cut by a walk back rather than an
end-anchored regex, and a title match reads a card title's first 40 words
(MAX_CARD_TITLE_WORDS): each word more was compared with every product it
found.

@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.

Looks good, with follow-ups. Nothing in this part's own diff blocks. The branch merges in part 2's fix, so the stack carries it; nothing else changes here.

What I checked:

  • Own change. a460878..3579d87: 2de7f7f plus the merge of part 2.
  • Merge on today's main. It needs a merge of main. web/src/config/platform-labels.ts conflicts: main renamed google-aio to "Google AI Overviews", and this adds chatgpt-shopping. Keep main's label and add the new line. Parts 1–2's conflicts (dashboard-navigation.test.ts, server/src/server.js, supabase/schema.sql) carry up.
  • Shelf. It reads the window's cards through the existing cardsInWindow/fetchAllCards (50,000-row cap) with the user's client, so RLS keeps it to the person's organization. It groups by question and channel, takes the newest answer's cards in position order, and counts the week's shelves. Rows the brand isn't on come first. Distinct products count catalog products when 00360 matched any, and titles otherwise, and the KPI says which. The catalog count is a head-only count.
  • Orders. getShoppingAiOrders reads ai_traffic_events (members can select, 00286) for order conversions over 60 days and splits them 30/30. Revenue is in the month's main currency. It only reads for full-access plans.
  • Tests. On the PR's tree, tsc is clean, and the shopping tests (16 files, 103 tests) pass, including shelf.test.ts, shopping-shelf.test.ts and _shelf.test.tsx. Prettier and eslint are clean.
  • Deploy. The Shelf selects catalog_product_id, so apply 00360 before merging. Without it the Shelf shows its "Couldn't read" note and the other tabs still work.

Follow-ups (none block):

  1. When the Shelf read fails, ShelfKpis and ShelfRows get null and show skeletons forever under the alert. Give them the failed state, so the alert stands alone or replaces them.
  2. getShoppingAiOrders filters on kind, goal and occurred_at, but the only brand index on ai_traffic_events is (brand_id, visitor_id, occurred_at). A brand with many page events scans them all for each of up to 50 sequential pages. A partial index on (brand_id, occurred_at desc) where kind = 'conversion' and goal = 'order', or one RPC that returns the totals, would make it a single cheap read.
  3. The price filter puts each shelf in a band by its middle price, whatever the currency, as if it were dollars. Either compare within the shelf's main currency or show the bands in it.
  4. As with the existing Shopping actions, the plan check (shopping_analytics) is only in the UI. The new actions only read the person's own organization's data (RLS), but a server-side check would match the page's gating.

@gkhngyk
gkhngyk merged commit 93f221d into ansvisor:main Oct 28, 2026
4 of 5 checks passed
@github-actions github-actions Bot removed the needs-migration Adds or edits a migration — apply it to the hosted database label Oct 28, 2026
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