Events
Automatic tracking and custom events
The core SDK automatically sends pageview and page_leave events. Add the
outbound-links extension to capture outbound_link, and use track for your
own events.
Automatic Tracking
| Event | When it fires |
|---|---|
pageview | On the first visible load and each client-side route change |
page_leave | When the page unloads or client-side navigation leaves the route |
outbound_link | When the optional extension sees a click to another host |
Page views include the path, sanitized URL, referrer, page title, and UTM parameters. Page-leave events include time on page and session duration.
Single-page navigation is detected through the History API, so pushState,
replaceState, and back/forward navigation create page views automatically.
Set trackHash: true for hash-based routers.
Outbound Links
Outbound link tracking is opt-in so applications that do not need it do not ship its click listener.
import { init } from "@faststats/web";
import { outboundLinks } from "@faststats/web/outbound-links";
init({
siteKey: "your_site_key",
extensions: [outboundLinks()],
});For React, import from @faststats/react/outbound-links. In Nuxt, set
faststats.extensions.outboundLinks to true.
Custom Events
Call track with a name and an optional object of JSON-serializable properties.
import { useTrack } from "@faststats/react";
const track = useTrack();
track("signup", { plan: "pro", source: "hero" });<script setup lang="ts">
const { $faststats } = useNuxtApp();
$faststats.track("signup", { plan: "pro", source: "hero" });
</script>import { track } from "@faststats/web";
track("signup", { plan: "pro", source: "hero" });The SDK trims names and ignores empty names. It reserves pageview,
page_leave, error, and outbound_link for built-in events.
Good Practices
Keep a small, stable set of event names and put changing details in properties.
track("checkout", { step: "cart" });
track("checkout", { step: "shipping" });
track("checkout", { step: "payment" });