Configuration
Configure the FastStats Web Analytics core and extensions
React and JavaScript use the same core options. Pass them as props to React’s
Analytics component or to JavaScript’s init, createClient, or
WebAnalytics constructor. In Nuxt, place them under faststats.
Core Options
| Option | Type | Default | Description |
|---|---|---|---|
siteKey | string | required | Project key that ties events to your FastStats project |
baseUrl | string | https://metrics.faststats.dev | Endpoint used by analytics and extensions |
debug | boolean | false | Logs SDK transport and extension diagnostics |
trackHash | boolean | false | Includes URL hashes and tracks hash-based route changes |
cookieless | boolean | false | Never stores an anonymous identifier |
consent | "anonymous" | "granted" | "denied" | "granted" | Initial consent mode |
extensions | readonly AnalyticsExtension[] | [] | Optional trackers to start with the client |
The siteKey is public and safe to include in browser code. baseUrl applies
to the core and all built-in extensions.
Extensions
Error tracking, Web Vitals, and session replay are separate, tree-shakeable
imports. Outbound link tracking is part of the core and needs no setup. With React or JavaScript, create each extension and add
it to the extensions array.
import { Analytics } from "@faststats/react";
import { errorTracking } from "@faststats/react/error";
import { sessionReplay } from "@faststats/react/replay";
import { webVitals } from "@faststats/react/web-vitals";
<Analytics
siteKey="your_site_key"
extensions={[
errorTracking(),
webVitals(),
sessionReplay({ recordConsole: true }),
]}
/>;import { init } from "@faststats/web";
import { errorTracking } from "@faststats/web/error";
import { sessionReplay } from "@faststats/web/replay";
import { webVitals } from "@faststats/web/web-vitals";
init({
siteKey: "your_site_key",
extensions: [
errorTracking(),
webVitals(),
sessionReplay({ recordConsole: true }),
],
});Nuxt uses a serializable extensions object and loads the selected extensions
for you.
export default defineNuxtConfig({
modules: ["@faststats/nuxt"],
faststats: {
siteKey: "your_site_key",
extensions: {
errorTracking: true,
webVitals: true,
sessionReplay: { recordConsole: true },
},
},
});Use true for default extension settings. errorTracking and sessionReplay
also accept an options object; webVitals has no options. See Error Tracking,
Web Vitals, and
Session Replay for their options.
Lifecycle
init starts the JavaScript shared client immediately. createClient and the
WebAnalytics constructor create independent clients that must be started
explicitly.
import { createClient } from "@faststats/web";
const analytics = createClient({ siteKey: "your_site_key" });
analytics.start();
// Later, remove listeners and stop extensions.
analytics.destroy();React and Nuxt own this lifecycle and start their clients automatically.
Custom Extensions
An extension is an object with a name and a setup function. setup receives
a context with the client’s settings and an on method for lifecycle hooks, and
may return a cleanup function.
import type { AnalyticsExtension } from "@faststats/web";
export function diagnostics(): AnalyticsExtension {
return {
name: "diagnostics",
setup(context) {
context.on("pageChange", ({ url }) => {
if (context.debug) console.debug("page changed", url);
});
return ({ discard }) => {
// Flush buffered data, or drop it when `discard` is true.
};
},
};
}The context exposes siteKey, baseUrl, debug, trackHash,
isCookieless(), and on(hook, handler).
| Hook | Payload | When it fires |
|---|---|---|
pageChange | { url } | After a client-side navigation to a new page |
pageHide | { persisted, terminal } | When the page is hidden or unloaded |
pageShow | { persisted } | When the page is shown, including from the bfcache |
consentChange | { cookieless } | When consent changes while tracking stays enabled |
error | { error } | When reportError is called |
Extensions start when tracking starts and stop when the client is destroyed or
consent is denied. Cleanup receives discard: true when consent was revoked.
Errors thrown from setup or a hook are caught and do not affect analytics.