Jump to

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');
  }
});
Comparison table
CallbackPopupEmbedDescription
onRenderYesYesSurvey is rendered and visible.
onSubmitYesYesUser submitted a score or text.
onCloseYesNoUser 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)

Comparison table
ParameterTypeDescription
surveyIdstringSurvey ID.
callbacks.onRender() => voidCalled when the survey renders.
callbacks.onSubmit({ score?, text? }) => voidCalled on submission.
callbacks.onClose() => voidCalled 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]);
}