Repository navigation
feat(shopping): give each product a page with where it shows and why AI picked another one (Product Visibility, part 6) - #1641
Merged
gkhngyk merged 38 commits intoOct 28, 2026
Conversation
…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]>
…ts, orders and readiness (product visibility, part 4) The Products tab (ECOM-007) lists the brand's catalog when it has one. Each product shows: - its photo, category and price; - the AI shelves it was on, its win rate (#1 or #2) and average place over the filter window, from its matched cards (00360); - the AI visits its page got; - the orders those visits led to, and their revenue; - its readiness out of 100. Visits and orders come from catalog_product_ai_stats (00361). No source carries order line items yet (Shopify order sync, ansvisor#1267), so an order is credited to the product whose page the AI visitor landed on first (ai_traffic_events.first_url). A product's page is its link, else its first variant's, matched by path. Members of the brand's organization only. Readiness adds up what the catalog can tell: - a GTIN (20); - a photo (15); - in stock (15); - a price (10); - a description of 25 words or more (15); - what the product is, in its first 40 words (10, ECOM-024); - a category (10); - a brand (5). Its tip says what's missing and what each costs. Views: All, Never shown, Shown not clicked, Clicked not bought, and Top sellers from AI, each with its count. The table reads up to 2,000 products and says so past that. A brand with no catalog, or one that can't be read, keeps the products AI showed by title, with a line on connecting the catalog. Prices format in one place (lib/shopping/price.ts). Co-Authored-By: Claude Opus 5.5 <[email protected]>
… on it, top rival and AI revenue (product visibility, part 5) The Categories tab (ECOM-008, between Shelf and Products) lists each category of the brand's catalog that has live products, with: - its shopping questions: a question is the category's when the category's own name is in it (its last level, plural or not: "Hiking backpacks" in "lightweight 30L hiking backpack for women"), or when one of its products was on the question's shelf (00360); - the brand's share of the product slots on those shelves, with a bar; - its products on a shelf, of its products; - the rival with the most slots there: the competitor a card is matched to, else the card's brand, with its favicon; - its products' AI revenue in their main currency (00361). A category with three questions or more where the brand holds under 10% of the slots is marked "needs attention", tinted amber. The tab reads when it opens, once per brand and filters, and shows its count. It also says when the catalog has no categories, or when they can't be read. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…AI picked another one (product visibility, part 6) Each product in the Products table now opens its own page, /dashboard/shopping/products/[id] (ECOM-011, the mockup's product detail). Header: its photo, price, category, "On N of M shelves", its readiness, and "View product page". Below it, its AI clicks, AI orders and AI revenue over 30 days (00361). "Why not your product?": for the most relevant question whose shelf it isn't on (else the one it ranks lowest on), it stands beside the product AI put first, row by row: - match with the question: both BM25 scores (ansvisor#1487's), over its title and its description's first 40 words, with the missing words; - price: close, or how much higher or lower; - rating and reviews, as the answers showed them; - what it is, in its first 40 words; - GTIN, photo and stock in the feed; - who sells each. Each row is marked ✓ matches, ✕ missing, ↓ weaker, or — just what each has. Rows we have no data for (delivery, returns, schema) are left out rather than guessed. "Where it shows": the questions it belongs on (its category's name in them, the shelves it was on, or a match of 40 or more), each channel's latest shelf, its place, its match and the missing words. Then its readiness, check by check. The view is its own component (_product-detail.tsx). Reading the catalog's products is shared with the Products table. The plan's locked note now says what Growth unlocks here. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ibility-shell Co-Authored-By: Claude Opus 5.5 <[email protected]>
…visibility-matching 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]>
…ct-visibility-shelf Co-Authored-By: Claude Opus 5.5 <[email protected]>
…visibility-products Co-Authored-By: Claude Opus 5.5 <[email protected]>
…'s active products first (00361) catalog_product_ai_stats returned a row for every live product, so a catalog past 1000 products lost the rest to PostgREST's max_rows, and the Products table read at most the first 2000 products by id, with every variant of the catalog. - 00361 returns only the products with an AI visit or an order, and takes p_product_id for one product's row. The table reads it a page at a time (readAllRpcRows, by product_id). - Past 2000 products, the table lists those on a shelf or visited from AI first (orders, then shelves, then visits), then the rest by id. Their rows, variants, photos and categories are read for those ids, 100 at a time; a catalog of 2000 or fewer is read by the brand, as before. - All and Never shown count the whole catalog (the server's count), not the rows read; the note says which products the table holds. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…f apart from the rest Each filter change read the whole Products table with the page's other reads, and the Shelf's rows waited for all of them. - useKeyedRead: a read made once per brand and filters while it's wanted, an older answer dropped. The Shelf reads with it on its own; the Products table only while its tab is open, as Categories does. - The no-catalog view says what main's CatalogNote says (with its link to Settings), not a second line of its own: products.noCatalog goes. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ct-visibility-categories Co-Authored-By: Claude Opus 5.5 <[email protected]>
The Categories table read catalog_product_ai_stats in one request, so a catalog with more than 1000 products with AI visits or orders lost the rest of its revenue to PostgREST's max_rows. It reads the pages now, as the Products table does (readProductAiStats). Co-Authored-By: Claude Opus 5.5 <[email protected]>
…duct-visibility-detail Co-Authored-By: Claude Opus 5.5 <[email protected]>
The product's page read every product's AI visits and orders to find its own, and lost it past the first 1000 rows. It asks catalog_product_ai_stats for its product only (p_product_id, 00361), and reads its catalog rows by its id. Co-Authored-By: Claude Opus 5.5 <[email protected]>
… beside its icon
The comparison's ✓, ✕, ↓ and – icons are hidden from screen readers, so
the state they draw wasn't read at all. Each row now says it after its
name ("Price, in place"; "GTIN in the feed, missing"), for a screen reader
only.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
7 of 12 tasks
# Conflicts: # server/src/server.js # supabase/schema.sql
# Conflicts: # web/src/config/platform-labels.ts
# Conflicts: # web/src/lib/dashboard-navigation.test.ts
…y-matching # Conflicts: # supabase/schema.sql
…y-products # Conflicts: # supabase/schema.sql
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.
… table Each category added up its questions' cards by walking every card in the window again; a big catalog's categories, each in most questions, took seconds. The cards are now counted once per question (slots, the brand's, each rival's), and a category adds up its questions. The rows are the same.
gkhngyk
approved these changes
Oct 28, 2026
gkhngyk
left a comment
Contributor
There was a problem hiding this comment.
Looks good, with follow-ups.
What I checked:
- Own change. a0d4b78 against part 5's head (82f6bd2): the product page (
products/[productId]/page.tsx,_product-detail.tsx),product-detail.ts,getShoppingProductDetailinactions/shopping.ts, the Products table's link to it, and 55 keys inen.json. No migration in this part; it uses part 4'scatalog_product_ai_stats(00361) with itsp_product_id, which part 5's head already has. On today's main the only conflicts come from parts 1–5 (server.js,platform-labels.ts,dashboard-navigation.test.ts,schema.sql); this part's own files merge cleanly. - Whose product. Both ids are checked as guids before any read. The product is read through
readCatalogProductswith the brand filter andremoved_at is null, under the caller's session, so a product of another brand, another organization or one removed from the catalog comes back as "This product isn't in your catalog anymore." The visits and orders come from 00361's own organization check, for that one product only. - The page. The shelves are each question's latest run per channel. A question is listed when the product was on it, when the question names the product's category, or when its match is 40 or more, at most 20, most relevant first. "Why not your product?" explains the most relevant shelf it's missing, else the one it ranks lowest on. Each comparison row says its state in words for a screen reader, beside its icon.
- Plan. The page shows the locked message without
shopping_analytics, like the rest of Product Visibility. The reads are the same kind the Products tab already makes for the brand. - Tests. On this tree, the PR's 4 test files pass (14 tests), and all of Shopping's web tests pass (23 files, 130 tests).
tscis clean; eslint and prettier are clean on the touched files.
Follow-ups (none block):
- The whole window's cards for one product.
getShoppingProductDetailreads every card of the brand in the last 30 days, with each card's question and searches (up to 50,000 rows), to find the shelves of one product. That's fine for today's brands. For a big one, reading only the cards of the questions the product could be on (its own cards' questions, plus those of its category) would be much lighter. - The page's window is fixed at 30 days. The Products table it opens from follows the page's date, channel and region filters; this page doesn't. Either pass the filters along in the link, or say "Last 30 days" on the page (the AI tiles already say "· 30d").
- A price row with no winner.
comparisonadds the price row whenwinner?.price !== null, which is also true when there's no winner (undefined !== null). It can't show today, since the table only renders with a winner, butwinner?.price != nullsays what's meant.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Product Visibility, part 6 of 14: a page for each product (ECOM-011, the mockup's PRODUCT DETAIL). Where the product shows, and why AI picked another one.
Stacked on #1640. This PR's own change is its commits after #1640's: ebfc1e8, 747b2e4, a0d4b78.
Where you see it:
/dashboard/shopping/products/[id].Header:
Why not your product? It takes the most relevant question whose shelf the product isn't on (else the one it ranks lowest on), and sets it beside the product AI put first, row by row:
Each row is marked ✓ in place, ✕ missing, ↓ weaker, or – for comparison. The mockup's rows we have no data for (delivery, returns, schema) are left out rather than guessed.
Where it shows:
Then its readiness, check by check.
Also:
Fixed in the pre-push review:
catalog_product_ai_statsfor its product only (p_product_id), and reads its catalog rows by its id.Related issue
No issue: ECOM-011 in Drive › E-commerce › ECOM-spec.md. The screens' tasks were only in epic #1190, closed as not planned. It uses #1282's match score (#1487) for the winner's score and the missing words; it doesn't close #1282.
Type of change
feat— New featurefix— Bug fixchore— Maintenance / dependenciesdocs— Documentation onlyrefactor— Code change that neither fixes a bug nor adds a featuretest— Adding or updating testsHow to test
cd web && yarn vitest run src/lib/shopping/product-detail.test.ts src/lib/actions/shopping-product-detail.test.ts "src/app/[locale]/(dashboard)/dashboard/shopping/products"Checklist
feature/,fix/,chore/,docs/) — see CONTRIBUTING.mdyarn lintpasses (run fromweb/)yarn typecheckpasses (run fromweb/)yarn format:checkpasses (run fromweb/)Checks:
server/npm test(3,383 tests),web/vitest(4,451 tests) andyarn build.yarn typecheck, and the tests, eslint and prettier of the files it changes.For you, @gkhngyk:
search_queries: heavy for a big brand.🤖 Generated with Claude Code