/** * TypeScript Type Definitions for Behavioral Tracking System * Use these types in your Next.js applications */ export type EventType = 'product_view' | 'update_cart' | 'category_view' | 'search' | 'add_to_cart' | 'remove_from_cart' | 'add_to_wishlist' | 'remove_from_wishlist' | 'checkout_initiated' | 'order_placed' | 'review_submitted' | 'share_product' | 'filter_applied' | 'sort_applied' | 'page_view' | 'scroll_depth' | 'time_spent' | 'video_play' | 'video_complete' | 'banner_click' | 'coupon_applied'; export type EventCategory = 'engagement' | 'conversion' | 'navigation' | 'social' | 'media' | 'other'; export type DeviceType = 'mobile' | 'tablet' | 'desktop'; export interface BehavioralEvent { event_type: EventType; consent_given: boolean; actor_type?: string; actor_id?: number; session_id?: string; device_id?: string; event_category?: EventCategory; target_type?: string; target_id?: number; url?: string; referrer?: string; utm_source?: string; utm_medium?: string; utm_campaign?: string; utm_term?: string; utm_content?: string; search_query?: string; search_results_count?: number; product_price?: number; product_quantity?: number; product_variant?: string; time_spent_seconds?: number; scroll_depth_percent?: number; interaction_count?: number; device_type?: DeviceType; browser?: string; platform?: string; ip_address?: string; country?: string; city?: string; metadata?: Record; converted?: boolean; conversion_order_id?: number; converted_at?: string; anonymized?: boolean; } export interface ApiResponse { success: boolean; message?: string; data?: T; errors?: Record; } export interface PaginatedResponse { data: T[]; current_page: number; last_page: number; per_page: number; total: number; from: number; to: number; } export interface ProductAffinity { target_id: number; view_count: number; product?: Product; } export interface CustomerJourneyStep { timestamp: string; event: EventType; target: string | null; target_id: number | null; url: string | null; converted: boolean; } export interface SearchQuery { search_query: string; search_count: number; avg_results: number; } export interface CartAbandonment { total_add_to_carts: number; converted: number; abandoned: number; abandonment_rate: number; conversion_rate: number; } export interface ConversionFunnel { product_views: number; add_to_cart: number; checkout_initiated: number; orders_placed: number; } export interface CustomerSegmentation { highly_engaged: number; moderately_engaged: number; low_engaged: number; } export interface CampaignPerformance { total_events: number; unique_sessions: number; conversions: number; conversion_rate: number; sources: Record; mediums: Record; } export interface DeviceAnalytics { by_device: Record; by_browser: Record; by_platform: Record; } export interface LocationAnalytics { by_country: Record; by_city: Array<{ city: string; country: string; count: number; }>; } export interface EventStats { by_event_type: Record; by_event_category: Record; total_events: number; unique_sessions: number; unique_users: number; } export interface DashboardData { conversion_funnel: ConversionFunnel; cart_abandonment: CartAbandonment; customer_segmentation: CustomerSegmentation; device_analytics: DeviceAnalytics; top_searches: SearchQuery[]; total_events: number; unique_sessions: number; } export interface EventQueryParams { event_type?: EventType; event_category?: EventCategory; actor_type?: string; actor_id?: number; target_type?: string; target_id?: number; session_id?: string; device_type?: DeviceType; utm_campaign?: string; country?: string; converted?: boolean; start_date?: string; end_date?: string; per_page?: number; page?: number; } export interface DateRangeParams { start_date?: string; end_date?: string; } export interface Product { id: number; name: string; slug: string; price: number; sale_price?: number; image?: string; category_id?: number; brand_id?: number; stock?: number; description?: string; sku?: string; created_at: string; updated_at: string; } export interface Order { id: number; customer_id: number; total: number; status: string; payment_status: string; created_at: string; updated_at: string; } export interface TrackingConfig { enabled: boolean; consentRequired: boolean; debugMode: boolean; apiUrl: string; autoTrack?: boolean; trackProductViews?: boolean; trackSearches?: boolean; trackScrollDepth?: boolean; trackTimeSpent?: boolean; } export interface UseBehavioralTrackingReturn { trackEvent: (eventType: EventType, data?: Partial) => Promise; trackProductView: (productId: number, price?: number) => Promise; trackAddToCart: (productId: number, quantity: number, price: number) => Promise; trackRemoveFromCart: (productId: number) => Promise; trackSearch: (query: string, resultsCount: number) => Promise; trackOrderPlaced: (orderId: number) => Promise; trackCheckoutInitiated: () => Promise; trackAddToWishlist: (productId: number) => Promise; trackRemoveFromWishlist: (productId: number) => Promise; } export interface UseTrackingReturn { hasConsent: boolean; grantConsent: () => void; revokeConsent: () => void; isLoading: boolean; } export interface AnalyticsClient { getDashboard: (params?: DateRangeParams) => Promise>; getEvents: (params?: EventQueryParams) => Promise>>; getEventStats: (params?: DateRangeParams) => Promise>; getProductAffinity: (productId: number, limit?: number) => Promise>; getCustomerJourney: (sessionId: string) => Promise>; getTopSearches: (params?: DateRangeParams & { limit?: number; }) => Promise>; getCartAbandonment: (params?: DateRangeParams) => Promise>; getConversionFunnel: (params?: DateRangeParams) => Promise>; getCustomerSegmentation: (params?: DateRangeParams) => Promise>; getCampaignPerformance: (campaign: string) => Promise>; getDeviceAnalytics: (params?: DateRangeParams) => Promise>; getLocationAnalytics: (params?: DateRangeParams) => Promise>; } export interface TrackingError { code: string; message: string; details?: any; } export declare class ConsentRequiredError extends Error { constructor(); } export declare class TrackingDisabledError extends Error { constructor(); } export type Nullable = T | null; export type Optional = T | undefined; export type AsyncResult = Promise;