Skip to main content
@bilyai/js is the official Bily browser SDK. It provides ESM, CommonJS, and TypeScript exports with no runtime dependencies.

Install

npm install @bilyai/js
The package supports Node.js 16 or newer for build tooling. Every public call is safe during server rendering, but browser tracking starts only in a browser document.

Methods

ExportReturn typePurpose
init(options)voidLoad Bily from an exact script URL
track(event, payload?)voidQueue or send an event
ready()Promise<void>Verify that Bily finished loading
getBilyTrackingId()string | nullRead or create the Bily browser identifier

Type exports

import type {
  BilyAddress,
  BilyClient,
  BilyEvent,
  BilyInitOptions,
  BilyLegacyInitOptions,
  BilyOrder,
  BilyPayload,
  BilyProduct,
  KnownBilyEvent,
} from "@bilyai/js";
See event names and the payload types for their complete shapes.

Basic lifecycle

analytics.ts
import { init, ready, track } from "@bilyai/js";

init({
  scriptUrl: "https://tracking.example.com/b.js?shop=store.example.com",
});

track("workspace_created", { workspace_id: "workspace_456" });

try {
  await ready();
} catch (error) {
  console.error("Bily failed to load", error);
}
track() can run before ready() resolves. The SDK keeps early calls in a bounded queue and delivers them in order after loading.
Do not add a raw script tag when an application uses the SDK. init() manages the browser script for you.