Skip to content

feat(shopping): say from Search Console whether Google shows the brand's products in its shopping results - #1751

Merged
gkhngyk merged 12 commits into
ansvisor:mainfrom
cihan-gyk:feature/gsc-shopping-appearance
Oct 29, 2026
Merged

gkhngyk merged 12 commits into
ansvisor:mainfrom
cihan-gyk:feature/gsc-shopping-appearance

Conversation

@cihan-gyk

Copy link
Copy Markdown
Collaborator

Summary

Product Visibility's Readiness had no way to tell whether Google lists a shop's products when Merchant Center can't be connected, which is the case on the cloud today. Search Console can tell, from the brand's own property: the pages Google shows as merchant listings (the free shopping listings) and as product snippets.

Server: the daily GSC sync reads them.

  • Search appearance can't be a column beside the page, so the read takes the two steps the API needs:
    1. the property's appearance types over 28 days;
    2. for each shopping type, its [page, date] rows, filtered to that type.
  • Types are matched by name, so MERCHANT_LISTINGS and "Merchant listings" both count.
  • A filtered read whose impressions are higher than its type's total is treated as unfiltered and dropped. It is never kept as "every page shown".
  • Rows go to the new gsc_shopping_page_stats (00377, readable by the brand's members). Rows for another property are dropped first, and 90 days are kept. brands.gsc_shopping_synced_at records that the read ran.

Web: a new Readiness item.

  • "Google shows your products in shopping results (Search Console)" counts the catalog's product pages (matched by the feed's pageKey) that were shown in the last 28 days:
    • half or more: pass;
    • some: warn;
    • none: fail, with what to check (product schema: price, availability, GTIN).
  • Without Search Console, before its first read, or when it couldn't be read, the item is unknown and not scored.
  • The MCP readiness (get_shopping_readiness) reads the same.

Related issue

Follows #1270. Merchant Center isn't offered on the cloud; this is the Search Console fallback.

Stacked on #1747 (don't ask for Merchant Center where it isn't offered). The diff against #1747 holds only this change.

Type of change

  • feat — New feature

How to test

  1. Apply 00377 and deploy the server, then the web.
  2. On a brand with Search Console connected and a catalog, run the GSC sync (or wait for the daily run). gsc_shopping_page_stats gets rows only if the property has merchant listings or product snippets, and brands.gsc_shopping_synced_at is set either way.
  3. Product Visibility › Readiness: the new item, with its count of product pages shown.
  4. Without Search Console, the item reads as unknown and the score doesn't change.

For the maintainer (live property): please check two things that can't be tried without a real property:

  • the types that step 1 returns (that merchant listings / product snippets come back under the names we match);
  • that Composio applies dimension_filter_groups as sent ({ groupType, filters: [{ dimension, operator, expression }] }). If it ignores the filter, the impression check drops the read instead of storing every page.

Checklist

  • Branch follows the naming convention
  • Commits follow Conventional Commits
  • bash supabase/build-schema.sh: schema.sql is current
  • Server: format, lint, and 281 test files / 3,916 tests (3 skipped) pass
  • Web: format, lint (0 errors, 7 warnings), typecheck, 564 test files / 5,364 tests and build pass
  • Tests added (gsc-sync-shopping.test.js, shopping-search-appearance.test.ts, readiness.test.ts, MCP)
  • Live Search Console property check: the maintainer's

🤖 Generated with Claude Code

cihan-gyk and others added 8 commits October 28, 2026 23:16
For an AI assistant working on a shop's catalog (MCP plan B6a):

- get_catalog_sources (REST GET /api/mcp/catalog/sources): where the
  catalog is read from (feeds, uploads, connected stores) and how each
  last sync went, with its products in the catalog now.
- list_catalog_products (REST GET /api/mcp/catalog/products): the live
  products, by title, as Product Visibility reads them, each with its
  readiness for AI shopping, its Google Merchant Center issues by
  severity and the AI visits and orders its page brought over 30 days;
  `search`, and paged with `limit` and `offset`.

