Feature Flags

Evaluate FastStats feature flags in the browser

Feature Flags are still in Private Preview. Please contact staff if you would like to try them out.

Evaluate a flag for the current visitor with useFlag in React or checkFeatureFlag on the SDK instance. The response includes the value and, for multivariate flags, the chosen variant.

React Hook

The useFlag hook is the simplest way to read a flag in React. It returns the value together with loading and error state, and a refetch helper.

"use client";

import { useFlag } from "@faststats/react";

export function NewDashboard() {
	const { value, isLoading } = useFlag("new_dashboard");

	if (isLoading) return <Spinner />;
	if (value === "true") return <DashboardV2 />;
	return <DashboardV1 />;
}

The hook needs an active Analytics component on the page. It uses the current visitor identity to evaluate the flag.

Hook Options

const { value, error, refetch } = useFlag("pricing_test", {
	attributes: { country: "DE", plan: "pro" },
	externalId: "user_123",
	skip: false,
});
OptionTypeDescription
attributesRecord<string, unknown>Extra context used by the targeting rules
externalIdstringEvaluate for a specific user instead of the visitor
skipbooleanSkip the request, for example until you are ready

Result Shape

FieldTypeDescription
valuestringThe flag value, defaults to "false"
variantKeystringThe chosen variant key when the flag is a test
variantValuestringThe value attached to that variant
isLoadingbooleanTrue while the request is in flight
errorError | nullSet when the evaluation failed
refetch() => voidRun the evaluation again

Outside React

When you do not use React, evaluate a flag through the instance.

import { getInstance } from "@faststats/web";

const result = await getInstance()?.checkFeatureFlag("new_dashboard", {
	country: "DE",
});

if (result?.value === "true") {
	// turn the feature on
}

Values are Strings

Flag values come back as strings, so a boolean flag returns "true" or "false". Compare against the string form rather than a real boolean.

if (value === "true") {
	// correct
}

Custom Flags Endpoint

Flag checks go to https://flags.faststats.dev by default. To send them through your own domain, set featureFlagsBaseUrl.

On this page