Surveys are a great way to collect qualitative feedback from your users. Qualitative feedback enables you to gain more insight into your users' and how they view their experience with your product.
With PostHog you can target surveys based on page url, selectors, feature flag, and user properties. Then, you can analyze the results right in PostHog too!
Getting started
Setting up surveys is easy, and there are two ways to do it. The first option will enable you to get started quickly with a pre-built survey, while the second option involves creating your own UI components.
Option 1 (recommended)
Make sure you've installed and enabled the surveys app in your project's apps.
You must have the
opt_in_site_apps
option enabled in your PostHog initialization code.
posthog.init("<ph_project_api_key>", {"api_host": "<ph_instance_address>","opt_in_site_apps": true})
- That's it! Now you can create surveys in the PostHog UI.
Option 2 (custom UI component)
Make sure you're up to date on PostHog's JavaScript library. Surveys requires version 1.67.1, or later.
Call
posthog.getSurveys()
and get a list of all surveys back, andposthog.getActiveMatchingSurveys()
to get a list of active matching surveys that should display for the current user client.
posthog.getActiveMatchingSurveys((surveys) => {// do something with surveys})
Note: You'll need to handle whether a user has seen a survey already or not manually if you're using this option. The survey app uses localStorage to keep track of this, which you can implement similarly in your code.
- In order for survey responses to be recorded, you'll need to send in a "survey sent" capture call event with the survey's name, id, and any properties you'd want.
posthog.capture("survey sent", {$survey_id: {survey.id} // required$survey_response: {survey_response} // required$survey_name: {survey.name} // optional})