Product Visibility's catalog reads (readCatalogProducts and its paged
readers) and Settings' source read (readCatalogSources) move to
lib/shopping/catalog-read.ts and take the client: the member's session
on the pages, the service role for the MCP once the brand is the key's.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
# Conflicts:
#	docs/guides/mcp-server.mdx
#	web/src/lib/mcp/server.ts
#	web/src/lib/mcp/subscription-gate.test.ts
…wer past its end

- Read the page's variants and their issues 100 ids and 1,000 rows a
  request, so a page past PostgREST's row cap keeps every issue.
- Count each issue (code and attribute) once per product, however many
  variants and destinations it is on, and only for a Merchant Center
  account whose last sync went through (hasMerchantCenter, now shared
  with the editor's shopping check from lib/shopping/catalog-read).
- Answer an empty page for an offset past the matches, which PostgREST
  refuses (PGRST103) once it counts them.
- Search titles as written: a case-insensitive regex with its special
  characters escaped, since PostgREST turns every `*` of a like pattern
  into `%`.
- One CARD_MAX_ROWS for the card and catalog reads.
- Tests for the REST mirrors, the paged reads and the brand scoping;
  readiness.unknown, revenue_30d and the REST `search` in the tool
  description and docs.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Three read tools and their REST mirrors (MCP plan B6b), on top of the
catalog tools (B6a):

- get_shopping_shelf: each shopping question's latest shelf per AI
  channel, the brand's place on it and its last 7 days, and "Why not
  you?" on the shelves it isn't on (its catalog product the question
  asks for most, with its readiness). Paged; period, platform, market
  and absent_only filters.
- get_shopping_readiness: the Readiness checklist and score, each
  check's text as the tab writes it (en.json) and where its fix starts,
  and each AI channel's state.
- get_product_ai_says: a catalog product's "What AI says": answers,
  quotes and the pages they cited.

They run the page's own loaders with the service role (dbClient /
withDbClient) once the brand is the key's, so the tools and the page
read the same. Like the page's tabs they need a plan with
shopping_analytics (403 over REST). copyValues moves to
lib/shopping/readiness.ts for both.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
- Plan: read the plan the organization is on (usagePlanFromOrgRow), as the
  page does, so a workspace whose trial ended still reads; the locked
  message names the first plan with Product Visibility.
- Shelf: read the products for "Why not you?" beside the shelves; pages of
  10 shelves (50 at most), each with its first 10 products and
  products_total.
- Readiness: read which channels hold the brand's products one row a
  channel (getShoppingOwnChannels) instead of every card on the shelves.
- Guard test: the page's loaders through the MCP client with the member's
  client failing, every read and RPC naming the brand; plan lock and
  not found answered as errors.
- Comments on the shared loaders say the MCP runs them with the service
  role; docs table no longer split by a blank line.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Google Merchant Center can't be connected where the API has no Composio
auth config for it (COMPOSIO_GMC_AUTH_CONFIG_ID), as on Cloud today, yet
Product Visibility asked for it: Readiness's "Google Merchant Center feed
connected" warned in the US and failed in Europe, pulling the score down,
and its Connect led to Settings' Coming soon.

- readinessChecklist takes merchantCenterOffered: where Merchant Center
  isn't offered and the brand has no Merchant Center source, the check is
  neither listed nor scored. A source connected before still passes.
- The page reads it from /api/integrations/config (getMerchantCenterOffered,
  false when unread); the data strip's Merchant Center chip says Soon there,
  as the marketplaces with no connector.
- The MCP readiness reads the same through a new CRON_SECRET internal
  endpoint, GET /api/internal/integrations-config (the MCP has no member
  session); unread counts as not offered. integrationsConfig() is the one
  definition for both routes.
