Consent and Cookieless
Run analytics with or without stored identifiers
This is not legal advice. Consult a lawyer for your specific use case.
FastStats supports normal analytics, anonymous cookieless analytics, and fully
disabled collection. Choose an initial mode with consent and change it at
runtime with setConsentMode.
How Identifiers Work
With granted consent, the SDK keeps an anonymous identifier in localStorage
and session state in browser storage. This allows it to recognize returning
visitors and measure sessions. Anonymous mode stores no anonymous identifier,
so visitors cannot be recognized across reloads.
Consent Modes
| Mode | Behavior |
|---|---|
"granted" | Tracks normally and stores an anonymous identifier |
"anonymous" | Tracks without a stored anonymous identifier |
"denied" | Sends no analytics and stops optional extensions |
The default is "granted". If consent has not yet been decided, start with
"anonymous" for cookieless counts or "denied" to send nothing.
<Analytics siteKey="your_site_key" consent="denied" />faststats: {
siteKey: "your_site_key",
consent: "denied",
}init({ siteKey: "your_site_key", consent: "denied" });Set cookieless: true when a site should always avoid stored identifiers. This
forces cookieless collection even while consent is "granted".
Update Consent at Runtime
import { useConsentMode } from "@faststats/react";
const setConsentMode = useConsentMode();
<button onClick={() => setConsentMode("granted")}>Accept</button>
<button onClick={() => setConsentMode("denied")}>Decline</button>React also exports useOptIn and useOptOut as shortcuts for setting
"granted" and "denied".
const { $faststats } = useNuxtApp();
$faststats.setConsentMode("granted");import { setConsentMode } from "@faststats/web";
setConsentMode("granted");Switching to "denied" stops collection and discards data buffered by active
extensions. Switching back starts tracking again. Moving between "anonymous"
and "granted" rotates the page and identity context so the two modes do not
share an anonymous identifier.
Controlled React Consent
The React component applies changes to its consent prop to the active client,
which works well when your consent manager already exposes React state.
<Analytics siteKey="your_site_key" consent={consentMode} />