From 07e9b9f20fb8a5781c5fe3ccda210f00f3d5c4f6 Mon Sep 17 00:00:00 2001 From: adm01-debug Date: Mon, 25 May 2026 10:35:22 -0300 Subject: [PATCH] fix(search): align global search telemetry with search_analytics schema MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Same bug as #329 fixed in useProductAnalytics.ts but missed in useGlobalSearch.ts. Insert was sending columns that do not exist in public.search_analytics: - seller_id → user_id (column name mismatch) - filters_used → search_context (column does not exist; the schema has search_context text) Validated against live DB (doufsxqlfjyuvxuezpln): search_analytics columns are id, user_id, search_term, results_count, search_context, created_at — no seller_id, no filters_used. Without this fix every global search insert was rejected with PGRST204 (column not found), silently breaking search telemetry. The latency+intent payload is now serialized as JSON into search_context (text) since the new column type is text, not jsonb. --- src/components/search/useGlobalSearch.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/components/search/useGlobalSearch.ts b/src/components/search/useGlobalSearch.ts index f3e2dd512..7f4ba4fc4 100644 --- a/src/components/search/useGlobalSearch.ts +++ b/src/components/search/useGlobalSearch.ts @@ -707,15 +707,15 @@ export function useGlobalSearch() { const latencyMs = Math.round(performance.now() - startedAt); void supabase.auth.getUser().then( ({ data }) => { - const sellerId = data.user?.id; - if (!sellerId) return; + const userId = data.user?.id; + if (!userId) return; return supabase .from('search_analytics') .insert({ - seller_id: sellerId, + user_id: userId, search_term: searchQuery.toLowerCase().trim().slice(0, 200), results_count: finalResults.length, - filters_used: { latency_ms: latencyMs, intent_type: intent.type }, + search_context: JSON.stringify({ latency_ms: latencyMs, intent_type: intent.type }), }) .then( () => undefined,