API Reference
flush & Lifecycle
Force-flush the outbound event queue, plus other lifecycle helpers — getClient, requireClient, and the testing reset.
flush#
typescript
function flush(): Promise<void>;Force-flushes the outbound queue. The returned Promise resolves when delivery attempts complete (whether they succeeded or failed). Reliable already flushes opportunistically on visibilitychange and pagehide, so manual flushing is rarely needed — but useful for explicit checkpoints.
typescript
import { flush } from '@reliableapp/frontend-core';
// Before logging the user out
async function logout() {
await flush(); // make sure the session ends with all events delivered
await api.logout();
window.location.href = '/login';
}
// Before client-side navigation that you want to be a clean break
await flush();
router.push('/different-app-section');getClient#
typescript
function getClient(): ReliableClient | null;Returns the active client, or null if init() hasn't been called. Useful for guarded access in code that can run before or after init.
typescript
import { getClient } from '@reliableapp/frontend-core';
const client = getClient();
client?.addBreadcrumb({ category: 'app', message: 'lazy module loaded' });track#
typescript
client.track(eventName: string, properties?: Record<string, unknown>): void;Track a custom business or product event. Available on the client object (not as a top-level export).
typescript
const client = getClient();
client?.track('subscription_upgraded', {
from: 'free',
to: 'pro',
amount_usd: 29,
});Lifecycle summary#
text
init(config) ← exactly once, at app startup
↓
identify(user) ← optionally, after login
setTag / setTags ← optionally, anytime
addBreadcrumb ← optionally, throughout
captureException ← optionally, in catch blocks
captureMessage ← optionally, for soft signals
↓
flush() ← optionally, at clean-break points
↓
(page unload) ← auto-flush via visibilitychangeAuto-flush
On
visibilitychange (tab hidden) and pagehide, the SDK uses navigator.sendBeacon to flush in-flight events before the page unloads. This is more reliable than a regular fetch — the browser guarantees the request will be sent even if the tab is closing.