Overview
Harshit Metrics — a full-featured, self-hostable analytics platform with a TypeScript SDK.
What is Harshit Metrics?
Harshit Metrics is a privacy-first, self-hostable analytics platform that gives you full control over your data. It ships with:
- A TypeScript SDK (
harshit-metrics) with auto-tracking for pageviews, clicks, scroll depth, errors, web vitals, and more - A REST API for event ingestion and dashboard data
- A real-time dashboard with traffic timelines, referrers, browser/device breakdowns, session stats, and event feeds
- API-key isolation per project for clean multi-app attribution
- MongoDB storage with optimized aggregation pipelines
Architecture
┌──────────────┐ POST /api/collect ┌──────────────┐
│ Your App │ ──────────────────────► │ Metrics API │
│ (SDK) │ x-api-key header │ (Next.js) │
└──────────────┘ └──────┬───────┘
│
▼
┌──────────────┐
│ MongoDB │
└──────┬───────┘
│
▼
┌──────────────┐
│ Dashboard │
│ (Next.js) │
└──────────────┘What Can You Track?
| Category | Events |
|---|---|
| Page analytics | Pageviews, SPA navigation, scroll depth, top pages |
| User behavior | Clicks, form submissions, outbound links, engagement time |
| Performance | Web Vitals (LCP, FID, CLS, FCP, TTFB) |
| Errors | Unhandled exceptions, promise rejections |
| Business | Revenue events, feature flag exposures, custom events |
| Identity | User identification, group analytics, UTM attribution |
Quick Start
npm install harshit-metricsimport { createMetricsClient } from "harshit-metrics";
const metrics = createMetricsClient("mtr_your_api_key", {
autoTrackPageviews: true,
autoTrackErrors: true,
autoTrackWebVitals: true,
});→ Continue to Getting Started for the full setup guide.