Surveys installation
Surveys are a great tool to collect qualitative feedback from your users.
Important: When installing PostHog via a package manager, surveys require
posthog-js v1.81.1+. It's recommended to install the latest version.
To get started with surveys, add PostHog to your web app by installing our Javascript web SDK (if you haven't already). There are two methods to do so:
Option 1: Add the JavaScript snippet to your HTML Recommended
Option 2: Install via package manager
And then include it with your project API key and host (which you can find in your project settings):
See our framework specific docs for Next.js, React, Vue, Angular, Astro, Remix, and Svelte for more installation details.
Bundle all required extensions (advanced)
By default, the JavaScript Web library only loads the core functionality. It lazy-loads extensions such as surveys or the session replay 'recorder' when needed.
This can cause issues if:
- You have a Content Security Policy (CSP) that blocks inline scripts.
- You want to optimize your bundle at build time to ensure all dependencies are ready immediately.
- Your app is running in environments like the Chrome Extension store or Electron that reject or block remote code loading.
To solve these issues, we have multiple import options available below.
Note: With any of the no-external options, the toolbar will be unavailable as this is only possible as a runtime dependency loaded directly from us.posthog.com.
Note: You should ensure if using this option that you always import posthog-js from the same module, otherwise multiple bundles could get included. At this time @posthog/react does not work with any module import other than the default.
Don't want to send test data while developing?
If you don't want to send test data while you're developing, you can do the following:
What is the `defaults` option?
The defaults is a date, such as 2025-05-24, for a configuration snapshot used as defaults to initialize PostHog. This default is overridden when you explicitly set a value for any of the options.