feat: Refinamiento del tracking de analiticas y actualizacion del dashboard admin
This commit is contained in:
@ -1,9 +1,48 @@
|
||||
/** analyticsService — stub. Analytics via Supabase can be implemented in v3 */
|
||||
export const analyticsService = {
|
||||
logEvent(_event: any) {
|
||||
// no-op
|
||||
},
|
||||
async getDashboardStats() {
|
||||
return null
|
||||
}
|
||||
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>;
|
||||
}
|
||||
|
||||
export const analyticsService = {
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Gets aggregated statistics for the Dashboard.
|
||||
* Can be fleshed out with RPCs later if calculations are too heavy.
|
||||
*/
|
||||
async getDashboardStats() {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user