Open-source agentic AI Search Execution Platform. Track AI visibility, find opportunities, and let agents turn signals into prioritized actions and drafted fixes across ChatGPT, Claude, Gemini, Google AI Overviews, Google AI Mode, Perplexity, Grok, and Microsoft Copilot.
TypeScript aeoai-agentai-searchanswer-engine-optimizationbrand-monitoringchatgptclaudecopilotdockergeminigeogoogle-ai-overviewsgrokmcpnextjsopen-sourceperplexityseosupabasetypescript
fix(shopping): store the products ChatGPT attaches to entities as inline product cards (#1193)
Gökhan Geyik56c546eece4f
diff --git a/server/src/lib/cloro-result-handler.js b/server/src/lib/cloro-result-handler.jsindex b1da359d4..c7a5b10e6 100644--- a/server/src/lib/cloro-result-handler.js+++ b/server/src/lib/cloro-result-handler.js@@ -10,13 +10,18 @@* 2. Runs sentiment analysis (only if brand was mentioned)* 3. Computes visibility metrics + competitor mentions via parseResponse* 4. Inserts a `prompt_results` row- * 5. Normalizes any captured shopping_cards into prompt_result_shopping_cards+ * 5. Normalizes any captured shopping_cards, then ChatGPT's inline products,+ * into prompt_result_shopping_cards*/import supabaseAdmin from '../config/supabase.js';import { analyzeSentimentAI } from './ai-tracker.js';import { parseResponse, countBrandMentions } from './response-parser.js';-import { normalizeShoppingCards, matchCardBrand } from './shopping-cards.js';+import {+ normalizeShoppingCards,+ normalizeInlineProducts,+ matchCardBrand,+} from './shopping-cards.js';import { updateTargetUrlStats } from './target-url-stats.js';import { persistCitationRows } from './citation-rows.js';import { logger } from './logger.js';@@ -103,6 +108,7 @@ export async function handleScraperResult({platform: scraperId,region,rawCards: aiResponse.shopping_cards ?? [],+ rawInlineProducts: aiResponse.inline_products ?? [],brandInfo: { brandId, brandName: brandInfo.brandName, domains: brandInfo.domains },competitors,});@@ -123,6 +129,7 @@ export async function handleScraperResult({* @param {string} args.platform* @param {string|null} args.region* @param {unknown[]} args.rawCards+ * @param {unknown[]} [args.rawInlineProducts] ChatGPT's in-answer products, stored after the cards* @param {{ brandId: string, brandName: string, domains: string[] }} args.brandInfo* @param {Array<{ id: string, name: string, domain: string|null }>} args.competitors* @returns {Promise<number>} number of rows inserted (0 if none / on failure)@@ -133,10 +140,16 @@ export async function persistShoppingCards({platform,region,rawCards,+ rawInlineProducts = [],brandInfo,competitors,}) {- const normalized = normalizeShoppingCards(platform, rawCards);+ const cards = normalizeShoppingCards(platform, rawCards);+ const lastPosition = cards.reduce((max, card) => Math.max(max, card.position ?? 0), 0);+ const normalized = [+ ...cards,+ ...normalizeInlineProducts(platform, rawInlineProducts, lastPosition),+ ];if (normalized.length === 0) return 0;const rows = normalized.map((card) => {diff --git a/server/src/lib/cloro-result-handler.test.js b/server/src/lib/cloro-result-handler.test.jsnew file mode 100644index 000000000..479aaee63--- /dev/null+++ b/server/src/lib/cloro-result-handler.test.js@@ -0,0 +1,72 @@+import { describe, it, expect, vi, beforeEach } from 'vitest';++// The handler reaches the supabase admin client at import time, and the AI+// tracker reaches the model SDKs; stub both so the module loads under test.+const upsert = vi.fn();+vi.mock('../config/supabase.js', () => ({+ default: { from: () => ({ upsert }) },+}));+vi.mock('./ai-tracker.js', () => ({ analyzeSentimentAI: vi.fn() }));++import { persistShoppingCards } from './cloro-result-handler.js';++const base = {+ promptResultId: 'result-1',+ brandId: 'brand-1',+ platform: 'chatgpt-shopping',+ region: 'US',+ brandInfo: { brandId: 'brand-1', brandName: 'Acme', domains: ['acme.com'] },+ competitors: [],+};++describe('persistShoppingCards – ChatGPT inline products (#1183)', () => {+ beforeEach(() => {+ upsert.mockReset();+ upsert.mockResolvedValue({ error: null });+ });++ it('stores inline products after the carousel cards', async () => {+ const inserted = await persistShoppingCards({+ ...base,+ rawCards: [+ {+ tags: [],+ products: [+ { title: 'Carousel A', position: 1, price: '$10.00' },+ { title: 'Carousel B', position: 2, price: '$12.00' },+ ],+ },+ ],+ rawInlineProducts: [+ { product: { title: 'Acme Trail Runner', price: '$75.00' }, entity: 'Acme Trail Runner' },+ ],+ });++ expect(inserted).toBe(3);+ const rows = upsert.mock.calls[0][0];+ expect(rows.map((row) => [row.product_title, row.position])).toEqual([+ ['Carousel A', 1],+ ['Carousel B', 2],+ ['Acme Trail Runner', 3],+ ]);+ expect(rows[2].raw.surface).toBe('inline');+ expect(rows[2].matched_brand_role).toBe('own');+ });++ it('stores inline products when the answer has no carousel', async () => {+ const inserted = await persistShoppingCards({+ ...base,+ rawCards: [],+ rawInlineProducts: [{ product: { title: 'Trail Runner', price: '$75.00' } }],+ });++ expect(inserted).toBe(1);+ expect(upsert.mock.calls[0][0][0].position).toBe(1);+ });++ it('writes nothing when there are neither cards nor inline products', async () => {+ const inserted = await persistShoppingCards({ ...base, rawCards: [] });+ expect(inserted).toBe(0);+ expect(upsert).not.toHaveBeenCalled();+ });+});diff --git a/server/src/lib/cloro-scraper.js b/server/src/lib/cloro-scraper.jsindex b363b8c6f..6b6b25f67 100644--- a/server/src/lib/cloro-scraper.js+++ b/server/src/lib/cloro-scraper.js@@ -177,12 +177,21 @@ export function parseScraperResponse(result, scraperId) {// into brand-level visibility numbers.const text = stripEntityMarkup(result.markdown || result.text || '');const citations = toCitations(result.sources);+ // Since 2026-10-16 Cloro returns the listing ChatGPT attaches to a product+ // it names as `entities[n].product`, with the same shape as a card product+ // minus `position`, and `inlineProducts` has come back empty since (#1183).+ // Both are single products inside the answer, so the listings join the+ // inline list in its `{ product }` shape.+ const inline = result.inlineProducts ?? result.inline_products ?? [];+ const entityListings = (Array.isArray(result.entities) ? result.entities : [])+ .filter((entity) => entity?.product && typeof entity.product === 'object')+ .map((entity) => ({ product: entity.product, entity: entity.name ?? null }));return {text,citations,model: result.model || 'gpt-5-3-mini',shopping_cards: result.shoppingCards ?? result.shopping_cards ?? [],- inline_products: result.inlineProducts ?? result.inline_products ?? [],+ inline_products: [...(Array.isArray(inline) ? inline : []), ...entityListings],};}diff --git a/server/src/lib/cloro-scraper.test.js b/server/src/lib/cloro-scraper.test.jsindex e3344ce8a..8b6498e06 100644--- a/server/src/lib/cloro-scraper.test.js+++ b/server/src/lib/cloro-scraper.test.js@@ -45,6 +45,34 @@ describe('cloro-scraper – parseScraperResponse', () => {expect(parsed.shopping_cards).toEqual([]);expect(parsed.inline_products).toEqual([]);});++ it('adds the listings ChatGPT attaches to entities to inline_products (#1183)', () => {+ const listing = {+ id: '23920641',+ title: 'Trail Runner 2',+ url: 'https://merchant.example/p/2?utm_source=chatgpt.com',+ price: '$75.00',+ merchants: 'Merchant',+ };+ const result = {+ markdown: 'hi',+ sources: [],+ shoppingCards: [],+ inlineProducts: [{ product: { id: 'prod1' }, render_as: 'inline' }],+ entities: [+ { type: 'product', name: 'Trail Runner 1' },+ { type: 'product', name: 'Trail Runner 2', product: listing },+ { type: 'software', name: 'Tracker', product: null },+ ],+ };++ const parsed = parseScraperResponse(result, 'chatgpt-shopping');++ expect(parsed.inline_products).toEqual([+ { product: { id: 'prod1' }, render_as: 'inline' },+ { product: listing, entity: 'Trail Runner 2' },+ ]);+ });});describe('google-aio', () => {diff --git a/server/src/lib/shopping-cards.js b/server/src/lib/shopping-cards.jsindex 251c01c15..6cdac3c6c 100644--- a/server/src/lib/shopping-cards.js+++ b/server/src/lib/shopping-cards.js@@ -431,6 +431,41 @@ export function normalizeShoppingCards(platform, cards) {.filter(Boolean);}+/**+ * Normalize ChatGPT's single in-answer products (`prompt_results.inline_products`,+ * each `{ product, … }`) into the same rows as its carousel cards.+ *+ * They take the positions after `afterPosition`, the carousel's last, so the+ * two never collide on (prompt_result_id, position), and `raw.surface` tells+ * them apart. Only ChatGPT Shopping has inline products; any other platform+ * returns `[]`.+ *+ * @param {string} platform+ * @param {unknown} items+ * @param {number} [afterPosition]+ */+export function normalizeInlineProducts(platform, items, afterPosition = 0) {+ if (platform !== 'chatgpt-shopping' || !Array.isArray(items)) return [];+ const products = items+ .map((item) => item?.product)+ .filter((product) => product && typeof product === 'object');+ return products+ .map((product, i) => {+ try {+ const card = parseChatgptCard(product, 0);+ return {+ ...card,+ position: afterPosition + i + 1,+ raw: { ...card.raw, surface: 'inline' },+ };+ } catch (err) {+ logger.error({ err, platform, position: i }, '[shopping-cards] inline parser failed');+ return null;+ }+ })+ .filter(Boolean);+}+/*** Match a normalized card against the tracked brand and competitors.* Returns `{ matched_brand_id, matched_brand_role }`.diff --git a/server/src/lib/shopping-cards.test.js b/server/src/lib/shopping-cards.test.jsindex 4393d163a..1b49d76aa 100644--- a/server/src/lib/shopping-cards.test.js+++ b/server/src/lib/shopping-cards.test.js@@ -11,6 +11,7 @@ import {parseCopilotCard,parseChatgptCard,normalizeShoppingCards,+ normalizeInlineProducts,matchCardBrand,} from './shopping-cards.js';@@ -348,6 +349,62 @@ describe('shopping-cards – normalizeShoppingCards', () => {});});+describe('shopping-cards – normalizeInlineProducts (#1183)', () => {+ // An entity listing as Cloro returns it since 2026-10-16: a card product+ // without `position`, wrapped as an inline product by parseScraperResponse.+ const entityListing = {+ product: {+ id: '23920641',+ title: 'Trail Runner 2',+ url: 'https://merchant.example/p/2?utm_source=chatgpt.com',+ price: '$75.00',+ merchants: 'Merchant',+ image_urls: ['https://images.example.com/trail-runner-2.jpg'],+ rating: 4.6,+ num_reviews: 210,+ offers: [{ merchant_name: 'Merchant', price: '$75.00', available: true }],+ },+ entity: 'Trail Runner 2',+ };+ const inlineProduct = {+ product: { title: 'Road Runner', position: 1, price: '$90.00' },+ render_as: 'inline',+ };++ it('parses each product like a carousel card', () => {+ const [card] = normalizeInlineProducts('chatgpt-shopping', [entityListing]);+ expect(card.product_title).toBe('Trail Runner 2');+ expect(card.price_amount).toBe(75);+ expect(card.price_currency).toBe('USD');+ expect(card.image_url).toBe('https://images.example.com/trail-runner-2.jpg');+ expect(card.merchant_domain).toBe('merchant.example');+ expect(card.rating).toBe(4.6);+ expect(card.review_count).toBe(210);+ });++ it('numbers them after the carousel and marks them inline', () => {+ const cards = normalizeInlineProducts('chatgpt-shopping', [inlineProduct, entityListing], 3);+ expect(cards.map((card) => card.position)).toEqual([4, 5]);+ expect(cards.every((card) => card.raw.surface === 'inline')).toBe(true);+ });++ it('starts at 1 when there is no carousel', () => {+ const cards = normalizeInlineProducts('chatgpt-shopping', [entityListing]);+ expect(cards[0].position).toBe(1);+ });++ it('skips items without a product', () => {+ const cards = normalizeInlineProducts('chatgpt-shopping', [{ id: 'x' }, null, entityListing]);+ expect(cards).toHaveLength(1);+ expect(cards[0].position).toBe(1);+ });++ it('returns [] for other platforms and non-array input', () => {+ expect(normalizeInlineProducts('copilot-web', [entityListing])).toEqual([]);+ expect(normalizeInlineProducts('chatgpt-shopping', null)).toEqual([]);+ });+});+describe('shopping-cards – matchCardBrand', () => {const brand = { brandId: 'brand-1', brandName: 'Acme', domains: ['acme.com'] };const competitors = [{ id: 'comp-1', name: 'Globex', domain: 'globex.com' }];