Skip to content

Tracker

The tracker is a lightweight JavaScript library that collects page views, custom events, and Web Vitals from your site, and sends them to your yawa server.

Add the tracker to your website or frontend app:

Terminal window
pnpm add yawa-tracker

Initialize the lib once when your app loads:

import { init } from "yawa-tracker";
const cleanup = init({
serverUrl: "https://your-yawa-server.com",
});

This automatically tracks page views on load and navigation (SPA-friendly via history.pushState and popstate).

To track a custom event, call track with a name and optional metadata:

import { track } from "yawa-tracker";
track({ name: "signup", metadata: { plan: "pro" } });

Keys and values must be strings, with a maximum of 10 keys and 200 characters per key/value.

Core Web Vitals (CLS, FCP, INP, LCP, TTFB) can also be collected by enabling the option when initializing the tracker:

import { init } from "yawa-tracker";
const cleanup = init({
serverUrl: "https://your-yawa-server.com",
webVitals: true,
});
FunctionDescription
init(options)Initialize the tracker. Returns a cleanup function.
visit()Fire-and-forget page view tracking.
visitAsync()Async page view tracking.
track(data)Fire-and-forget custom event.
trackAsync(data)Async custom event.
OptionRequiredDescription
serverUrlYesURL of your yawa server.
webVitalsNoEnable Web Vitals tracking. Defaults to false.