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): voidChirp.on("survey:completed", ({ surveyId, response }) => {
analytics.track("survey_done", { surveyId, response });
});Unsubscribe
Chirp.off(event: ChirpEventName, handler: (payload) => void): voidfunction 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
| Event | Payload | When 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
| Event | Payload |
|---|---|
survey:shown | { surveyId } |
survey:completed | { surveyId, response } |
survey:dismissed | { surveyId, reason? } |
Announcements
| Event | Payload |
|---|---|
announcement:shown | { id, internalId?, ctaUrl? } |
announcement:clicked | { id, internalId?, ctaUrl? } |
announcement:dismissed | { id, reason? } |
Changelog
| Event | Payload |
|---|---|
changelog:shown | {} |
changelog:dismissed | { reason? } |
Feedback
| Event | Payload |
|---|---|
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 initsurvey: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 });
});React to consent changes
Chirp.on("consent:changed", ({ state }) => {
if (state === "denied") {
// user revoked — maybe hide your "Give feedback" button
setFeedbackButtonVisible(false);
}
});