From 52cc20e81b401b8d824249c1afb527689dd286de Mon Sep 17 00:00:00 2001 From: Hanzo_dev <2002samudiojohan@gmail.com> Date: Wed, 4 Mar 2026 20:59:35 -0500 Subject: [PATCH] fix: Fetch completo de negocios/shuttles e integracion de cupones en analisis --- frontend/src/views/StrategicAnalytics.vue | 40 +++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-) diff --git a/frontend/src/views/StrategicAnalytics.vue b/frontend/src/views/StrategicAnalytics.vue index 95d0a83..c87b2a5 100644 --- a/frontend/src/views/StrategicAnalytics.vue +++ b/frontend/src/views/StrategicAnalytics.vue @@ -421,11 +421,15 @@ onMounted(async () => { try { const [ { count: userCount }, - { data: events } + { data: events }, + { data: allBusinesses }, + { data: allShuttles } ] = await Promise.all([ supabase.from('users').select('*', { count: 'exact', head: true }).eq('is_active', true), // In a production app with >1M rows we might use a group-by RPC - supabase.from('analytics_events').select('*') + supabase.from('analytics_events').select('*'), + supabase.from('businesses').select('name'), + supabase.from('shuttles').select('company_name, vehicle_type') ]) const shuttleStats: any = {} @@ -434,6 +438,25 @@ onMounted(async () => { let total_shuttle_contacts = 0 let total_biz_views = 0 + // PRE-FILL all businesses so they always show even with 0 clicks + if (allBusinesses) { + for (const b of allBusinesses) { + if (b.name) { + bizStats[b.name] = { views: 0, promos: 0, favs: 0, social: 0, location: 0, calls: 0 } + } + } + } + + // PRE-FILL all shuttles so they always show even with 0 clicks + if (allShuttles) { + for (const s of allShuttles) { + const name = s.company_name || s.vehicle_type || 'shuttle' + if (!shuttleStats[name]) { + shuttleStats[name] = { views: 0, contacts: 0, calls: 0, whatsapp: 0 } + } + } + } + const safeRows = events || [] for (const ev of safeRows) { @@ -473,6 +496,19 @@ onMounted(async () => { bizStats[nameKey].promos++ total_promo_clicks++ } + } else if (ev.entity_type === 'coupon') { + // Los cupones se suman a la parte del negocio correspondiente + const bizName = ev.properties?.business || nameKey + if (!bizStats[bizName]) { + bizStats[bizName] = { views: 0, promos: 0, favs: 0, social: 0, location: 0, calls: 0 } + } + + if (ev.event_name === 'promo_view') { + bizStats[bizName].promos++ + total_promo_clicks++ + } else if (ev.event_name === 'location_click') { + bizStats[bizName].location++ + } } }