- Europe's market note no longer says only a Merchant Center feed decides
  ChatGPT: Google Shopping does, from a feed or the pages' product schema.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…d's products in its shopping results

Readiness had no way to tell whether Google lists a shop's products
where Merchant Center can't be connected. Search Console can, from the
brand's own property: the pages shown as merchant listings (the free
shopping listings) and product snippets.

- The daily GSC sync reads them in the two steps the API needs (search
  appearance can't be a column beside the page): the property's types
  over 28 days, then each shopping one's [page, date] rows filtered to it
  (types matched by name, so MERCHANT_LISTINGS or "Merchant listings"
  both count). A filtered read whose impressions pass its type's total is
  dropped as unfiltered, never kept as every page shown. Rows go to
  gsc_shopping_page_stats (00377, members read); another property's rows
  are dropped first; 90 days kept. brands.gsc_shopping_synced_at says it
  was read.
- Readiness's new "Google shows your products in shopping results
  (Search Console)": the catalog's product pages (feed-match pageKey)
  shown in 28 days; half or more passes, some warn, none fails, with
  what to check (product schema: price, availability, GTIN). Without
  Search Console, before its first read or unread: unknown, not scored.
- The MCP readiness reads the same (get_shopping_readiness).

To check on a live property (gkhngyk): the step 1 types list, and that
Composio applies dimension_filter_groups as sent
({ groupType, filters: [{ dimension, operator, expression }] }).

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 29, 2026
…g-appearance

# Conflicts:
#	docs/guides/mcp-server.mdx
#	supabase/schema.sql
#	web/src/app/[locale]/(dashboard)/dashboard/shopping/page.tsx
#	web/src/app/api/mcp/product-visibility/ai-says/route.test.ts
#	web/src/app/api/mcp/product-visibility/ai-says/route.ts
#	web/src/app/api/mcp/product-visibility/readiness/route.test.ts
#	web/src/app/api/mcp/product-visibility/readiness/route.ts
#	web/src/app/api/mcp/product-visibility/shelf/route.test.ts
#	web/src/app/api/mcp/product-visibility/shelf/route.ts
#	web/src/lib/mcp/catalog.test.ts
#	web/src/lib/mcp/catalog.ts
#	web/src/lib/mcp/product-visibility-scope.test.ts
#	web/src/lib/mcp/product-visibility.test.ts
#	web/src/lib/mcp/product-visibility.ts
#	web/src/lib/mcp/server.ts
#	web/src/lib/mcp/subscription-gate.test.ts
#	web/src/lib/shopping/readiness.test.ts
#	web/src/lib/shopping/readiness.ts
@cihan-gyk

Copy link
Copy Markdown
Collaborator Author

Merged main forward. The conflicts (18 files: the MCP catalog / Product Visibility files, readiness, the Shopping page, server.ts, the MCP docs and schema.sql) came from this branch's parents being squash-merged (#1729, #1733, #1747; each squash commit matches its branch's final state). Resolved by taking main's version of every parent file and re-applying this PR's own commit on top (git apply -3): the result's diff against main is exactly this PR's 15 files. The one hand-merge: the get_product_visibility_readiness description keeps main's plan wording and adds googleShopping. schema.sql regenerated with build-schema.sh.

Typecheck and the conflicted files' tests pass (readiness, Product Visibility MCP + routes, catalog, subscription gate, shopping search appearance; server gsc-sync tests); server lint clean.

…ped read as unknown

The type's total was counted by property, where a result showing several
of the shop's products counts once, so a shop's page rows always added
up past it and were dropped; the brand was then marked read and showed
as having no product in Google's shopping results. The total is now
counted by page, as the rows are, and a dropped read leaves the brand
unread, so Readiness says it can't tell.

@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 cc6b833: the totals per appearance type are read by page, as the rows are (aggregation_type: 'byPage'), and a dropped read clears gsc_shopping_synced_at so Readiness shows the item as not read yet rather than failing it; two tests. 00377 also revokes the default grants before giving members select. At merge time gsc_shopping_page_stats is listed in the demo coverage as skipped (Search Console never syncs a demo brand).

