SDK

Events

Subscribe to SDK lifecycle and user-interaction events.

The SDK emits typed events at every meaningful moment — initialization, survey show / complete / dismiss, announcement interactions, feedback submission, and consent changes. Use them to forward data to your own analytics or trigger custom behavior.

Subscribe

Chirp.on(event: ChirpEventName, handler: (payload) => void): void
Chirp.on("survey:completed", ({ surveyId, response }) => {
  analytics.track("survey_done", { surveyId, response });
});

Unsubscribe

Chirp.off(event: ChirpEventName, handler: (payload) => void): void
function onReady(payload) {
  console.log("SDK ready", payload);
}

Chirp.on("ready", onReady);
// later
Chirp.off("ready", onReady);

off requires the exact same function reference you passed to on. An arrow function used twice creates two different references — keep a named handler around if you'll need to unsubscribe.

Event reference

Lifecycle

EventPayloadWhen it fires
ready{ sdkVersion?, buildSha? }SDK finished init. Replays for late subscribers.
error{ code, message, context? }Any SDK-level error.
consent:changed{ state, previous, source? }Consent state transitioned.

Surveys

EventPayload
survey:shown{ surveyId }
survey:completed{ surveyId, response }
survey:dismissed{ surveyId, reason? }

Announcements

EventPayload
announcement:shown{ id, internalId?, ctaUrl? }
announcement:clicked{ id, internalId?, ctaUrl? }
announcement:dismissed{ id, reason? }

Changelog

EventPayload
changelog:shown{}
changelog:dismissed{ reason? }

Feedback

EventPayload
feedback:shown{ name }
feedback:submitted{ name, type?, response? }
feedback:dismissed{ name?, reason? }

Replay behavior

Some events replay so handlers attached after the event still receive it:

  • ready — replays once for handlers attached within the same JS tick after init
  • survey:shown, announcement:shown, feedback:shown — replay for handlers attached within 5 seconds of the show event

All other events do not replay. Attach handlers before triggering the action.

Common patterns

Forward to your analytics stack

Chirp.on("survey:completed", (p) => analytics.track("survey_completed", p));
Chirp.on("announcement:clicked", (p) => analytics.track("announcement_clicked", p));
Chirp.on("feedback:submitted", (p) => analytics.track("feedback_submitted", p));

Centralized error logging

Chirp.on("error", ({ code, message, context }) => {
  errorReporter.captureMessage(`[ChirpBack] ${code}: ${message}`, { extra: context });
});
Chirp.on("consent:changed", ({ state }) => {
  if (state === "denied") {
    // user revoked — maybe hide your "Give feedback" button
    setFeedbackButtonVisible(false);
  }
});

Next steps

On this page