2026-03-04 20:36:31 -05:00
|
|
|
import { supabase } from '@/supabase';
|
|
|
|
|
|
|
|
|
|
export interface AnalyticsEvent {
|
|
|
|
|
event_name: string;
|
|
|
|
|
entity_type?: 'business' | 'shuttle' | 'coupon' | 'stop' | 'route' | 'taxi' | 'system' | 'other';
|
|
|
|
|
entity_id?: string; // The ID of the specific entity
|
|
|
|
|
entity_name?: string; // Optional name for easier querying
|
|
|
|
|
screen_name?: string; // Optional screen name
|
|
|
|
|
properties?: Record<string, any>;
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-21 09:53:31 -05:00
|
|
|
export const analyticsService = {
|
2026-03-04 20:36:31 -05:00
|
|
|
/**
|
|
|
|
|
* Logs an action or event to the analytics_events table.
|
|
|
|
|
*/
|
|
|
|
|
async logEvent(event: AnalyticsEvent) {
|
|
|
|
|
try {
|
|
|
|
|
const { data: userData } = await supabase.auth.getUser();
|
|
|
|
|
|
|
|
|
|
const payload = {
|
|
|
|
|
event_name: event.event_name,
|
|
|
|
|
entity_type: event.entity_type,
|
|
|
|
|
entity_id: event.entity_id,
|
|
|
|
|
entity_name: event.entity_name,
|
|
|
|
|
properties: event.properties || {},
|
|
|
|
|
user_id: userData?.user ? userData.user.id : null
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const { error } = await supabase
|
|
|
|
|
.from('analytics_events')
|
|
|
|
|
.insert(payload);
|
|
|
|
|
|
|
|
|
|
if (error) {
|
|
|
|
|
console.warn('Analytics logging failed:', error);
|
|
|
|
|
}
|
|
|
|
|
} catch (e) {
|
|
|
|
|
console.warn('Failed to dispatch analytics event:', e);
|
|
|
|
|
}
|
2026-02-21 09:53:31 -05:00
|
|
|
},
|
2026-03-04 20:36:31 -05:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Gets aggregated statistics for the Dashboard.
|
|
|
|
|
* Can be fleshed out with RPCs later if calculations are too heavy.
|
|
|
|
|
*/
|
refactor: migrate fully to Supabase, remove Firebase/Render/Python backend
- DELETED: entire backend/ (Python/FastAPI — replaced by Supabase)
- DELETED: old/ directory (obsolete code)
- DELETED: render.yaml, inject_api.py, check_tags.py, PENDING_FOR_TOMORROW.md
- DELETED: frontend/src/firebaseConfig.ts (Firebase Auth replaced by Supabase Auth)
- DELETED: frontend/src/services/apiClient.ts (HTTP client for dead backend)
- MIGRATED services to Supabase native:
schedulesService, favoritesService, usersService,
telemetryService (stub), reportsService, analyticsService (stub)
- MIGRATED stores/favorites.ts to Supabase direct queries
- MIGRATED views: SplashScreen, AdminTaxis, AdminDrivers, StrategicAnalytics
- MIGRATED utils/imageUrl.ts to Supabase Storage URLs
- FIXED router/index.ts: guard now uses supabase.auth.getSession()
instead of old localStorage auth_token (fixes logout + map loading)
- FIXED AuthView.vue: removed aggressive watch({ immediate: true })
that caused wrong redirects on map route
- FIXED SplashScreen.vue: navigate() now reads Supabase session + role
- FIXED RLS: added INSERT policy on public.users for trigger
- CONFIRMED: admin@sibu.com assigned ADMIN role in Supabase
2026-02-25 21:49:26 -05:00
|
|
|
async getDashboardStats() {
|
2026-03-04 20:36:31 -05:00
|
|
|
return null;
|
2026-02-21 09:53:31 -05:00
|
|
|
}
|
2026-03-04 20:36:31 -05:00
|
|
|
};
|