48 lines
1.7 KiB
TypeScript
48 lines
1.7 KiB
TypeScript
import { BaseApiClient } from '../base/BaseApiClient';
|
|
import { RecordPageViewOutputDTO } from '../../types/generated/RecordPageViewOutputDTO';
|
|
import { RecordEngagementOutputDTO } from '../../types/generated/RecordEngagementOutputDTO';
|
|
|
|
// TODO: Move these types to apps/website/lib/types/generated when available
|
|
type RecordPageViewInputDto = { path: string; userId?: string };
|
|
type RecordEngagementInputDto = { eventType: string; userId?: string; metadata?: Record<string, unknown> };
|
|
|
|
// TODO: Move these types to apps/website/lib/types/generated when available
|
|
type AnalyticsDashboardDto = {
|
|
totalUsers: number;
|
|
activeUsers: number;
|
|
totalRaces: number;
|
|
totalLeagues: number;
|
|
};
|
|
type AnalyticsMetricsDto = {
|
|
pageViews: number;
|
|
uniqueVisitors: number;
|
|
averageSessionDuration: number;
|
|
bounceRate: number;
|
|
};
|
|
|
|
/**
|
|
* Analytics API Client
|
|
*
|
|
* Handles all analytics-related API operations.
|
|
*/
|
|
export class AnalyticsApiClient extends BaseApiClient {
|
|
/** Record a page view */
|
|
recordPageView(input: RecordPageViewInputDto): Promise<RecordPageViewOutputDTO> {
|
|
return this.post<RecordPageViewOutputDTO>('/analytics/page-view', input);
|
|
}
|
|
|
|
/** Record an engagement event */
|
|
recordEngagement(input: RecordEngagementInputDto): Promise<RecordEngagementOutputDTO> {
|
|
return this.post<RecordEngagementOutputDTO>('/analytics/engagement', input);
|
|
}
|
|
|
|
/** Get analytics dashboard data */
|
|
getDashboardData(): Promise<AnalyticsDashboardDto> {
|
|
return this.get<AnalyticsDashboardDto>('/analytics/dashboard');
|
|
}
|
|
|
|
/** Get analytics metrics */
|
|
getAnalyticsMetrics(): Promise<AnalyticsMetricsDto> {
|
|
return this.get<AnalyticsMetricsDto>('/analytics/metrics');
|
|
}
|
|
} |