Browser SDK
Install
import { ReflagClient } from "@reflag/browser-sdk";
const user = {
id: 42,
role: "manager",
};
const company = {
id: 99,
plan: "enterprise",
};
const reflagClient = new ReflagClient({ publishableKey, user, company });
await reflagClient.initialize();
const {
isEnabled,
config: { payload: question },
track,
requestFeedback,
} = reflagClient.getFlag("huddle");
if (isEnabled) {
// Show flag. When retrieving `isEnabled` the client automatically
// sends a "check" event for the "huddle" flag which is shown in the
// Reflag UI.
// On usage, call `track` to let Reflag know that a user interacted with the flag
track();
// The `payload` is a user-supplied JSON in Reflag that is dynamically picked
// out depending on the user/company.
const question = payload?.question ?? "Tell us what you think of Huddles";
// Use `requestFeedback` to create "Send feedback" buttons easily for specific
// flags. This is not related to `track` and you can call them individually.
requestFeedback({ title: question });
}
// `track` just calls `reflagClient.track(<flagKey>)` to send an event using the same flag key
// You can also use `track` on the client directly to send any custom event.
reflagClient.track("huddle");
// similarly, `requestFeedback` just calls `reflagClient.requestFeedback({flagKey: <flagKey>})`
// which you can also call directly:
reflagClient.requestFeedback({ flagKey: "huddle" });Init options
Migrating from Bucket SDK
Flag toggles
Remote config
Server-side rendering and bootstrapping
Init options bootstrapped
Using bootstrappedFlags
Context management
Updating user/company/other context
setContext()
getContext()
Toolbar
Qualitative feedback on beta flags
Automated feedback collection
Reflag feedback UI
Reflag feedback SDK
Reflag feedback API
Tracking flag usage
Event listeners
Zero PII
Use of cookies
TypeScript
Content Security Policy (CSP)
Directive
Values
Reason
Directive
Values
Reason
License
Last updated
Was this helpful?