Files
web-alterflixhub/app/lib/analytics-types.ts
T
2026-11-01 17:24:44 +07:00

54 lines
1.9 KiB
TypeScript

/**
* สถิติแบบ privacy-first (แนวเดียวกับ Umami): ไม่ใช้คุกกี้ ไม่เก็บ IP/UA ดิบ
* เก็บเป็น event ต่อบรรทัด (JSONL) แล้วสรุปผลฝั่งเซิร์ฟเวอร์
*/
export type AnalyticsEventType = "search" | "cinema_select" | "cinema_view" | "near_me";
export type AnalyticsEvent = {
type: AnalyticsEventType;
/** เวลาที่เกิดเหตุ (ISO) — เซิร์ฟเวอร์เป็นผู้กำหนด */
at: string;
/** รหัสผู้เข้าชมแบบไม่ระบุตัวตน (sha256 ของ ip+ua+เกลือรายวัน) */
visitor: string;
locale: string;
/** คำค้น (เฉพาะ type=search) */
query?: string;
category?: string;
result_count?: number;
slug?: string;
/** ที่มาของการคลิก: search | category | near_me | other_cinemas */
source?: string;
position?: number;
};
export type SearchQueryStat = {
query: string;
count: number;
zero_result_count: number;
click_count: number;
};
export type CinemaStat = {
slug: string;
views: number;
selects: number;
};
export type AnalyticsSummary = {
range_days: number;
total_searches: number;
unique_visitors: number;
zero_result_searches: number;
near_me_uses: number;
average_results: number;
click_through_rate: number;
top_queries: SearchQueryStat[];
zero_result_queries: SearchQueryStat[];
top_categories: Array<{ category: string; count: number }>;
top_cinemas: CinemaStat[];
daily_searches: Array<{ date: string; count: number }>;
/** คำค้นล่าสุด เพื่อดูพฤติกรรมสด ๆ ในหลังบ้าน */
recent_searches: Array<{ at: string; query: string; result_count: number }>;
};