React integration with useThumbSurvey
Contents
To quickly integrate with your React app, we provide a hook useThumbSurvey that exposes a method to submit survey responses, the user's response, and a ref to position followup question pop-ups.
Quickstart
Note: This hook requires
@posthog/react1.7.1+, which is bundled withposthog-js1.345.1+
Initialize the hook with the following options:
It returns the following interface:
A simple usage of this hook, including a followup question pop-up, looks like this:
Impression tracking
By default, the hook emits a survey shown (impression) event on mount.
Duplicate impression events will not impact your ability to see responses within LLM Analytics, but may skew metrics viewed directly from Surveys.
To disable this behavior, initialize the hook with disableAutoShownTracking: true and manually call trackShown() when you consider your survey to be "shown."
Response persistence
The hook's response value is not persisted across mounts. We plan to improve this soon, but in the meantime, you'll need to set up your own persistent response tracking if needed.
Question indices
The hook submits survey responses using the legacy index-based tracking for survey questions. If you add or re-order survey questions from the Surveys UI, you may experience unexpected behavior. See Implementing custom surveys for more information.
Survey compatibility
To use this hook, your survey must begin with a thumbs up/down question. All other surveys features are supported, such as followup questions and question branching.
For more information, see the hook source here on GitHub, or a real implementation in the PostHog codebase here.