Configuration
init(config) accepts a single configuration object. Only apiKey and projectId are required; every other field has a sensible default.
interface TreliqConfig {
apiKey: string; // Required. tk_live_… or tk_test_…
projectId: string; // Required. Project UUID
apiUrl?: string; // Default: window.location.origin
sseUrl?: string; // Optional. Enables WebSocket streaming.
autoTrack?: boolean; // Default: false. Track SPA route changes as $page_view.
batchSize?: number; // Default: 10
batchInterval?: number; // Default: 2000 (ms)
inApp?: {
enabled?: boolean; // Default: true
position?: 'top-left' | 'top-right'
| 'bottom-left' | 'bottom-right'; // Default: 'bottom-right'
};
onError?: (error: Error) => void;
debug?: boolean; // Auto-true for tk_test_… keys
}
Required
apiKey
A publishable API key from your project settings. See Authentication.
projectId
The project UUID. The SDK isolates state per project — you can run multiple instances in the same page if you have a multi-project setup.
Connectivity
apiUrl
Base URL for HTTP requests. Defaults to the page’s origin, which works when your Treliq deployment is reverse-proxied behind the same domain as your app. Override for cross-origin setups:
init({ apiKey, projectId, apiUrl: 'https://api.yourdomain.com' });
sseUrl
Base URL for the WebSocket streaming endpoint. When set, the SDK opens a persistent connection to ${sseUrl}/v1/sse/stream?session_token=… after identify() and receives in-app content in real time. When omitted, the SDK falls back to polling every 30 seconds.
init({ apiKey, projectId, sseUrl: 'https://stream.yourdomain.com' });
The SDK auto-converts http:// → ws:// and https:// → wss://.
Event batching
batchSize (default 10)
Maximum events held in memory before forcing a flush.
batchInterval (default 2000 ms)
How often the queue flushes regardless of size. Lower values reduce latency but increase request volume.
init({
apiKey, projectId,
batchSize: 25, // Send larger batches
batchInterval: 5000, // Every 5 seconds
});
To bypass batching for a single event, pass { immediate: true } to track() instead of tuning the global config.
Auto-tracking
autoTrack (default false)
When true, the SDK automatically fires a $page_view event on:
popstate(back/forward navigation)history.pushState(programmatic navigation)history.replaceState(route replacement)
Each event includes url, path, and title properties. Turn it off if your framework already tracks page views.
In-app content
inApp.enabled (default true)
Master switch. Set to false to suppress all in-app rendering — the SDK still receives content over the wire but nothing is displayed.
inApp.position (default 'bottom-right')
Anchor for banners and popovers. Tooltips and modals position themselves relative to a target element and ignore this option.
init({
apiKey, projectId,
inApp: { position: 'top-right' },
});
Error handling
onError
Callback invoked for every recoverable error inside the SDK — failed network calls, malformed responses, etc. The SDK never throws from the public API except identify(); everything else routes through onError.
init({
apiKey, projectId,
onError: (err) => Sentry.captureException(err),
});
debug
Forces verbose logging on or off. By default, debug logging is on for keys starting with tk_test_ and off for live keys.
init({ apiKey, projectId, debug: true }); // Always log, regardless of key