JavaScript SDK
Add the client, identify your users, and you're live.
- Last reviewed
JavaScript SDK
The JavaScript SDK gives you a lightweight client to add getuserfeedback.com to any browser app.
1. Install
npm install @getuserfeedback/sdk
2. Create the client
Create one client and reuse it across your app.
import { createClient } from "@getuserfeedback/sdk";
const client = createClient({
apiKey: "YOUR_API_KEY",
});
The only required option is apiKey — grab it from Settings → Widget in the
getuserfeedback.com dashboard.
You're live
That's it. The widget is running and surveys will show up based on the targeting rules you set in the getuserfeedback.com dashboard.
3. Identify your users (recommended)
If your app has logged-in users, identifying them unlocks targeting, personalization, and behavioral segmentation.
await client.identify("user_123", {
email: "user@example.com",
plan: "pro",
});
If you don't have a stable user ID yet, traits-only mode also works:
await client.identify({
email: "user@example.com",
});
This step is optional — surveys work fine without it. But with user identity, you can target by plan, role, or behavior, and responses are tied to real people. See Personalization for the full picture.
Call reset() on logout so the previous user's identity doesn't carry over.
Dark mode
The widget automatically matches your app's color scheme. If your app is in dark mode, the widget follows along. If your app doesn't have dark mode, the widget stays light. No configuration needed.
You can force a specific scheme at startup:
const client = createClient({
apiKey: "YOUR_API_KEY",
colorScheme: "dark",
});
Or update it at runtime:
client.configure({ colorScheme: "system" });
See Dark mode for the full story on how detection works.
Privacy & consent
By default, the widget starts with granted consent. If you need GDPR or CCPA
compliance, set defaultConsent to "pending" and update it after the user
makes a choice:
const client = createClient({
apiKey: "YOUR_API_KEY",
defaultConsent: "pending",
});
Then sync with your cookie banner or CMP:
// When the user grants consent:
client.configure({
consent: ["analytics.measurement", "analytics.storage"],
});
// Or deny:
client.configure({ consent: "denied" });
Response collection and imperative flow display are never affected by consent settings — only targeting rules that depend on persisted activity or storage-backed signals.
Going further
- Personalization — targeting, personalization, and behavioral segmentation
- Dark mode — intelligent color scheme detection
- Opening surveys from code — trigger surveys from buttons, menus, or code
- Containers — render inside your own dialog
- JavaScript SDK reference — full API surface