/** * Popular Content Analytics * * Shared logic for fetching popular and trending content. * Used by /api/analytics/popular endpoints across properties. * * @packageDocumentation */ export interface PopularContent { path: string; title: string; type: 'paper' | 'experiment'; views: number; uniqueSessions: number; avgReadTime: number; avgScrollDepth: number; } export interface UserReadingHistory { path: string; title: string; type: 'paper' | 'experiment'; lastViewed: string; viewCount: number; maxScrollDepth: number; totalTimeSpent: number; } export interface PopularResponse { popular: PopularContent[]; trending: PopularContent[]; userHistory?: UserReadingHistory[]; period: string; generatedAt: string; } export type ContentType = 'papers' | 'experiments' | 'all'; export interface PopularQueryOptions { type?: ContentType; period?: '7d' | '30d' | 'all'; limit?: number; userId?: string | null; } interface D1Result { results?: T[]; } interface D1PreparedStatement { bind(...args: unknown[]): D1PreparedStatement; first(): Promise; all(): Promise>; } interface D1Database { prepare(query: string): D1PreparedStatement; } /** * Extract a readable title from a URL path * /papers/code-mode-hermeneutic-analysis -> Code Mode Hermeneutic Analysis */ export declare function extractTitle(path: string): string; /** * Fetch popular analytics data * * @example * ```typescript * // In +server.ts * import { fetchPopularAnalytics } from '@create-something/components/analytics'; * * export const GET = async ({ platform, url, cookies }) => { * const db = platform?.env?.DB; * const result = await fetchPopularAnalytics(db, { * type: 'experiments', * period: '30d', * limit: 10, * userId: authenticatedUserId, * }); * return json(result); * }; * ``` */ export declare function fetchPopularAnalytics(db: D1Database, options?: PopularQueryOptions): Promise; export {};