Skip to content

sdk-core (advanced)

trackScene is the one-call path. When you need finer control — a custom transport, a beforeSend hook to inspect/modify/drop events, or registering multiple collectors on one session — build the UptimizrClient yourself and attach a connector’s collector with client.use(...).

import { UptimizrClient } from "@uptimizr/sdk-core";
import { babylonCollector, readDeviceCaps, readSceneMeta } from "@uptimizr/babylon";
const client = new UptimizrClient({
projectId: "your-project-id",
endpoint: "https://collect.example.com",
// Inspect, modify, or drop each event before it is queued. Return null to drop.
beforeSend: (event) => (event.type === "pointer_move" ? null : event),
});
client.use(babylonCollector({ scene }));
client.start({ device: readDeviceCaps(scene), scene: readSceneMeta(scene) });
// Same API as the trackScene return value:
client.track("add_to_cart", { sku: "ABC-123" });
client.setScene("level-2");
await client.stop("manual");
OptionDefaultEffect
projectIdYour project id (required).
endpointCollector base URL (required).
batchSize20Events per network flush.
flushIntervalMs5000Max time between flushes (0 disables the timer).
beforeSendPer-event hook; return null to drop. Runs after the envelope is filled in.
transportbeacon → fetchCustom delivery (e.g. to observe sends).
offloadmainRun batching on the main thread or a worker.
disabledfalseCollect nothing (e.g. honor Do-Not-Track).

beforeSend runs on every event after the envelope is filled in; use it to redact fields or sample a noisy channel. It is not exposed through trackScene — reach for the custom-client path when you need it.

user is opt-in and Uptimizr never derives it — you pass it explicitly and own the anonymization. user.id MUST be pseudonymous or hashed (never an email, username, or raw account id); omit it to stay fully anonymous. user.traits is an open map of non-identifying values for segmentation.

import { createHash } from "node:crypto"; // server-side, or hash before it reaches the client
const hashedUserId = createHash("sha256").update(`${rawUserId}:${dailySalt}`).digest("hex");
trackScene(scene, {
projectId,
endpoint,
user: { id: hashedUserId, traits: { plan: "pro", locale: "en-US" } },
});