chore(frontend-admin): 🔧 Add analytics tracking infrastructure (API clients, batch queue, custom hooks, and provider component)

This commit is contained in:
Lilith 2026-01-25 17:36:00 -08:00
parent ee1711a774
commit e36cf92899
8 changed files with 95 additions and 6 deletions

View file

@ -0,0 +1,88 @@
# Platform Analytics - Frontend Admin
Admin analytics pages migrated from `@lilith/analytics` plugin.
## Overview
This package contains all admin-facing analytics pages and components for the Lilith Platform. It's designed as a library package that exports pages for integration into the main platform admin application.
## Structure
```
src/
├── pages/ # Analytics admin pages
│ ├── ABTestingPage.tsx
│ ├── BounceRatePage.tsx
│ ├── ConversionFunnelsPage.tsx
│ ├── CostsPage.tsx
│ ├── ErrorTrackingPage.tsx
│ ├── PerformancePage.tsx
│ ├── PnLPage.tsx
│ ├── RealTimePage.tsx
│ ├── RevenuePage.tsx
│ └── TransactionsPage.tsx
├── hooks/ # Analytics tracking hooks and admin query hooks
├── providers/ # MockDataProvider and AnalyticsProvider
├── components/ # Analytics UI components
└── api/ # Analytics client and types
```
## Usage
Import pages from this package in your routing configuration:
```typescript
import {
RealTimePage,
RevenuePage,
PnLPage
} from '@platform/analytics-frontend-admin';
// Use in routes
<Route path="/analytics/realtime" element={<RealTimePage />} />
<Route path="/analytics/revenue" element={<RevenuePage />} />
<Route path="/analytics/pnl" element={<PnLPage />} />
```
## Key Features
- **10 Analytics Pages**: Comprehensive admin analytics views
- **MockDataProvider**: Development-friendly mock data for testing
- **Analytics Hooks**: Tracking hooks for view and engagement events
- **Admin Query Hooks**: React Query hooks for analytics data fetching
- **UI Components**: Reusable analytics components (MetricCard, LeaderboardTable, etc.)
## Dependencies
- `@lilith/ui-charts`: Chart components
- `@lilith/ui-styled-components`: Styled components wrapper
- `@lilith/ui-theme`: Theme system
- `@lilith/ui-primitives`: UI primitive components
- `recharts`: Charting library
- `date-fns`: Date utilities
## Development
```bash
# Install dependencies
pnpm install
# Run type checking
pnpm typecheck
# Run tests
pnpm test
# Start dev server (if using as standalone app)
pnpm dev
```
## Migration Notes
This package was migrated from `@packages/@plugins/analytics/src/` on 2026-01-25. All import paths have been updated to use local API types instead of the old `../types` pattern.
## Related Packages
- `@platform/analytics-shared`: Shared types and utilities
- `@platform/analytics-backend-api`: Backend API service
- `@platform/analytics-frontend-public`: Public-facing analytics (if exists)

View file

@ -4,7 +4,7 @@ import type {
BatchedEvent,
ViewEventData,
EngagementEventData,
} from '../types';
} from './analytics';
// Type declarations for browser APIs (allows compilation in Node.js environments)
declare const window: { addEventListener: (event: string, handler: () => void) => void } | undefined;

View file

@ -1,7 +1,7 @@
import type {
ViewEventData,
EngagementEventData,
} from '../types';
} from './analytics';
export interface BackendAnalyticsConfig {
apiBaseUrl: string;

View file

@ -1,4 +1,4 @@
import type { BatchedEvent } from '../types';
import type { BatchedEvent } from './analytics';
export class BatchQueue {
private queue: BatchedEvent[] = [];

View file

@ -1,6 +1,6 @@
import { useCallback } from 'react';
import { useAnalytics } from '../providers/analytics-provider';
import type { EngagementEventData } from '../types';
import type { EngagementEventData } from '../api/analytics';
type TrackEngagementFn = (
data: Omit<EngagementEventData, 'userId'> & { userId?: string },

View file

@ -1,6 +1,6 @@
import { useEffect, useRef } from 'react';
import { useAnalytics } from '../providers/analytics-provider';
import type { ViewEventData } from '../types';
import type { ViewEventData } from '../api/analytics';
interface UseTrackViewOptions {
contentId: string;

View file

@ -3,7 +3,7 @@
import { createContext, useContext, useEffect, useMemo } from 'react'
import type { FC, ReactNode } from 'react';
import { AnalyticsClient } from '../api/analytics-client';
import type { AnalyticsConfig, AnalyticsContext } from '../types';
import type { AnalyticsConfig, AnalyticsContext } from '../api/analytics';
const AnalyticsContextInstance = createContext<AnalyticsContext | null>(null);

View file

@ -40,6 +40,7 @@
"@platform/seo": ["./features/seo/shared/src"],
"@platform/truth-validation": ["./features/truth-validation/shared/src"],
"@platform/webmap": ["./features/webmap/shared/src"],
"@platform/analytics-frontend-admin": ["./features/platform-analytics/frontend-admin/src"],
// === LOCALE FILES ===
"@i18n-locales/*": ["./features/i18n/locales/*"],