Harshit Metrics

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?

CategoryEvents
Page analyticsPageviews, SPA navigation, scroll depth, top pages
User behaviorClicks, form submissions, outbound links, engagement time
PerformanceWeb Vitals (LCP, FID, CLS, FCP, TTFB)
ErrorsUnhandled exceptions, promise rejections
BusinessRevenue events, feature flag exposures, custom events
IdentityUser identification, group analytics, UTM attribution

Quick Start

npm install harshit-metrics
import { 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.

On this page