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.

Your yawa server also serves the tracker as a static file, which lets you load it with a script tag:

<script type="module" src="https://your-yawa-server.com/static/yawa.js"></script>

This is the simplest option if your site doesn’t have a build step, or you’d rather not add a dependency. It works well for static site generators too. With Astro Starlight, for example, you can add it directly via the head config:

astro.config.mjs
starlight({
head: [
{
tag: "script",
attrs: {
type: "module",
src: "https://your-yawa-server.com/static/yawa.js",
},
},
],
});

The script derives the server URL from where it was loaded, so no further configuration is needed.

If your project uses a bundler, 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",
});
OptionRequiredDescription
serverUrlYesURL of your yawa server.
webVitalsNoEnable Web Vitals tracking. Defaults to false.

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.