Skip to content

feat(shopping): brand-level Shopping mode toggle + ChatGPT Shopping platform + Insights isolation (#155) - #157

Merged
gkhngyk merged 1 commit into
mainfrom
feat/shopping-mode-toggle
Jun 3, 2026
Merged

gkhngyk merged 1 commit into
mainfrom
feat/shopping-mode-toggle

Conversation

@gkhngyk

@gkhngyk gkhngyk commented Jun 3, 2026 •

Copy link
Copy Markdown
Contributor

Closes #155, supersedes #95.

Summary

  • New per-brand "Shopping mode" toggle in Brand Settings → General. Admin-only.
  • Turning it ON appends chatgpt-shopping to every existing prompt under that brand and inserts the matching brand_platforms row (both idempotent).
  • After it's on, the new-prompt path defaults chatgpt-shopping into the platforms list automatically so the user doesn't have to remember it per prompt.
  • Turning it OFF preserves history — flag flips, but prompt platforms and brand_platforms rows stay so any already-captured ChatGPT Shopping data remains queryable.

ChatGPT Shopping platform

  • New Cloro scraper id chatgpt-shopping — same CHATGPT task, include.shopping: true. Parses shoppingCards to prompt_results.shopping_cards and inlineProducts to the new prompt_results.inline_products jsonb column.
  • Plan gating: starter.allowedScrapers was already restrictive enough; growth / self-hosted / enterprise use the implicit "allow all" path.

Insights isolation

The ChatGPT Shopping scraper runs on gpt-5-3-mini, so its visibility_score is not comparable to a normal ChatGPT answer. Mixing those rows into brand-level Insights would skew visibility/mentions/citations. The migration filters platform <> 'chatgpt-shopping' in:

  • insights_aggregates, competitor_aggregates, share_of_voice_aggregates (originally defined in 00006_insights_aggregates.sql)
  • visibility_trend_aggregates (originally defined in 00008_visibility_trend_aggregates.sql)

Plus the matching TS callers in web/src/lib/actions/tracking.ts and web/src/lib/mcp/data.ts (getVisibilitySummaryFor, listCitationsFor, the head-to-head comparison, the per-prompt visibility summary, etc.) — each call site has a // #155 — … comment so the next contributor doesn't drop the filter.

The Shopping dashboard at /dashboard/shopping is the only surface that consumes platform = 'chatgpt-shopping' rows and isn't affected — it reads from the normalized prompt_result_shopping_cards table.

Sidebar gating

The Shopping sidebar entry stays hidden by default. It's revealed when any brand in the org has Shopping mode on, on top of the existing shopping_analytics plan-feature gate. PlanProvider carries the derived org-wide flag so the sidebar doesn't need its own fetch.

Schema

supabase/migrations/00012_shopping_mode.sql:

  • brands.shopping_mode_enabled boolean default false
  • prompt_results.inline_products jsonb default []
  • CREATE OR REPLACE of the four aggregate RPCs with the new filter

Acceptance criteria

  • New Brand Settings toggle. Admin-only write.
  • Sidebar Shopping entry visible only when both shopping_analytics plan feature is unlocked AND at least one brand has Shopping mode on.
  • Flipping ON appends chatgpt-shopping to every prompt's platforms array under that brand; flipping OFF does not remove them.
  • New prompts under a Shopping-mode-on brand default chatgpt-shopping into their platforms.
  • ChatGPT Shopping rows excluded from Insights aggregations.
  • Shopping page still shows ChatGPT Shopping data.
  • yarn tsc --noEmit + yarn lint + yarn format:check clean.

Test plan

  • Toggle ON for a brand → toast reports X prompt(s) updated; verify in DB that every prompt's platforms array now contains chatgpt-shopping
  • Verify brand_platforms has a (brand_id, 'chatgpt-shopping', is_enabled=true) row for that brand
  • Create a new prompt under that brand → chatgpt-shopping shows up in the saved platforms list automatically
  • Sidebar shows the Shopping entry; switch to a brand that has Shopping mode off → sidebar still shows it because any-brand-on triggers it (correct per the spec)
  • Disable Shopping mode on every brand → Shopping sidebar entry disappears, but the existing brand_platforms + prompts platforms stay (verify in DB)
  • On Insights / Citations / Competitors / Visibility trend with a brand that has both chatgpt-shopping and normal results, confirm the shopping rows don't show up in aggregates
  • Shopping dashboard at /dashboard/shopping still surfaces shopping data
  • Run a tracking cycle with a prompt that has chatgpt-shopping enabled → confirm a prompt_results row with platform = 'chatgpt-shopping' lands with shopping_cards + inline_products populated

…latform + Insights isolation (#155)

Adds a per-brand "Shopping mode" toggle in Brand Settings. Flipping it on
adds `chatgpt-shopping` to every existing prompt's platforms array and
inserts the matching brand_platforms row, and the same default is applied
to any new prompt created under that brand thereafter. Flipping off
preserves history.

ChatGPT Shopping is a new Cloro scraper variant — same CHATGPT task with
`include.shopping: true` — that returns `shoppingCards` + `inlineProducts`
alongside the normal response. The cards land on the shared
prompt_results.shopping_cards column; the new prompt_results.inline_products
jsonb column carries the inline-products array.

Because that scraper runs a different model (`gpt-5-3-mini`) whose
visibility_score isn't comparable to a normal ChatGPT answer, every Insights
surface — the three aggregate RPCs in 00006, visibility_trend_aggregates in
00008, and the equivalent TS paths in tracking.ts + mcp/data.ts — now
excludes `platform = 'chatgpt-shopping'`. The Shopping dashboard is the only
place that consumes those rows; it reads from prompt_result_shopping_cards
directly and is unaffected.

The Shopping sidebar entry is hidden by default and only appears when at
least one brand in the org has Shopping mode on (still subject to the
existing `shopping_analytics` plan gate). PlanProvider carries the
derived org-wide signal so the sidebar doesn't need its own fetch.

Closes #155, supersedes #95.
@gkhngyk
gkhngyk merged commit d6fb84f into main Jun 3, 2026
3 checks passed
@gkhngyk
gkhngyk deleted the feat/shopping-mode-toggle branch June 3, 2026 13:24

This branch was successfully deployed

1 active deployment
Preview — 375b89db Deployed Jun 3, 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): org-level "Shopping mode" toggle + ChatGPT Shopping platform + Insights isolation

1 participant