Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

feat(surveys): add in-app/hosted distribution toggle and converter (#58912)

Lucas Fariaa2fed61b7939
diff --git a/frontend/src/scenes/surveys/SurveyEdit.tsx b/frontend/src/scenes/surveys/SurveyEdit.tsx
index be4eb2d1a146..ced564856c75 100644
--- a/frontend/src/scenes/surveys/SurveyEdit.tsx
+++ b/frontend/src/scenes/surveys/SurveyEdit.tsx
@@ -296,6 +296,30 @@ export default function SurveyEdit({ id }: { id: string }): JSX.Element {
const { setPreferredEditor } = useActions(surveysLogic)
const { featureFlags } = useValues(enabledFeaturesLogic)
const surveyTranslationsEnabled = !!featureFlags[FEATURE_FLAGS.SURVEYS_TRANSLATIONS]
+ const hostedEditorEnabled = !!featureFlags[FEATURE_FLAGS.SURVEYS_HOSTED_EDITOR]
+ const canConvertToHosted = hostedEditorEnabled && survey.type !== SurveyType.ExternalSurvey
+
+ const convertToHostedSurvey = (): void => {
+ LemonDialog.open({
+ title: 'Convert to hosted survey?',
+ description: (
+ <p className="py-2">
+ This keeps the questions and style, then switches the editor to the hosted-survey setup. Display
+ conditions and in-app placement settings won't apply.
+ </p>
+ ),
+ primaryButton: {
+ children: 'Convert',
+ onClick: () => {
+ setSurveyValue('type', SurveyType.ExternalSurvey)
+ setSelectedPageIndex(0)
+ },
+ },
+ secondaryButton: {
+ children: 'Cancel',
+ },
+ })
+ }
const activeEditingLanguage = surveyTranslationsEnabled ? editingLanguage : null
const surveyTranslations = survey.translations ?? {}
const hasActualTranslations = !!(
@@ -441,6 +465,16 @@ export default function SurveyEdit({ id }: { id: string }): JSX.Element {
Guided editor
</LemonButton>
)}
+ {canConvertToHosted && (
+ <LemonButton
+ data-attr="convert-to-hosted-survey"
+ type="tertiary"
+ size="small"
+ onClick={convertToHostedSurvey}
+ >
+ Convert to hosted
+ </LemonButton>
+ )}
<LemonButton
data-attr="cancel-survey"
type="secondary"
diff --git a/frontend/src/scenes/surveys/wizard/steps/TemplateStep.tsx b/frontend/src/scenes/surveys/wizard/steps/TemplateStep.tsx
index 5b079ae043b1..d9bb7a866ad5 100644
--- a/frontend/src/scenes/surveys/wizard/steps/TemplateStep.tsx
+++ b/frontend/src/scenes/surveys/wizard/steps/TemplateStep.tsx
@@ -19,14 +19,16 @@ import {
IconTrending,
IconWarning,
} from '@posthog/icons'
-import { LemonButton, LemonTextArea } from '@posthog/lemon-ui'
+import { LemonButton, LemonSegmentedButton, LemonTag, LemonTextArea } from '@posthog/lemon-ui'
+import { FEATURE_FLAGS } from 'lib/constants'
+import { featureFlagLogic } from 'lib/logic/featureFlagLogic'
import { eventUsageLogic } from 'lib/utils/eventUsageLogic'
import { useMaxTool } from 'scenes/max/useMaxTool'
import { SURVEY_CREATED_SOURCE, SurveyTemplate, SurveyTemplateType } from '../../constants'
import { surveysLogic } from '../../surveysLogic'
-import { surveyWizardLogic } from '../surveyWizardLogic'
+import { SurveyTemplateMode, surveyWizardLogic } from '../surveyWizardLogic'
const TEMPLATE_ICONS: Partial<Record<SurveyTemplateType, React.ComponentType<{ className?: string }>>> = {
[SurveyTemplateType.NPS]: IconGraph,
@@ -88,10 +90,12 @@ function TemplateCard({ template, onClick, featured }: TemplateCardProps): JSX.E
}
export function TemplateStep({ handleCustomizeMore }: { handleCustomizeMore: () => void }): JSX.Element {
- const { coreTemplates, otherTemplates } = useValues(surveyWizardLogic)
- const { selectTemplate } = useActions(surveyWizardLogic)
+ const { coreTemplates, otherTemplates, templateMode } = useValues(surveyWizardLogic)
+ const { selectTemplate, setTemplateMode } = useActions(surveyWizardLogic)
const { reportSurveyAiPromptSubmitted } = useActions(eventUsageLogic)
const { handleMaxSurveyCreated } = useActions(surveysLogic)
+ const { featureFlags } = useValues(featureFlagLogic)
+ const hostedEditorEnabled = !!featureFlags[FEATURE_FLAGS.SURVEYS_HOSTED_EDITOR]
const [showOthers, setShowOthers] = useState(false)
const [prompt, setPrompt] = useState('')
const textAreaRef = useRef<HTMLTextAreaElement>(null)
@@ -109,13 +113,41 @@ export function TemplateStep({ handleCustomizeMore }: { handleCustomizeMore: ()
}
}
+ const isHostedMode = templateMode === 'hosted'
+ const modeDescription = isHostedMode
+ ? "Pick a template — you'll get a shareable link, no SDK needed."
+ : 'Start with a proven template, then customize it to your needs.'
+
return (
<div className="space-y-6">
<div className="text-center space-y-2">
<h1 className="text-2xl font-semibold">Choose a survey template</h1>
- <p className="text-secondary">Start with a proven template, then customize it to your needs</p>
+ <p className="text-secondary">{modeDescription}</p>
</div>
+ {hostedEditorEnabled && (
+ <div className="flex justify-center">
+ <LemonSegmentedButton
+ value={templateMode}
+ onChange={(value) => setTemplateMode(value as SurveyTemplateMode)}
+ options={[
+ { value: 'in_app', label: 'In-app survey' },
+ {
+ value: 'hosted',
+ label: (
+ <span className="flex items-center gap-1.5">
+ Hosted link
+ <LemonTag type="warning" size="small">
+ Beta
+ </LemonTag>
+ </span>
+ ),
+ },
+ ]}
+ />
+ </div>
+ )}
+
{/* Core templates - 2x2 grid */}
<div className="grid grid-cols-1 sm:grid-cols-2 gap-4">
{coreTemplates.map((template) => (
diff --git a/frontend/src/scenes/surveys/wizard/surveyWizardLogic.ts b/frontend/src/scenes/surveys/wizard/surveyWizardLogic.ts
index b31292e278f4..99ba65e8bef3 100644
--- a/frontend/src/scenes/surveys/wizard/surveyWizardLogic.ts
+++ b/frontend/src/scenes/surveys/wizard/surveyWizardLogic.ts
@@ -26,6 +26,8 @@ import type { surveyWizardLogicType } from './surveyWizardLogicType'
export type WizardStep = 'template' | 'questions' | 'where' | 'when' | 'appearance' | 'success'
+export type SurveyTemplateMode = 'in_app' | 'hosted'
+
// Main flow steps (appearance is optional, branched from 'when')
const WIZARD_STEPS: WizardStep[] = ['template', 'questions', 'where', 'when']
@@ -73,6 +75,7 @@ export const surveyWizardLogic = kea<surveyWizardLogicType>([
prevStep: true,
resetWizard: true,
selectTemplate: (template: SurveyTemplate) => ({ template }),
+ setTemplateMode: (mode: SurveyTemplateMode) => ({ mode }),
restoreDefaultQuestions: true,
launchSurvey: true,
launchSurveySuccess: (survey: Survey) => ({ survey }),
@@ -110,6 +113,13 @@ export const surveyWizardLogic = kea<surveyWizardLogicType>([
resetWizard: () => null,
},
],
+ templateMode: [
+ 'in_app' as SurveyTemplateMode,
+ {
+ setTemplateMode: (_, { mode }) => mode,
+ resetWizard: () => 'in_app' as SurveyTemplateMode,
+ },
+ ],
createdSurvey: [
null as Survey | null,
{
@@ -237,10 +247,14 @@ export const surveyWizardLogic = kea<surveyWizardLogicType>([
listeners(({ actions, values, props }) => ({
selectTemplate: ({ template }) => {
+ const isHostedMode = values.templateMode === 'hosted'
const timestamp = dayjs().format('YYYY-MM-DD HH:mm')
actions.setSurveyValue('name', `${template.templateType} (${timestamp})`)
actions.setSurveyValue('description', template.description || '')
- actions.setSurveyValue('type', template.type || SurveyType.Popover)
+ actions.setSurveyValue(
+ 'type',
+ isHostedMode ? SurveyType.ExternalSurvey : template.type || SurveyType.Popover
+ )
actions.setSurveyValue('questions', template.questions)
// Apply Clean theme by default (works well on most sites, and users without
@@ -285,6 +299,11 @@ export const surveyWizardLogic = kea<surveyWizardLogicType>([
actions.setSurveyValue('conditions', template.conditions ?? null)
actions.reportSurveyTemplateClicked(template.templateType, SURVEY_CREATED_SOURCE.SURVEY_WIZARD)
+
+ // Hosted surveys don't have a guided wizard — route to the dedicated editor.
+ if (isHostedMode) {
+ router.actions.push(props.id === 'new' ? urls.survey('new') : `${urls.survey(props.id)}?edit=true`)
+ }
},
restoreDefaultQuestions: () => {
const template = values.selectedTemplate