Browser Monitoring
Browser SDK
Public surface of @mydle/browser-sdk: init once, emit beacons, flush or stop cleanly. Calling init again replaces the previous instance.
API
import { mydle } from "@mydle/browser-sdk";
mydle.init({ projectKey: "pk_live_…" });
mydle.track("checkout_started", { plan: "pro" });
mydle.captureException(error);
await mydle.flush();
mydle.stop();init— start (or replace) the global client; returns a handle with the same methods.track(name, properties?)— customeventbeacon.captureException(error, context?)—errorbeacon.flush()— await pending batch send.stop()— remove instrumentation and flush sync on teardown.
Options
projectKey/ legacypublicKey— requiredpk_publishable key.endpoint— absolute ingest URL; defaulthttps://www.mydle.app/api/rum/v1/ingest.release— app version / SHA tagged on beacons.sampleRate— session sample fraction0–1(default1).network— capture fetch / XHR (defaulttrue).clicks— automatic click timeline events (defaultfalse).tracePropagation— same-origin W3Ctraceparent+X-Mydle-Session-ID(defaulttrue).batchSize— default10.flushIntervalMs— default5000.
Beacons
Types: pageview, navigation, route_change, visibility, unload, error, vital, session, network, event. Each carries an opaque eventId for retry-safe deduplication. Transport: POST /api/rum/v1/ingest.
Batching
Events buffer in memory (with a bounded offline queue in localStorage) and flush on batch size, interval, visibility hidden / pagehide, or explicit flush().
Legacy
initMydleBrowser({ publicKey, … }) maps to mydle.init with projectKey. Prefer the mydle facade for new code.
Limitations
- Invalid keys warn and return a no-op handle — they do not throw.
- Duplicate
inittears down the previous client (no stacked patches). - Automatic DOM click capture stays opt-in (
clicks: true).