This monorepo contains the official Klime SDKs for JavaScript environments.
| Package | Description | npm |
|---|---|---|
| @klime/browser | Browser SDK for vanilla JavaScript apps | npm install @klime/browser |
| @klime/node | Node.js SDK for server-side tracking | npm install @klime/node |
Coming soon: @klime/react and @klime/nextjs
- Browser apps: Use
@klime/browser- includes automatic browser context (userAgent, locale, timezone) and page unload handling - Node.js servers: Use
@klime/node- includes graceful shutdown on SIGTERM/SIGINT
import { KlimeClient } from "@klime/browser";
const client = new KlimeClient({
writeKey: "your-write-key",
});
// Identify a user
client.identify("user_123", { email: "user@example.com" });
// Track an event
client.track(
"Button Clicked",
{ buttonName: "Sign up" },
{ userId: "user_123" }
);
// Associate user with a group and set group traits
client.group(
"org_456",
{ name: "Acme Inc", plan: "enterprise" },
{ userId: "user_123" }
);
// Or just link the user to a group (if traits are already set)
client.group("org_456", null, { userId: "user_123" });const { KlimeClient } = require("@klime/node");
const client = new KlimeClient({
writeKey: "your-write-key",
});
// Identify a user
client.identify("user_123", { email: "user@example.com" });
// Track an event
client.track("API Request", { endpoint: "/users" }, { userId: "user_123" });
// Associate user with a group and set group traits
client.group(
"org_456",
{ name: "Acme Inc", plan: "enterprise" },
{ userId: "user_123" }
);
// Or just link the user to a group (if traits are already set)
client.group("org_456", null, { userId: "user_123" });
// Graceful shutdown
process.on("SIGTERM", async () => {
await client.shutdown();
process.exit(0);
});Both SDKs share these core features:
- Automatic Batching: Events are batched and sent every 2 seconds or when batch reaches 20 events
- Automatic Retries: Failed requests retry with exponential backoff
- Zero Dependencies: Uses only native APIs (fetch in browsers, fetch/https in Node.js)
- TypeScript Support: Full type definitions included
- Universal Module Support: Works with ESM (
import) and CommonJS (require) out of the box
- Automatic browser context (userAgent, locale, timezone)
- Page unload handling (
beforeunloadevent) crypto.randomUUID()with fallback
- Process exit handling (SIGTERM/SIGINT)
- Fallback to
https/httpmodules for Node.js < 18
This monorepo uses pnpm workspaces.
# Install dependencies
pnpm install
# Build all packages
pnpm build
# Clean all packages
pnpm cleanSee the individual package READMEs for detailed API documentation:
MIT