TrichiData

Browser SDK

Track events from vanilla JavaScript and browser frameworks with @trichidata/browser.

Use this guide for browser applications — vanilla JavaScript and frameworks like Vue, Svelte, and Angular.

For session flow and event schemas, see the REST API. For a guided first integration, see Quickstart.

Install

npm install @trichidata/browser

@trichidata/browser provides TrichiDataClient configured for browser environments. The client uses credentials: 'include' so the browser stores the sdk_session cookie automatically after init().

Usage

import { TrichiDataClient } from '@trichidata/browser';

const client = new TrichiDataClient({
  apiKey: 'prj_ak_xxxxxxxxxxxx',
});

await client.init(); // device + tracking cookies under the hood

await client.identify({ userId: 'usr_7f3a9b2c', appVersion: '2.4.1' });

await client.page(); // page context filled from window/document
await client.productViewed({ productId: 'sku_1', name: 'Shoes', price: 99, currency: 'USD' });
await client.trackCustom('promo_banner_click', { slot: 'hero' });

init() collects device info and tracking automatically: _ga / _fbp / _fbc / fbclid when present; otherwise the SDK generates a GA-like clientId. You can override with init({ device, tracking }).

Helpers

HelperDescription
getPageContext()Current page title, url, referrer

Client methods

MethodDescription
init(params?)Start a session (init_sdk)
identify({ userId?, appVersion? })Associate session context — at least one field required
page / productViewed / …Typed helpers for reserved event names
trackCustom(name, properties?)Custom (non-reserved) event

See REST API for reserved eventName values and properties schemas.

See also

On this page