Repository navigation
Closed
Labels
enhancementNew feature or request
Description
Context
We now capture shopping cards from three platforms into prompt_results.shopping_cards as raw provider-shape JSONB:
- Perplexity —
shopping_cards(snake_case) — landed in feat(tracking): capture Perplexity shopping_cards into prompt_results #83 - Google AI Mode —
shoppingCards(camelCase) — landed in feat(tracking): capture Google AI Mode shopping cards into prompt_results #86 - Microsoft Copilot —
shoppingCards(camelCase) — landed in feat(tracking): capture Microsoft Copilot shoppingCards into prompt_results #87 - ChatGPT — pending, tracked in feat(tracking): ChatGPT Shopping as a Growth-gated opt-in platform (capture shoppingCards + inlineProducts) #95 (separate platform, Growth-gated)
The raw JSONB is fine for storage but useless for analytics — querying "which competitor's products are in my shopping cards?" today means scanning every prompt_result and JSON-parsing in app code. The forthcoming Shopping dashboard page (see B–D below) and the MCP shopping tool (E) both need normalized rows.
Acceptance criteria
- Migration adds
prompt_result_shopping_cardstable — one row per card per prompt_result, with columns:prompt_result_id,brand_id(denorm for fast org-scoped queries),position,product_title,product_brand,price_amount,price_currency,image_url,merchant_url,merchant_domain,rating,review_count,raw(original card jsonb, future-proof),matched_brand_id,matched_brand_role(own | competitor | other), plus denormplatform,region,created_at. - Indexes:
(brand_id, matched_brand_role),(product_brand),(merchant_domain). - RLS policy mirrors
prompt_results(org-scoped). - Parser module at
server/src/lib/shopping-cards.jswith one normalizer per provider (parsePerplexityCard,parseAiModeCard,parseCopilotCard). Each handles the live provider shape — not the docs shape (see feat(tracking): capture Google AI Mode shopping_cards data into prompt_results #49 retro: AI Mode is camelCase not snake_case). -
cloro-result-handler.jscalls the normalizer after theprompt_resultsinsert, inserts normalized rows in a single statement. - Brand matching is delegated to the existing brand/competitor matcher used by citations —
ownif card brand/title contains tracked brand name OR merchant_domain matches tracked brand domain;competitorif it matches any tracked competitor; elseother. - Backfill script:
server/src/scripts/backfill-shopping-cards.jswalks existingprompt_results.shopping_cardsrows (last 90d) and populates the normalized table. - Backfill is idempotent (
ON CONFLICT (prompt_result_id, position) DO NOTHINGor similar).
Out of scope
- The Shopping dashboard UI — handled in #B (separate issue).
- ChatGPT capture — tracked separately in feat(tracking): ChatGPT Shopping as a Growth-gated opt-in platform (capture shoppingCards + inlineProducts) #95.
- Pricing diff vs DTC store scrape — handled in a later issue (#F).
inlineProducts(ChatGPT/AI Mode) — different shape, not in this normalization pass.
Notes
This is the blocker for the Shopping page work — open this first, merge first, then B/C/D can land in parallel.
Metadata
Metadata
Assignees
Labels
enhancementNew feature or request
Activity
feat(shopping): normalize prompt_result_shopping_cards + parser worker (
feat(shopping): sidebar entry + Shopping overview page (#144)