/** * Analytics Server Utilities * * Reusable server-side handlers for processing analytics events. * Import this in your +server.ts API route handlers. * * @packageDocumentation */ import type { AnalyticsEvent, EventBatch, BatchResponse, Property } from './types.js'; export interface D1Database { prepare(query: string): D1PreparedStatement; batch(statements: D1PreparedStatement[]): Promise[]>; } interface D1PreparedStatement { bind(...values: unknown[]): D1PreparedStatement; run(): Promise; } interface D1Result { success: boolean; results?: T[]; error?: string; } /** * Process a batch of analytics events and store in D1. */ export declare function processEventBatch(db: D1Database, batch: EventBatch, context: { userAgent?: string; ipCountry?: string; }): Promise; /** * Update or create session summary */ export declare function updateSessionSummary(db: D1Database, sessionId: string, event: AnalyticsEvent, context: { userAgent?: string; ipCountry?: string; }): Promise; export interface AnalyticsQueryOptions { property?: Property; category?: string; action?: string; startDate?: string; endDate?: string; sessionId?: string; limit?: number; } /** * Query events with filters */ export declare function queryEvents(db: D1Database, options: AnalyticsQueryOptions): Promise; /** * Get daily aggregates for dashboard */ export declare function getDailyAggregates(db: D1Database, options: { property?: Property; days?: number; }): Promise>; export {};