Skip to content

feat(shopping): show where AI sends shoppers, and flag resellers cheaper than the brand - #1460

Merged
gkhngyk merged 4 commits into
mainfrom
feature/shopping-merchant-split
Oct 24, 2026
Merged

gkhngyk merged 4 commits into
mainfrom
feature/shopping-merchant-split

Conversation

@gkhngyk

@gkhngyk gkhngyk commented Oct 24, 2026

Copy link
Copy Markdown
Contributor

Summary

Parts 2–4 of #1277: where AI sends shoppers for the brand's own products, and resellers cheaper than the brand. Part 1, storing each card's destination, shipped in #1313 (00225).

Stacked on #1459 (the market switch); review that first.

  • Migration 00268_shopping_merchant_split adds two reads over the brand's own-product cards. They use the Overview tab's window and filters, ChatGPT Shopping's market included (p_chatgpt_regions, as shopping_overview has since 00267):
    • shopping_merchant_split counts cards per destination: your store, Amazon, Walmart, eBay, other marketplaces, other resellers. Unclassified cards are counted apart.
    • shopping_own_product_offers returns each merchant's lowest price per listing, title and currency, as one jsonb list (no 1,000-row cap).
    • Both are security definer behind the same membership check as shopping_amazon_share_weekly, with search_path set. anon and public can't execute them.
  • Overview tab:
    • A "Where AI sends shoppers" card: a split bar and legend, with counts and percentages that add up to 100. Unclassified cards are shown apart.
    • A "Resellers cheaper than you" list, with both prices and both links.
    • Both wait for the market like the rest of the Overview. A failed read shows the card empty without breaking the page.
  • The rule (detectResellerPriceAlerts) matches offers by listing id, else by normalized title, within the brand's own products. It flags a reseller or marketplace at 5% or more below the store's lowest price in the same currency.
    • product_brand isn't part of the match. On these cards it often holds the seller's name, so the store and the reseller would never pair.

Prod dry run (rolled back), with 00267 then 00268:

  • Both reads take under 3 ms on the brand with the most cards, over 30 and 90 days, with and without a market.
  • With the same filters, the split's total equals shopping_overview's own cards.
  • A member of another organization gets nothing.

Not here yet: the split on Shelf and in the Products table, and the Readiness row. Those views don't exist yet.

Related issue

Closes #1277

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 Shopping › Overview for a brand with own-product cards. "Where AI sends shoppers" shows the split, with unclassified cards as a separate line.
  2. Change the date, platform and region filters, and the market. The split follows them, and its total matches the Overview's own cards.
  3. With a store and a reseller card for the same product, the reseller at 5% or more below the store in the same currency, the product is listed with both prices. Its links open in a new tab.
  4. Check light and dark mode. Plans without shopping analytics still see only the upgrade card.

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

🤖 Generated with Claude Code

…h its source per market (#1278)

- lib/shopping/markets: one country-to-market helper. US and US state
  codes map to the US; EU / EEA countries, the UK and Switzerland to
  Europe; anything else to none. Also the default market and each
  market's region codes.
- getBrandMarketCountries reads the brand's domain countries and every
  prompt's location codes (paged past the 1,000-row cap).
- The Shopping page opens on the US when the brand has US countries and
  on Europe when all of them are European. With no market it shows no
  switch and makes no source claim. The choice is remembered per brand
  in localStorage.
- The switch shows where ChatGPT's products come from in each market and
  keeps ChatGPT Shopping cards to that market's regions in the card
  reads. Other platforms' cards are unaffected. A picked region already
  narrows every platform, so the switch then follows that region, and
  choosing a market clears the region.
…arket (#1278)

- 00267 adds p_chatgpt_regions to shopping_overview. It narrows ChatGPT
  Shopping's results and cards only; null (the default) reads exactly
  what the function did before. The 6-argument version is dropped so
  PostgREST sees one candidate, and its grants are restored. Apply the
  migration before deploying the web.
- loadShoppingOverview passes the market's regions only while the market
  filter applies (All regions picked), the same rule as the card reads.
  Reports call without it and are unchanged.

Behaviour kept from the switch:
- A brand opens on Europe only when every country is European; DE + TR
  gets no market, no switch and no claim.
- Both markets are offered once a brand has one.
- While a market applies, ChatGPT cards from other countries show only
  through the region filter.
- The switch shows with shopping mode off, paused prompts count as the
  brand's countries, brands.region is not read, and a ChatGPT card with
  no region is left out under a market.
…per than the brand (#1277)

Migration 00268 adds two reads over the brand's own-product cards, in the
Overview tab's window and filters, ChatGPT Shopping's market included
(p_chatgpt_regions, as shopping_overview has since 00267):
- shopping_merchant_split counts the cards per destination (your store,
  Amazon, Walmart, eBay, other marketplaces, other resellers) and the
  unclassified ones apart.
- shopping_own_product_offers returns each merchant's lowest price per
  listing, title and currency as one jsonb list.
Both are security definer behind the same membership check as
shopping_amazon_share_weekly; anon and public can't execute them.

The Overview tab gets a "Where AI sends shoppers" card (split bar and
legend with counts and percentages that add up to 100) and a "Resellers
cheaper than you" list with both prices and both links. Both wait for the
market like the rest of the Overview. The rule lives in
detectResellerPriceAlerts: offers match by listing id or normalized title,
and a reseller is flagged at 5% or more below the store's lowest price in
the same currency.
@gkhngyk gkhngyk added enhancement New feature or request e-commerce Shopping, product catalog, store and marketplace connectors labels Oct 24, 2026
@github-actions github-actions Bot added the needs-migration Adds or edits a migration — apply it to the hosted database label Oct 24, 2026
@gkhngyk
gkhngyk merged commit 703ef00 into main Oct 24, 2026
5 of 6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

e-commerce Shopping, product catalog, store and marketplace connectors enhancement New feature or request 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.

feat(shopping): show where AI sends shoppers, and flag resellers cheaper than the brand

1 participant