Track Events

Events are the fuel of every Treliq workflow. track() sends a named event with optional properties to the engine, where it can trigger new workflow runs or advance existing ones waiting on that event.

Signature

track(
  eventName: string,
  properties?: Record<string, unknown>,
  options?: { immediate?: boolean },
): void

track() is synchronous — it returns immediately after queuing. Errors are surfaced via onError, never thrown.

Basic usage

treliq.track('checkout_started', {
  cart_value: 79.99,
  currency: 'USD',
  item_count: 3,
});

Property values can be strings, numbers, booleans, arrays, or nested objects. Keep payloads under a few KB; very large properties can be truncated server-side.

Naming conventions

Pick a convention and stick to it across your codebase. Snake_case is recommended:

checkout_started
trial_extended
feature_enabled
invite_sent

Avoid:

  • Spaces — 'checkout started' works but is harder to query
  • Mixed casing — 'CheckoutStarted', 'checkoutStarted', 'Checkout Started' all become distinct events
  • Versioning in the name — 'checkout_started_v2' fragments your data; add a version property instead

Reserved prefix: events starting with $ are SDK-emitted (e.g. $page_view). Avoid that prefix in your own events.

Batching

By default, events are queued and flushed in batches of 10 every 2 seconds. This keeps network usage low without losing events. The default tuning is right for most apps; see Configuration to override batchSize and batchInterval.

To force-send a single event right now, pass immediate: true:

treliq.track('payment_completed', { amount: 79.99 }, { immediate: true });

Use immediate for events that must reach the server before the page might unload (last action before redirect, conversion completion).

Offline buffering

When navigator.onLine is false, events are queued in memory. The SDK listens for the online event and automatically flushes the buffer once connectivity returns. No explicit retry logic is needed in your code.

Buffered events live in memory only. They do not survive a page reload.

Auto-tracked events

Setting autoTrack: true in init() adds a single auto-tracked event:

EventWhen it firesProperties
$page_viewInitial load + every pushState/replaceState/popstateurl, path, title

This works out of the box for SPAs that use HTML5 history (React Router, Vue Router, Next.js App Router). Disable if your framework already emits page views.

Error cases

ErrorCauseRecovery
Treliq: call identify() before track()track() called before identify() resolvedAwait identify() first
Rate limit (HTTP 429)Per-API-key event ceiling exceededSDK swallows the error and surfaces via onError. Reduce volume or upgrade plan.
  • In-App Content — how events trigger banners and modals
  • Errors — handling network and rate-limit failures