Consent and Cookieless

Run analytics with or without stored identifiers

This is no legal advice. Consult a lawyer for your specific use case.

The SDK supports cookieless mode and three consent states: pending, granted, and denied. Switch modes at runtime with setConsentMode, optIn, or optOut.

How Identifiers Work

In the normal mode the SDK keeps an anonymous id in localStorage and a session in storage so returning visits and sessions can be measured. In cookieless mode no anonymous id is stored and events are sent without a user id, which means visitors cannot be recognized across reloads.

Cookieless Mode

Set cookieless to true to never store an identifier.

<Analytics siteKey="your_site_key" cookieless />
nuxt.config.ts
faststats: {
	siteKey: "your_site_key",
	cookieless: true,
}
new WebAnalytics({ siteKey: "your_site_key", cookieless: true });

When you use a consent banner, start in pending and update the mode once the user decides. There are three modes.

ModeMeaning
pendingThe user has not chosen yet
grantedThe user accepted, the SDK stores identifiers
deniedThe user declined, the SDK runs cookieless

While the mode is pending the SDK runs cookieless by default, so you can still count page views without storing anything. Set pendingBehavior to "disabled" if you prefer to send nothing at all until consent.

new WebAnalytics({
	siteKey: "your_site_key",
	consent: { mode: "pending", pendingBehavior: "anonymous" },
});

Call optIn or optOut from your banner buttons, or call setConsentMode for full control. The SDK switches storage behavior right away and tells the replay and other trackers about the change.

import { optIn, optOut } from "@faststats/react";

<button type="button" onClick={() => optIn()}>Accept</button>
<button type="button" onClick={() => optOut()}>Decline</button>
import { optIn, optOut, setConsentMode } from "@faststats/web";

optIn(); // same as setConsentMode("granted")
optOut(); // same as setConsentMode("denied")
setConsentMode("pending");

You can call setConsentMode, optIn or optOut before the instance has started. The chosen mode is remembered and applied as soon as tracking begins.

In React you can also drive the mode through the consent.mode prop. When the prop changes the component updates the running instance for you.

<Analytics siteKey="your_site_key" consent={{ mode: consentState }} />

On this page