Custom surveys is currently supported only with the JavaScript Web SDK.
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.
Rendering surveys programmatically
Although we recommend using popover surveys and display conditions, if you want to show surveys programmatically without setting up all the extra logic needed for API surveys, you can render surveys programmatically with the renderSurvey method. This takes a survey ID and an HTML selector to render an unstyled survey.
Important: Surveys are not immediately available on page load. If you call
renderSurveybefore surveys have been initialized, the call may fail. To avoid this, use theposthog.onSurveysLoaded(callback)method. This ensures surveys are fully initialized before attempting to render them.
An example implementation in React looks like this:
This renders an unstyled survey in the #survey-container element that looks like this:


You can then style the survey by targeting the classes like survey-box, survey-question, textarea, buttons, footer-branding, and thank-you-message.
Fetching surveys manually
For more control over your surveys, you can use API 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, as long as the user (determined by their distinct ID) has not already dismissed or responded 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. PostHog supports two formats for survey responses, but we strongly recommend using ID-based responses as they are more reliable and resistant to changes in question ordering:
For backward compatibility, PostHog also supports index-based responses, but these are more fragile as they depend on question order:
Response formats
Survey responses expect text, so you should convert numbers to text e.g. 8 should be converted to "8".
For multiple choice surveys, the response must be an array of values with the selected choices e.g., $survey_response_multiple_choice_1: ["response_1", "response_2"].
Capturing multiple responses
For surveys with multiple questions, use ID-based properties to ensure your responses remain valid even if questions are reordered:
While index-based responses are still supported, we recommend using ID-based responses for all new implementations:
Note: While PostHog's survey results page supports both formats, custom dashboards and insights might need updates if you switch from index-based to ID-based responses. We recommend planning this transition carefully if you have existing custom analytics based on survey responses.
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.