At its most basic level, a survey is a collection of response events. If you wanted to, you could capture events from anywhere, like in this example of a hardcoded Next.js feedback survey:
The benefit of using PostHog beyond this is that it handles:
- Survey content. Customize question type, text, and more. Change it at runtime without needing to redeploy your app. 
- Display conditions. This means not showing the same survey multiple times, the wrong survey, or a survey that has collected enough responses. Leverage property filters, cohorts, feature flags, and more. 
If you create a popover survey, updating and display conditions are handled automatically. When you create one in API mode, you need to add logic to fetch and display surveys yourself with the help of the JavaScript Web SDK or snippet.
Fetching surveys
When implementing an API survey, there are two options for fetching surveys from PostHog:
- To get all surveys, call - getSurveys(callback, forceReload). This means you still need to handle display conditions yourself.
- To get surveys enabled for the current user, call - getActiveMatchingSurveys(callback, forceReload). This always returns an active survey if the user meets the display conditions, even if they have already seen, dismissed, or responded to the survey.
Surveys are requested on first load and then cached by default by the JavaScript SDK. If you want to force an API call to get an updated list of surveys, pass true to the forceReload parameter. You only need to do this if you want changed surveys to appear mid-session for users.
Both methods return a callback with an array of surveys in this format:
As an example, we can use getActiveMatchingSurveys() to make our Next.js feedback survey more dynamic:
Tip: To keep track of surveys shown, dismissed, or responded to, store values in a cookie or local storage like this:
Web
Capture survey responses
The main event you must capture to track survey results is survey_sent which we've already shown. It is formatted like this:
Survey responses expect text, so you should convert numbers to text e.g. 8 should be converted to "8".
For multiple choice surveys, survey_response must be an array of values with the selected choices e.g., $survey_response: ["response_1", "response_2"].
Capturing multiple responses
If you have a survey with multiple questions, you can capture the responses to each question using the following syntax:
If you want to make the most of PostHog's automatic survey analysis and results visualizations page, you'll need to capture survey responses in the above formats.
Capture survey lifecycle events
There are two other events you should capture to track the full lifecycle of a survey. They are survey_shown and survey_dismissed:
Capturing all three events ensures you have a full implementation matching popup surveys and that your analysis is accurate in PostHog.