/** * Analytics Types * * Tipos e interfaces para el servicio de Firebase Analytics (GA4). */ /** * Configuración de Analytics para ValtechFirebaseConfig */ export interface AnalyticsConfig { /** Habilitar tracking automático de page views via Router (default: true) */ enablePageViewTracking?: boolean; /** Habilitar tracking automático de errores via ErrorHandler (default: false) */ enableErrorTracking?: boolean; /** Habilitar integración con auth para userId y userProperties (default: true) */ enableAuthIntegration?: boolean; /** Modo debug: logea a consola además de enviar a Firebase (default: false) */ debugMode?: boolean; /** Auto-grant consent para desarrollo/testing (default: false) */ defaultConsentGranted?: boolean; /** Rutas a excluir del page view tracking (regex patterns) */ excludeRoutes?: string[]; /** Consent mode inicial (GDPR) */ defaultConsent?: ConsentSettings; /** Clave de localStorage para persistir consent (default: 'analytics_consent') */ consentStorageKey?: string; /** Propiedades de usuario por defecto */ defaultUserProperties?: Record; /** Prefijo para eventos custom (ej: 'myapp_') */ eventPrefix?: string; /** Sampling rate (0.0 - 1.0) para reducir volumen (default: 1.0) */ samplingRate?: number; } /** * Settings de consentimiento GDPR */ export interface ConsentSettings { /** Permite recolección de analytics */ analytics?: boolean; /** Permite personalización de ads */ advertising?: boolean; /** Permite funcionalidad */ functionality?: boolean; /** Permite seguridad */ security?: boolean; } /** * Estado completo de consentimiento */ export interface ConsentState { /** Settings actuales */ settings: ConsentSettings; /** Timestamp de la última actualización */ updatedAt: Date | null; /** Si el usuario ha tomado una decisión explícita */ hasDecided: boolean; } /** * Nombres de eventos GA4 recomendados + customs */ export type AnalyticsEventName = 'add_payment_info' | 'add_shipping_info' | 'add_to_cart' | 'add_to_wishlist' | 'begin_checkout' | 'purchase' | 'refund' | 'remove_from_cart' | 'view_cart' | 'view_item' | 'view_item_list' | 'generate_lead' | 'login' | 'page_view' | 'screen_view' | 'search' | 'select_content' | 'select_item' | 'select_promotion' | 'share' | 'sign_up' | 'view_promotion' | 'feature_used' | 'preference_changed' | 'onboarding_step' | 'error_occurred' | 'performance_metric' | string; /** * Parámetros tipados por evento */ export interface AnalyticsEventParams { add_to_cart: { item_id: string; item_name?: string; value?: number; currency?: string; quantity?: number; }; purchase: { transaction_id: string; value: number; currency?: string; items?: AnalyticsItem[]; tax?: number; shipping?: number; }; begin_checkout: { value?: number; currency?: string; items?: AnalyticsItem[]; }; view_item: { item_id: string; item_name?: string; value?: number; currency?: string; }; remove_from_cart: { item_id: string; item_name?: string; value?: number; }; login: { method?: string; }; sign_up: { method?: string; }; search: { search_term: string; }; share: { content_type?: string; item_id?: string; method?: string; }; select_content: { content_type: string; item_id?: string; }; page_view: { page_path?: string; page_title?: string; page_location?: string; }; screen_view: { screen_name: string; screen_class?: string; }; feature_used: { feature_name: string; feature_category?: string; }; preference_changed: { preference_name: string; old_value?: string; new_value?: string; }; onboarding_step: { step_number: number; step_name?: string; }; error_occurred: { error_type: string; error_message?: string; error_stack?: string; context?: string; }; performance_metric: { metric_name: string; value: number; unit?: string; }; [key: string]: Record | undefined; } /** * Item para eventos de ecommerce */ export interface AnalyticsItem { /** ID único del item */ item_id: string; /** Nombre del item */ item_name: string; /** Categoría principal */ item_category?: string; /** Subcategorías */ item_category2?: string; item_category3?: string; /** Marca */ item_brand?: string; /** Variante (ej: color, talla) */ item_variant?: string; /** Precio unitario */ price?: number; /** Cantidad */ quantity?: number; /** Moneda ISO 4217 */ currency?: string; /** Posición en lista */ index?: number; /** Cupón aplicado */ coupon?: string; } /** * Tipo de evento de debug */ export type DebugEventType = 'event' | 'page_view' | 'screen_view' | 'user_property' | 'error' | 'consent' | 'timing'; /** * Evento de debug (solo en debug mode) */ export interface AnalyticsDebugEvent { /** Timestamp del evento */ timestamp: Date; /** Tipo de evento */ type: DebugEventType; /** Nombre del evento */ name: string; /** Parámetros del evento */ params?: Record; /** Si fue enviado a Firebase (false en debug mode) */ sent: boolean; } /** * Métrica de timing/performance */ export interface TimingMetric { /** Nombre de la métrica */ name: string; /** Valor en milisegundos */ valueMs: number; /** Categoría (ej: 'api', 'render', 'load') */ category?: string; /** Parámetros adicionales */ params?: Record; } /** * Propiedades de usuario para segmentación */ export interface UserProperties { /** Idioma preferido */ preferred_language?: string; /** Nivel de suscripción */ subscription_tier?: string; /** Organización activa (multi-tenant) */ active_organization?: string; /** Propiedades custom */ [key: string]: string | number | boolean | undefined; }