SDK

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

  1. The SDK applies the consent state you passed (or reads the saved one from local storage).
  2. If consent is granted, it fetches your project's bootstrap payload — surveys, announcements, and feature flags scoped to the anonymous device.
  3. It emits the ready event 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.
  • init returns a Promise, but you don't have to await it. Calls to identify, 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:

FrameworkWhere
Next.js App RouterA "use client" component mounted in the root layout, inside useEffect
Next.js Pages Routerpages/_app.tsx inside useEffect
Remixapp/root.tsx inside useEffect
Vite / CRAsrc/main.tsx next to ReactDOM.createRoot
Script tagRight after the install snippet

Next steps

On this page