Docs

JavaScript / TypeScript SDK

The official logit npm package for Node.js, Deno, Bun, and any JS/TS runtime.


Installation

bash
npm install logit

Initialization

ts
import { init } from "logit";

const logit = init({
  token: process.env.LOGIT_API_KEY!,
  // baseUrl: "https://api.logit.now", // optional override
  // projectId: "proj_xxx",            // optional, inferred from token
});

Create one instance per project and reuse it across your app. The client is stateless and safe to share across requests.

logit.now()

ts
await logit.now(channel: string, data: LogEventData): Promise<LogitResponse>
// Returns: { success: boolean, id: string, trackingId: string }

LogEventData reference

FieldTypeRequiredDescription
eventstringYesShort human-readable title
descriptionstringNoOne-line context string
iconstringNoEmoji shown in the inbox
notifybooleanNoSend a push notification (default: false)
tagsRecord<string, any>NoKey-value pairs for filtering
metadataRecord<string, any>NoArbitrary JSON object
trackingIdstringNoFirst event's id — links events into a timeline
inboxbooleanNoShow in realtime inbox (default: true)

Timelines (trackingId)

Use trackingId to group related events into a single timeline:

ts
// First event — creates a new timeline
const first = await logit.now("payments", {
  event: "Payment started",
  metadata: { orderId: "ord_123" },
});

// Subsequent events — pass first event's id
await logit.now("payments", {
  event: "Payment processing",
  trackingId: first.id,
});

await logit.now("payments", {
  event: "Payment succeeded",
  trackingId: first.id,
  notify: true,
});

Error handling

ts
import { init, LogitError } from "logit";

try {
  const res = await logit.now("signups", { event: "User signed up" });
  console.log(res.id, res.trackingId);
} catch (error) {
  if (error instanceof LogitError) {
    console.error(error.message, error.statusCode, error.details);
  } else {
    throw error;
  }
}

TypeScript

The SDK ships with full TypeScript definitions — no @types package needed.

ts
import type { LogEventData } from "logit";

const payload: LogEventData = {
  event: "Trial started",
  icon: "🎁",
  notify: true,
  tags: { plan: "pro" },
};

await logit.now("trials", payload);