A data visualization dashboard for the GistPin platform, providing insights into gist activity, user engagement, and geographic distribution.
- Quick Start
- Environment Variables
- Available Scripts
- Architecture
- Charts & Components
- API Documentation
- Troubleshooting
- Node.js 18+
- npm
cd analytics
npm installnpm run devOpen http://localhost:3000 to view the dashboard.
Create a .env.local file in the analytics/ directory:
# GistPin Backend API base URL
NEXT_PUBLIC_API_URL=http://localhost:3000
# Optional: override mock data record count
NEXT_PUBLIC_MOCK_DATA_COUNT=500No environment variables are required for local development — all data is generated client-side via mock utilities.
Run from inside the analytics/ directory:
| Command | Description |
|---|---|
npm run dev |
Start development server |
npm run build |
Build for production |
npm run start |
Serve the production build |
npm run lint |
Run ESLint |
npm run typecheck |
TypeScript type check |
Tech stack: Next.js 15 (App Router) · Chart.js + react-chartjs-2 · TanStack Query · TypeScript
analytics/
├── app/
│ ├── page.tsx # Main dashboard
│ ├── forecast/ # Forecast page
│ ├── funnel/ # User funnel page
│ ├── segments/ # Audience segments
│ ├── campaigns/ # Campaign analytics
│ ├── moderation/ # Content moderation
│ ├── comparison/ # Period comparison
│ ├── projections/ # Growth projections
│ ├── reports/ # Report builder
│ ├── experiments/ # A/B experiments
│ ├── query-builder/ # Custom query builder
│ └── ... # Other feature pages
├── components/
│ ├── charts/ # Chart components
│ ├── ui/ # Shared UI components
│ ├── DateRangePicker.tsx # Date range selector with presets
│ └── KPICard.tsx # KPI metric cards
├── hooks/
│ └── useDateRange.ts # Date range state + URL persistence
├── lib/
│ ├── analytics-data.ts # Mock data generators
│ ├── analytics-queries.ts # TanStack Query hooks
│ ├── anomaly.ts # Anomaly detection
│ ├── export.ts # CSV export utilities
│ └── utils.ts # Shared utilities
└── types/
└── index.ts # Shared TypeScript interfaces
All chart data is generated client-side via mock utilities in lib/analytics-data.ts. TanStack Query wraps each data source with a simulated async delay. No network requests are made in the current implementation.
| Component | Description |
|---|---|
KPICard |
Key metric cards (total gists, active users, etc.) |
LiveGistCounter |
Real-time gist counter simulation |
UserAreaChart |
New vs returning users over 90 days |
DailyGistsChart |
Daily gist volume — last 30 days |
ScatterChart |
Gist age vs. engagement with regression trendline |
RadarChart |
Platform usage comparison (this month vs. last) |
CategoryPieChart |
Gist category distribution (8 segments, interactive legend) |
EngagementDonutChart |
Engagement breakdown: Views, Likes, Shares, Comments |
LocationTable |
City-level activity trends with sparklines |
Preset buttons: Today, Last 7 days, Last 30 days, Custom.
Custom mode shows two <input type="date"> fields. Selected range is persisted in URL params (?preset=7d&from=...&to=...).
const { range, preset, applyPreset } = useDateRange();
// range: { from: 'YYYY-MM-DD', to: 'YYYY-MM-DD' }
// preset: 'today' | '7d' | '30d' | 'custom'
// applyPreset(preset, customRange?)State is synced to/from URL search params so ranges survive page refresh and are shareable.
The dashboard is designed to consume the GistPin REST API. The backend exposes:
Returns gists near a coordinate.
| Parameter | Required | Default | Description |
|---|---|---|---|
lat |
yes | — | Latitude (decimal degrees) |
lon |
yes | — | Longitude (decimal degrees) |
radius |
no | 500 | Search radius in meters |
limit |
no | 20 | Max records per page |
cursor |
no | — | Pagination cursor (base64) |
Example response:
{
"data": [
{
"id": "uuid",
"content": "Suya spot open till midnight",
"location_cell": "s17eb4n",
"content_hash": "Qm...",
"created_at": "2026-03-28T10:00:00Z",
"distance": 42.5
}
],
"cursor": "eyJpZCI6..."
}Returns a single gist by UUID.
Returns backend and database status.
Full interactive API docs at http://localhost:3000/api/docs when the backend is running.
Chart does not render / blank page
Each chart file calls ChartJS.register(...) at module level. If you add a new chart type, register its elements/scales there. All chart files must use the 'use client' directive.
@/ import paths not resolving
The @/ alias maps to the analytics/ root. Verify tsconfig.json contains:
{ "compilerOptions": { "paths": { "@/*": ["./*"] } } }Module not found: react-chartjs-2
Run npm install inside the analytics/ directory. Dependencies are not hoisted from the repo root.
Backend not connecting
- Start the backend:
cd ../Backend && npm run start:dev - Set
NEXT_PUBLIC_API_URLin.env.localto match the backend port - CORS is enabled for all origins in development