Events
Use on() to subscribe to survey lifecycle events. This is the only way to set callbacks — they are not accepted by init() or open().
ftools('on', 'SURVEY_ID', {
onRender: () => {
console.log('survey rendered');
},
onSubmit: ({ score, text }) => {
console.log('user submitted', score, text);
},
onClose: () => {
console.log('user closed the survey');
}
});| Callback | Popup | Embed | Description |
|---|---|---|---|
onRender | Yes | Yes | Survey is rendered and visible. |
onSubmit | Yes | Yes | User submitted a score or text. |
onClose | Yes | No | User closed the survey. |
on() must be called after init(). It can be called at any point after that — before or after the survey opens. Callbacks are merged — calling on() again only updates the callbacks you provide, leaving others intact. If the survey is already mounted when on() is called, onRender fires immediately.
ftools('on', surveyId, callbacks)
| Parameter | Type | Description |
|---|---|---|
surveyId | string | Survey ID. |
callbacks.onRender | () => void | Called when the survey renders. |
callbacks.onSubmit | ({ score?, text? }) => void | Called on submission. |
callbacks.onClose | () => void | Called when the user closes the survey (popup only). |
ftools('off', surveyId)
Removes all callbacks previously set via on().
ftools('off', 'SURVEY_ID');Useful for cleanup in component unmount handlers:
import { useEffect } from 'react';
export function useSurveyEvents(surveyId, { onSubmit, onClose } = {}) {
useEffect(() => {
window.ftools?.('on', surveyId, { onSubmit, onClose });
return () => {
window.ftools?.('off', surveyId);
};
}, [surveyId]);
}