: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.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
fix(surveys): tailor launch UX for hosted surveys (#59312)
Lucas Fariad394feb916b3
diff --git a/frontend/src/scenes/surveys/CopySurveyLink.tsx b/frontend/src/scenes/surveys/CopySurveyLink.tsxindex 8ab65d23bcc5..a280eb87bf5c 100644--- a/frontend/src/scenes/surveys/CopySurveyLink.tsx+++ b/frontend/src/scenes/surveys/CopySurveyLink.tsx@@ -4,7 +4,7 @@ import { LemonButton } from '@posthog/lemon-ui'import { IconLink } from 'lib/lemon-ui/icons'import { copyToClipboard } from 'lib/utils/copyToClipboard'-function getSurveyUrl(surveyId: string): string {+export function getSurveyUrl(surveyId: string): string {const url = new URL(window.location.origin)url.pathname = `/external_surveys/${surveyId}`return url.toString()diff --git a/frontend/src/scenes/surveys/components/HostedSurveyRespondentHint.tsx b/frontend/src/scenes/surveys/components/HostedSurveyRespondentHint.tsxnew file mode 100644index 000000000000..37c4ef7fa51c--- /dev/null+++ b/frontend/src/scenes/surveys/components/HostedSurveyRespondentHint.tsx@@ -0,0 +1,28 @@+import { Link } from '@posthog/lemon-ui'++export function HostedSurveyRespondentHint({ className }: { className?: string }): JSX.Element {+ return (+ <div className={`flex flex-col gap-1 text-muted ${className ?? 'text-xs'}`}>+ <div className="font-medium text-secondary">Customize the URL with query parameters:</div>+ <ul className="list-disc list-inside space-y-0.5 m-0">+ <li>+ <code>?distinct_id=user_id</code> — tie the response to a specific person (use the same value as{' '}+ <code>posthog.identify()</code>)+ </li>+ <li>+ <code>?q0=2&q1=8</code> — pre-fill answers for one-click surveys in emails (<code>q0</code> =+ first question, value = choice or rating)+ </li>+ <li>+ <code>?key=value</code> — any extra parameter is captured as an event property on the response+ </li>+ </ul>+ <Link+ to="https://posthog.com/docs/surveys/creating-surveys#identifying-respondents-on-hosted-surveys"+ target="_blank"+ >+ Learn more about hosted survey URLs+ </Link>+ </div>+ )+}diff --git a/frontend/src/scenes/surveys/components/LaunchSurveyButton.tsx b/frontend/src/scenes/surveys/components/LaunchSurveyButton.tsxindex d1b70470b66e..1a1c3e803aae 100644--- a/frontend/src/scenes/surveys/components/LaunchSurveyButton.tsx+++ b/frontend/src/scenes/surveys/components/LaunchSurveyButton.tsx@@ -4,13 +4,16 @@ import { ReactNode } from 'react'import { LemonButton, LemonDialog } from '@posthog/lemon-ui'import { AccessControlAction } from 'lib/components/AccessControlAction'+import { copyToClipboard } from 'lib/utils/copyToClipboard'+import { HostedSurveyRespondentHint } from 'scenes/surveys/components/HostedSurveyRespondentHint'import { SdkVersionWarnings } from 'scenes/surveys/components/SdkVersionWarnings'import { SurveyConditionsList } from 'scenes/surveys/components/SurveyConditions'+import { getSurveyUrl } from 'scenes/surveys/CopySurveyLink'import { surveyLogic } from 'scenes/surveys/surveyLogic'import { getSurveyDisplayConditionsSummary } from 'scenes/surveys/utils'import { teamLogic } from 'scenes/teamLogic'-import { AccessControlLevel, AccessControlResourceType } from '~/types'+import { AccessControlLevel, AccessControlResourceType, SurveyType } from '~/types'export function LaunchSurveyButton({ children = 'Launch' }: { children?: ReactNode }): JSX.Element {const { survey, surveyWarnings } = useValues(surveyLogic)@@ -19,7 +22,8 @@ export function LaunchSurveyButton({ children = 'Launch' }: { children?: ReactNoconst { updateCurrentTeam } = useActions(teamLogic)const needsOptIn = !currentTeam?.surveys_opt_in- const conditionsSummary = getSurveyDisplayConditionsSummary(survey)+ const isHostedSurvey = survey.type === SurveyType.ExternalSurvey+ const conditionsSummary = isHostedSurvey ? [] : getSurveyDisplayConditionsSummary(survey)return (<AccessControlAction@@ -37,7 +41,15 @@ export function LaunchSurveyButton({ children = 'Launch' }: { children?: ReactNocontent: (<div className="flex flex-col gap-3"><SdkVersionWarnings warnings={surveyWarnings} />- {conditionsSummary.length > 0 ? (+ {isHostedSurvey ? (+ <div className="flex flex-col gap-3 text-sm">+ <p className="text-secondary m-0">+ Once launched, anyone with the link can answer the survey. We'll copy the+ link to your clipboard so you can share it right away.+ </p>+ <HostedSurveyRespondentHint />+ </div>+ ) : conditionsSummary.length > 0 ? (<div className="text-sm"><div className="text-secondary mb-1">This survey will be shown to users who match:@@ -55,12 +67,15 @@ export function LaunchSurveyButton({ children = 'Launch' }: { children?: ReactNo</div>),primaryButton: {- children: 'Launch',+ children: isHostedSurvey ? 'Launch and copy link' : 'Launch',type: 'primary',onClick: () => {if (needsOptIn) {updateCurrentTeam({ surveys_opt_in: true })}+ if (isHostedSurvey) {+ void copyToClipboard(getSurveyUrl(survey.id), 'survey link')+ }launchSurvey()},size: 'small',diff --git a/frontend/src/scenes/surveys/wizard/SurveyWizard.tsx b/frontend/src/scenes/surveys/wizard/SurveyWizard.tsxindex aa9b284fa48c..d68b366a52c0 100644--- a/frontend/src/scenes/surveys/wizard/SurveyWizard.tsx+++ b/frontend/src/scenes/surveys/wizard/SurveyWizard.tsx@@ -17,8 +17,9 @@ import { teamLogic } from 'scenes/teamLogic'import { urls } from 'scenes/urls'import { themeLogic } from '~/layout/navigation-3000/themeLogic'-import { SurveyMatchType, SurveyQuestionBranchingType } from '~/types'+import { SurveyMatchType, SurveyQuestionBranchingType, SurveyType } from '~/types'+import { HostedSurveyRespondentHint } from '../components/HostedSurveyRespondentHint'import { SdkVersionWarnings } from '../components/SdkVersionWarnings'import { NewSurvey } from '../constants'import { SurveyAppearancePreview } from '../SurveyAppearancePreview'@@ -130,6 +131,33 @@ function SurveyWizard({ id }: SurveyWizardLogicProps): JSX.Element {router.actions.push(target)}+ 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)+ // The wizard doesn't render hosted surveys — route to the dedicated editor.+ const target = isEditing ? `${urls.survey(id)}?edit=true` : urls.survey(id)+ router.actions.push(target)+ },+ },+ secondaryButton: {+ children: 'Cancel',+ },+ })+ }+// Show loading state while loading existing surveyif (isEditing && surveyLoading) {return (@@ -215,8 +243,9 @@ function SurveyWizard({ id }: SurveyWizardLogicProps): JSX.Element {}const showLaunchConfirmation = (onConfirm: () => void): void => {- const hasConditions = doesSurveyHaveDisplayConditions(survey)- const conditionsSummary = getConditionsSummary()+ const isHostedSurvey = survey.type === SurveyType.ExternalSurvey+ const hasConditions = !isHostedSurvey && doesSurveyHaveDisplayConditions(survey)+ const conditionsSummary = isHostedSurvey ? [] : getConditionsSummary()const hasAudienceConditions = conditionsSummary.length > 0LemonDialog.open({@@ -224,7 +253,15 @@ function SurveyWizard({ id }: SurveyWizardLogicProps): JSX.Element {content: (<div className="space-y-2"><SdkVersionWarnings warnings={surveyWarnings} />- {hasConditions || hasAudienceConditions ? (+ {isHostedSurvey ? (+ <div className="flex flex-col gap-3">+ <p className="text-secondary m-0">+ Once launched, anyone with the link can answer the survey. You'll get the share link on+ the next screen.+ </p>+ <HostedSurveyRespondentHint />+ </div>+ ) : hasConditions || hasAudienceConditions ? (<><p className="text-secondary">The survey will be shown to users who match these conditions:@@ -315,9 +352,21 @@ function SurveyWizard({ id }: SurveyWizardLogicProps): JSX.Element {<div className="space-y-1"><div className="flex items-center justify-between">{backButton}- <LemonButton type="secondary" size="small" onClick={handleCustomizeMore}>- Full editor- </LemonButton>+ <div className="flex items-center gap-2">+ {canConvertToHosted && (+ <LemonButton+ data-attr="convert-to-hosted-survey"+ type="tertiary"+ size="small"+ onClick={convertToHostedSurvey}+ >+ Convert to hosted+ </LemonButton>+ )}+ <LemonButton type="secondary" size="small" onClick={handleCustomizeMore}>+ Full editor+ </LemonButton>+ </div></div><div><label htmlFor="survey-name" className="text-xs font-medium text-muted">diff --git a/frontend/src/scenes/surveys/wizard/steps/SuccessStep.tsx b/frontend/src/scenes/surveys/wizard/steps/SuccessStep.tsxindex 94f749d34db2..f36008624855 100644--- a/frontend/src/scenes/surveys/wizard/steps/SuccessStep.tsx+++ b/frontend/src/scenes/surveys/wizard/steps/SuccessStep.tsx@@ -5,8 +5,10 @@ import { LemonButton } from '@posthog/lemon-ui'import { urls } from 'scenes/urls'-import { Survey, SurveySchedule } from '~/types'+import { Survey, SurveySchedule, SurveyType } from '~/types'+import { HostedSurveyRespondentHint } from '../../components/HostedSurveyRespondentHint'+import { CopySurveyLink } from '../../CopySurveyLink'import { SurveyAppearancePreview } from '../../SurveyAppearancePreview'interface SuccessStepProps {@@ -14,10 +16,11 @@ interface SuccessStepProps {}export function SuccessStep({ survey }: SuccessStepProps): JSX.Element {+ const isHostedSurvey = survey.type === SurveyType.ExternalSurveyconst [countdown, setCountdown] = useState(5)useEffect(() => {- if (!survey?.id) {+ if (!survey?.id || isHostedSurvey) {return}@@ -33,16 +36,36 @@ export function SuccessStep({ survey }: SuccessStepProps): JSX.Element {clearInterval(interval)clearTimeout(timer)}- }, [survey?.id])+ }, [survey?.id, isHostedSurvey])return (<div className="text-center space-y-6"><div className="space-y-2"><h1 className="text-2xl font-semibold">Your survey is live!</h1>- <p className="text-secondary">Responses will start coming in based on your targeting settings.</p>- <p className="text-muted text-sm">Redirecting to your survey in {countdown}...</p>+ {isHostedSurvey ? (+ <p className="text-secondary">Copy the link below and share it to start collecting responses.</p>+ ) : (+ <>+ <p className="text-secondary">+ Responses will start coming in based on your targeting settings.+ </p>+ <p className="text-muted text-sm">Redirecting to your survey in {countdown}...</p>+ </>+ )}</div>+ {isHostedSurvey && (+ <div className="flex flex-col items-center gap-4">+ <CopySurveyLink+ surveyId={survey.id}+ enableIframeEmbedding={survey.enable_iframe_embedding ?? false}+ />+ <div className="max-w-xl text-left">+ <HostedSurveyRespondentHint className="text-sm" />+ </div>+ </div>+ )}+<div className="flex items-center justify-center gap-4"><LemonButton type="primary" to={urls.survey(survey.id)}>View survey now@@ -54,29 +77,31 @@ export function SuccessStep({ survey }: SuccessStepProps): JSX.Element {<SurveyAppearancePreview survey={survey} previewPageIndex={0} /></div>- <div className="bg-bg-3000 rounded-lg p-4 text-left max-w-md mx-auto space-y-2">- <h3 className="font-medium">Summary</h3>- <dl className="space-y-1 text-sm">- <div className="flex justify-between">- <dt className="text-secondary">Showing on</dt>- <dd>{survey.conditions?.url || 'All pages'}</dd>- </div>- <div className="flex justify-between">- <dt className="text-secondary">Frequency</dt>- <dd>- {survey.schedule === SurveySchedule.Once || !survey.iteration_frequency_days- ? 'Once ever'- : `Up to ${survey.iteration_count ?? 10} times, every ${survey.iteration_frequency_days} days`}- </dd>- </div>- {survey.conditions?.seenSurveyWaitPeriodInDays != null && (+ {!isHostedSurvey && (+ <div className="bg-bg-3000 rounded-lg p-4 text-left max-w-md mx-auto space-y-2">+ <h3 className="font-medium">Summary</h3>+ <dl className="space-y-1 text-sm"><div className="flex justify-between">- <dt className="text-secondary">Wait period across all surveys</dt>- <dd>{survey.conditions.seenSurveyWaitPeriodInDays} days</dd>+ <dt className="text-secondary">Showing on</dt>+ <dd>{survey.conditions?.url || 'All pages'}</dd></div>- )}- </dl>- </div>+ <div className="flex justify-between">+ <dt className="text-secondary">Frequency</dt>+ <dd>+ {survey.schedule === SurveySchedule.Once || !survey.iteration_frequency_days+ ? 'Once ever'+ : `Up to ${survey.iteration_count ?? 10} times, every ${survey.iteration_frequency_days} days`}+ </dd>+ </div>+ {survey.conditions?.seenSurveyWaitPeriodInDays != null && (+ <div className="flex justify-between">+ <dt className="text-secondary">Wait period across all surveys</dt>+ <dd>{survey.conditions.seenSurveyWaitPeriodInDays} days</dd>+ </div>+ )}+ </dl>+ </div>+ )}</div>)}