Skip to main content
Use track() to record an outcome with a known Bily name or your own non-empty event name.

Send an event

function track(event: BilyEvent, payload?: BilyPayload): void;

Track a known outcome

import { track } from "@bilyai/js";

track("Product Viewed", {
  products: [
    {
      id: "product_123",
      name: "Everyday Tee",
      price: 39,
      currency: "USD",
    },
  ],
});

Track an application outcome

track("integration_connected", {
  integration_id: "integration_456",
  integration_type: "crm",
});
Use stable snake_case names for application events. You still get autocomplete for known Bily names.

Know what Bily adds

When the SDK prepares a browser event, it adds:
  • A Bily browser tracking ID when one is available.
  • An ISO timestamp when ts is not already a string.
  • A generated event ID when event_id is empty or absent.
  • The browser source for the event.
Provide event_id when the same outcome needs one identifier across systems.

Track before loading finishes

Call track() before init() or while Bily loads. The SDK keeps those calls in memory until loading succeeds. The queue holds 100 calls by default. Set a limit from 1 to 1,000 with init({ maxQueueSize }). When the queue is full, the SDK removes the oldest call before it adds the newest.

Handle errors without interrupting the app

  • An empty or whitespace-only event name is ignored.
  • A browser delivery failure does not throw from track().
  • With debug: true, Bily logs a warning for delivery failures without logging the payload.
  • During server rendering, track() is a no-op.

Track only later page views

The first PageView is automatic. Call track("PageView", ...) only after a later client-side route change.
track("PageView", {
  sourceUrl: window.location.href,
  pageTitle: document.title,
});

Event names

Payload types