SDK Guide
Install and use the harshit-metrics-sdk package with advanced options.
Installation
npm install harshit-metrics-sdkQuick start
import { createMetricsClient } from "harshit-metrics-sdk";
const metrics = createMetricsClient("mtr_your_api_key", {
endpoint: "https://metrics.harshit.page/api/collect",
autoTrackPageviews: true,
});
metrics.track("signup_clicked", {
metadata: {
plan: "pro",
},
});Recommended initialization
Create one singleton client for your app runtime, set shared context once, and reuse it from UI actions.
Advanced capabilities
- event batching with configurable queue size
- retry with exponential backoff
- optional local queue persistence across reloads
- global context and per-event metadata merging
- timing helpers (
startTimer,trackTiming) - lifecycle flush on page hide/unload
API reference (high-level)
createMetricsClient(apiKey, options)metrics.track(name, event)metrics.trackPageview(metadata?)metrics.identify({ userId, traits })metrics.setContext(context)metrics.trackTiming(name, startedAt, event?)metrics.flush()metrics.shutdown()