Browser SDK for heat-tracker session events and heatmaps
npm install @m-software-engineering/heat-sdkBrowser SDK for capturing session events and generating heatmaps with the heat-tracker collector.
``bash`
npm install @m-software-engineering/heat-sdkor
pnpm add @m-software-engineering/heat-sdkor
yarn add @m-software-engineering/heat-sdk
`ts
import { init } from "@m-software-engineering/heat-sdk";
const tracker = init({
endpoint: "https://collector.example.com/ingest",
projectKey: "your-project-key"
});
tracker.track("signup", { plan: "pro" });
await tracker.flush();
`
`tsx
import { useEffect } from "react";
import { init } from "@m-software-engineering/heat-sdk";
export function App() {
useEffect(() => {
const tracker = init({
endpoint: "https://collector.example.com/ingest",
projectKey: "your-project-key"
});
return () => void tracker.shutdown();
}, []);
return
$3
`ts
import { Component, OnDestroy, OnInit } from "@angular/core";
import { init, type Tracker } from "@m-software-engineering/heat-sdk";@Component({ selector: "app-root", template: "
My App" })
export class AppComponent implements OnInit, OnDestroy {
private tracker?: Tracker; ngOnInit() {
this.tracker = init({
endpoint: "https://collector.example.com/ingest",
projectKey: "your-project-key"
});
}
ngOnDestroy() {
void this.tracker?.shutdown();
}
}
`API
$3
Creates a tracker instance.
Required:
-
endpoint: Full URL to the collector ingest endpoint (e.g. /ingest).
- projectKey: The project key used by the collector.Optional:
-
app, session, batch, sampling, privacy, capture$3
-
identify(userId, traits?)
- setAuthToken(jwt | null)
- track(name, props?)
- flush()
- shutdown()Notes
- This SDK is intended for browsers. Calling
init on the server will throw.
- When using JWT auth, call setAuthToken` to attach the token to ingest requests.