Initialize
Boot the ChirpBack SDK with your project credentials. Call this once, as early as possible.
Chirp.init is the first call you make. It applies consent, loads your project's configuration, and prepares the SDK to handle surveys, announcements, and feedback.
Signature
Chirp.init(config: ChirpInitConfig): Promise<void>
interface ChirpInitConfig {
clientId: string; // Required. From Project Settings → Developer
consent?: { state: ConsentState; source?: ConsentSource };
onReady?: () => void;
}Minimum usage
import { Chirp } from "chirpback";
await Chirp.init({
clientId: "your-client-id",
consent: { state: "granted" },
});Passing consent: { state: 'granted' } makes the SDK active immediately — surveys, announcements, and feedback all work on the next call. If you have your own CMP (OneTrust, Cookiebot, etc.) or need GDPR / CCPA / GPC handling, leave consent out and manage it via Chirp.consent instead.
What happens on init
- The SDK applies the consent state you passed (or reads the saved one from local storage).
- If consent is granted, it fetches your project's bootstrap payload — surveys, announcements, and feature flags scoped to the anonymous device.
- It emits the
readyevent when the runtime is fully prepared.
Chirp.on("ready", ({ sdkVersion }) => {
console.log(`ChirpBack v${sdkVersion} ready`);
});ready replays for handlers attached after init resolves, so you don't have to race the listener registration.
Gotchas
Call init exactly once. A second call returns the same promise and logs
a warning. It does not re-fetch your project config.
- If the user previously revoked consent and you don't pass a new state, the SDK initializes in a teardown state — no events fire, no surfaces show — until consent is re-granted.
initreturns a Promise, but you don't have toawaitit. Calls toidentify,survey.open, etc. are buffered and run after init resolves.
Where to put it
Put init somewhere that runs once per page load, as early as you can:
| Framework | Where |
|---|---|
| Next.js App Router | A "use client" component mounted in the root layout, inside useEffect |
| Next.js Pages Router | pages/_app.tsx inside useEffect |
| Remix | app/root.tsx inside useEffect |
| Vite / CRA | src/main.tsx next to ReactDOM.createRoot |
| Script tag | Right after the install snippet |
Next steps
- Identify users
- Consent — when to skip the inline
consentand use the consent API instead - Surveys