What I changed

  • The filter check compared different counts. Step 1 read each appearance type's total with aggregation_type: 'auto'. With only the searchAppearance dimension, that means by property. Step 2 groups by page, so it is counted by page. Counted by property, a result that shows several of the shop's products counts once. Counted by page, each of those pages counts. So a shop whose products show side by side in a shopping unit (the shops this item is for) would add up more than 5% past the total, and every read would be dropped as "filter not applied". The brand was still stamped gsc_shopping_synced_at, so Readiness would read zero products shown and mark the item fail ("Google hasn't shown any of your product pages…").
    • Step 1 now asks aggregation_type: 'byPage', so both sides are counted the same way.
    • A dropped read now clears gsc_shopping_synced_at. Readiness then shows the item as unknown and leaves it out of the score, instead of claiming no product is shown. Another type that read fine is still kept.
    • Tests: the sync's appearance call asks by page, and a dropped read leaves the brand unread while the other type's rows are kept. Both fail on the PR's head.
    • For the live-property check you already listed: please also confirm that the appearance read with byPage comes back for the property. If the API or Composio rejects it, the shopping sync logs "shopping sync failed" and the item stays unknown. Nothing would read wrong.

What I checked

  • Migration 00377.
    • gsc_shopping_page_stats has RLS on, with only a member select policy. It's scoped like 00181's gsc_page_stats, through brands.organization_id = profiles.organization_id for auth.uid(). There's a grant select to authenticated. With no insert/update/delete policy, the default table grants don't let anon or members write. Only the sync (service role) does.
    • The unique key (brand_id, page, appearance, date) matches the upsert's onConflict.
    • Indexes cover the brand/date read and the table-wide date prune.
    • The two brands columns are nullable and have no default, so adding them doesn't rewrite the table.
    • notify pgrst is at the end.
  • Server. The shopping read runs inside the brand loop's own try/catch, so a failure there doesn't stop the query or page sync. Another property's rows are deleted before the read. Retention is 90 days.
  • Web. getShoppingSearchAppearance reads through dbClient() (RLS for a person, the key's scope over MCP), the same as the other Readiness reads. Without a property, or before the first read, the item is unknown and isn't scored. Pages are matched with pageKey on both sides.
  • No PostgREST embeds are added. No new server action writes.
  • Tests: gsc-sync* (23), the readiness, MCP and shopping-action tests (52) pass. Web tsc passes. The full server suite passes, except for suites that need a package missing from my local install and the known content-people timing test.

Merge on main: this PR's own diff merges cleanly. The stack under it (#1729 → #1733 → #1747) conflicts with main in web/src/lib/mcp/server.ts, web/src/lib/mcp/subscription-gate.test.ts and docs/guides/mcp-server.mdx (from #1715's MCP tools). Those conflicts belong to #1729 and need resolving there first.

Follow-ups

  1. getShoppingSearchAppearance reads every (page, day, type) row of 28 days and dedupes them in the app. A large shop can have tens of thousands of rows: dozens of 1,000-row requests each time the Readiness tab opens (and on each MCP call). A select distinct page RPC, or rolling up to one row per page and type, would make it a single small read.
  2. The new function is inserted between getShoppingFilterOptions and its doc comment ("values that actually appear in this brand's data…"). That comment now sits above getShoppingSearchAppearance's own.
  3. When a read is dropped, Readiness's unknown text says the results "come with its next daily sync". If the filter keeps being dropped, that's not quite right. A not_readable reason would say what happened.
  4. 00377's create policy has no drop policy if exists, so it can't be run twice. That's the same as 00181. Fine as long as it's applied once.

@gkhngyk
gkhngyk merged commit 12a4201 into ansvisor:main Oct 29, 2026
3 of 5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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.

2 participants