also looking at this
chore: wip stx improvements
#1649
241 files
+19022
-1323
| @@ -0,0 +1,56 @@ | ||
| 1 | export interface PageView { | |
| 2 | id: string | |
| 3 | path: string | |
| 4 | referrer?: string | |
| 5 | userAgent?: string | |
| 6 | country?: string | |
| 7 | timestamp: number | |
| 8 | sessionId?: string | |
| 9 | duration?: number | |
| 10 | } | |
| 11 | ||
| 12 | export interface AnalyticsEvent { | |
| 13 | id: string | |
| 14 | name: string | |
| 15 | data?: Record<string, unknown> | |
| 16 | path?: string | |
| 17 | timestamp: number | |
| 18 | sessionId?: string | |
| 19 | } | |
| 20 | ||
| 21 | export interface AnalyticsQuery { | |
| 22 | from?: Date | |
| 23 | to?: Date | |
| 24 | path?: string | |
| 25 | event?: string | |
| 26 | limit?: number | |
| 27 | groupBy?: 'day' | 'week' | 'month' | 'path' | 'referrer' | 'country' | |
| 28 | } | |
| 29 | ||
| 30 | export interface AnalyticsResult { | |
| 31 | totalPageViews: number | |
| 32 | uniqueVisitors: number | |
| 33 | topPages: Array<{ path: string, views: number }> | |
| 34 | topReferrers: Array<{ referrer: string, count: number }> | |
| 35 | topCountries: Array<{ country: string, count: number }> | |
| 36 | pageViewsByPeriod?: Array<{ period: string, count: number }> | |
| 37 | events?: Array<{ name: string, count: number }> | |
| 38 | averageDuration?: number | |
| 39 | } | |
| 40 | ||
| 41 | export interface AnalyticsConfig { | |
| 42 | storage: AnalyticsStorage | |
| 43 | anonymize?: boolean | |
| 44 | ignorePaths?: string[] | |
| 45 | sessionTimeout?: number | |
| 46 | } | |
| 47 | ||
| 48 | export interface AnalyticsStorage { | |
| 49 | savePageView(view: PageView): Promise<void> | |
| 50 | saveEvent(event: AnalyticsEvent): Promise<void> | |
| 51 | getPageViews(query?: AnalyticsQuery): Promise<PageView[]> | |
| 52 | getEvents(query?: AnalyticsQuery): Promise<AnalyticsEvent[]> | |
| 53 | getStats(query?: AnalyticsQuery): Promise<AnalyticsResult> | |
| 54 | clear(): Promise<void> | |
| 55 | count(): Promise<number> | |
| 56 | } | |