@tinycrm/sdk
v0.1.1
Published
Lightweight JavaScript SDK for TinyCRM — track events and identify users
Maintainers
Readme
@tinycrm/sdk
Lightweight JavaScript SDK for TinyCRM — track events and identify users from any web app.
- Zero dependencies
- < 2 kB gzipped
- Never throws — errors are silently swallowed and reported via an optional callback
- Events are batched and flushed every 5 s or on page unload (
sendBeacon)
Install
npm install @tinycrm/sdkQuick Start
import { TinyCRM } from "@tinycrm/sdk";
const crm = new TinyCRM("tk_live_your_write_key");
// Identify the current user (sent immediately)
crm.identify("user_123", {
email: "[email protected]",
plan: "pro",
});
// Track events (batched automatically)
crm.track("page_viewed", { page: "/pricing" });
crm.track("button_clicked", { label: "Upgrade" });API
new TinyCRM(writeKey, options?)
| Option | Type | Default | Description |
| --------------- | ---------- | ------------------------------------ | -------------------------------- |
| apiUrl | string | https://app.tinycrm.dev/api/v1 | API base URL |
| flushInterval | number | 5000 | Flush interval in ms |
| batchSize | number | 20 | Max events per batch |
| debug | boolean | false | Enable debug logging |
| onError | function | () => {} | Error callback for debugging |
crm.identify(userId, traits?)
Associates the current user. Sends an identify call immediately (not batched).
crm.track(event, properties?)
Queues an event for batched delivery. Requires identify() to have been called first.
crm.flush()
Force-flushes the event buffer immediately. Returns a Promise<void>.
crm.reset()
Clears the current user identity and event buffer. Call on user logout.
crm.destroy()
Stops the flush timer and flushes remaining events. Call when the SDK is no longer needed.
License
MIT
