Skip to content

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

Closed

Description

@gkhngyk

Epic — supersedes #95. Adds an org-level "Shopping mode" toggle in Settings on top of the per-brand ChatGPT Shopping platform from #95, plus an explicit Insights isolation rule.

Why now

Shopping is meaningful for product / e-commerce brands and irrelevant for everyone else — so the Shopping dashboard and the per-brand ChatGPT Shopping scrape should both stay hidden by default. Today the Shopping sidebar entry is always visible (plan-gated only) and #95 only exposes ChatGPT Shopping as a per-brand toggle deep in Brand Settings. A single coarse switch — "I do e-commerce" — at the org level is a cleaner UX hook than expecting customers to find a per-brand checkbox.

A second decision: ChatGPT Shopping returns answers from a different model (gpt-5-3-mini) under include.shopping: true — its visibility_score is not comparable to a normal ChatGPT text response. Mixing those rows into the Insights aggregates would skew brand-level visibility numbers. The shopping data captured by Perplexity / AI Mode / Copilot is fine to keep in Insights because their shopping cards are a side-payload of the same model's answer; ChatGPT Shopping isn't.

Scope

1. Org-level "Shopping mode" toggle

  • New field on organizations (e.g. shopping_mode_enabled boolean not null default false).
  • New section in web/src/components/settings — Settings → Project (or its own card) — single checkbox "I'm in e-commerce / shopping". Default off. Admin-only via the existing useUserRole().canAdmin gate.
  • New REST endpoint to read / update the flag (mirror the /api/settings/anthropic-key pattern).

2. Sidebar gating

  • The Shopping entry in web/src/config/dashboard.ts is hidden unless shopping_mode_enabled === true. Combine the existing requiredFeature: 'shopping_analytics' plan gate with the new org-preference gate — both must pass.

3. Auto-bulk ChatGPT Shopping platform

When the org toggle flips from false → true:

  • For every existing brand in the org: insert a brand_platforms row with platform = 'chatgpt-shopping' and is_enabled = true (idempotent — use ON CONFLICT DO NOTHING against the existing unique constraint).
  • For brands created after the toggle is on, the new-brand path defaults chatgpt-shopping on too.
  • When the toggle flips true → false: do not delete the rows or disable them (preserve historical opt-ins). Just hide the sidebar entry and stop adding the platform to new brands. The per-brand toggle in Brand Settings remains the granular override.

4. ChatGPT Shopping pipeline (#95's original scope, kept)

  • New scraper chatgpt-shopping in server/src/lib/cloro-scraper.js — Cloro CHATGPT task with include.shopping: true.
  • parseScraperResponse returns shopping_cards: result.shoppingCards ?? [] AND inline_products: result.inlineProducts ?? [] for this scraper.
  • Migration: prompt_results.inline_products jsonb not null default '[]' (mirrors shopping_cards).
  • Plan gating in web/src/config/plans.ts: chatgpt-shopping stays out of starter.allowedScrapers. Growth + self-hosted + enterprise allow it.

5. Insights data isolation

Every server function that aggregates prompt_results for visibility / Insights / Citations / Competitors excludes platform = 'chatgpt-shopping'. Concrete touch points:

Document the rule with a comment near each call site so the next contributor doesn't accidentally drop it.

The Shopping page (/dashboard/shopping) is the only surface that should consume platform = 'chatgpt-shopping' rows — it already does the right thing via the prompt_result_shopping_cards table.

Acceptance criteria

  • New Settings checkbox toggles organizations.shopping_mode_enabled. Admin-only write.
  • Sidebar Shopping entry visible only when both shopping_analytics plan feature is unlocked AND shopping_mode_enabled = true.
  • Flipping the toggle ON bulk-adds chatgpt-shopping to every brand's brand_platforms; flipping it OFF does not remove them.
  • New brand creation path adds chatgpt-shopping when org has shopping mode on.
  • ChatGPT Shopping rows (platform = 'chatgpt-shopping') are excluded from Insights aggregations — Brand visibility, Competitor comparison, Citations, Visibility trend.
  • The Shopping page still shows ChatGPT Shopping data (no double-filtering).
  • pnpm tsc --noEmit + yarn lint + pnpm format:check clean.

Out of scope

Why this supersedes #95

#95 is the capture-and-platform layer only (new scraper, per-brand toggle, plan gating). The org-level toggle + the Insights isolation rule are new asks on top. This issue covers both layers as one shippable epic. Closing #95 with a redirect here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementhelp wanted

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions