Surveys (beta)

Last updated:

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.

  1. Make sure you've installed and enabled the surveys app in your project's apps.

  2. You must have the opt_in_site_apps option enabled in your PostHog initialization code.

JavaScript
posthog.init("<ph_project_api_key>", {
"api_host": "<ph_instance_address>",
"opt_in_site_apps": true
})
  1. That's it! Now you can create surveys in the PostHog UI.

Option 2 (custom UI component)

  1. Make sure you're up to date on PostHog's JavaScript library. Surveys requires version 1.67.1, or later.

  2. Call posthog.getSurveys() and get a list of all surveys back, and posthog.getActiveMatchingSurveys() to get a list of active matching surveys that should display for the current user client.

JavaScript
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.

  1. 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.
JavaScript
posthog.capture("survey sent", {
$survey_id: {survey.id} // required
$survey_response: {survey_response} // required
$survey_name: {survey.name} // optional
})

Questions?

Was this page useful?

Next article

Surveys (beta)

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…

Read next article