: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
feat(surveys): add intro screen to the hosted survey canvas (#116329)
Lucas Faria8d821668cbae
diff --git a/frontend/public/surveys/hosted-survey.css b/frontend/public/surveys/hosted-survey.cssindex ed0f7af3efa6..64ca8b600998 100644--- a/frontend/public/surveys/hosted-survey.css+++ b/frontend/public/surveys/hosted-survey.css@@ -108,7 +108,8 @@ body.PostHogHostedSurvey {gap: 1.5rem;}-.PostHogHostedSurvey .thank-you-message {+.PostHogHostedSurvey .thank-you-message,+.PostHogHostedSurvey .intro-screen {display: flex;flex-direction: column;gap: 1.5rem;@@ -117,7 +118,8 @@ body.PostHogHostedSurvey {}.PostHogHostedSurvey .survey-question,-.PostHogHostedSurvey .thank-you-message-header {+.PostHogHostedSurvey .thank-you-message-header,+.PostHogHostedSurvey .intro-screen-header {margin: 0;font-size: clamp(1.5rem, 2.4vw, 1.875rem);font-weight: 600;@@ -128,7 +130,8 @@ body.PostHogHostedSurvey {}.PostHogHostedSurvey .survey-question-description,-.PostHogHostedSurvey .thank-you-message-body {+.PostHogHostedSurvey .thank-you-message-body,+.PostHogHostedSurvey .intro-screen-body {margin: 0;font-size: 0.975rem;line-height: 1.6;@@ -136,7 +139,8 @@ body.PostHogHostedSurvey {}.PostHogHostedSurvey .survey-question-description strong,-.PostHogHostedSurvey .thank-you-message strong {+.PostHogHostedSurvey .thank-you-message strong,+.PostHogHostedSurvey .intro-screen strong {color: var(--ph-survey-text-primary-color, #111);}@@ -535,7 +539,8 @@ body.PostHogHostedSurvey {}.PostHogHostedSurvey #posthog-survey-container:has(.question-container) .loading,-.PostHogHostedSurvey #posthog-survey-container:has(.thank-you-message) .loading {+.PostHogHostedSurvey #posthog-survey-container:has(.thank-you-message) .loading,+.PostHogHostedSurvey #posthog-survey-container:has(.intro-screen) .loading {display: none;}@@ -624,7 +629,8 @@ body.PostHogHostedSurvey {}.PostHogHostedSurvey .survey-question,- .PostHogHostedSurvey .thank-you-message-header {+ .PostHogHostedSurvey .thank-you-message-header,+ .PostHogHostedSurvey .intro-screen-header {font-size: 1.5rem;}diff --git a/frontend/src/scenes/surveys/HostedSurveyEdit.tsx b/frontend/src/scenes/surveys/HostedSurveyEdit.tsxindex ba0a8262ec1e..72c29648a612 100644--- a/frontend/src/scenes/surveys/HostedSurveyEdit.tsx+++ b/frontend/src/scenes/surveys/HostedSurveyEdit.tsx@@ -28,7 +28,12 @@ import { Customization } from 'scenes/surveys/survey-appearance/SurveyCustomizatimport { SurveyTranslationFields } from 'scenes/surveys/SurveyTranslationFields'import { SurveyTranslations } from 'scenes/surveys/SurveyTranslations'import { getSurveyWithTranslatedContent } from 'scenes/surveys/surveyTranslationUtils'-import { sanitizeSurveyAppearance, validateSurveyAppearance } from 'scenes/surveys/utils'+import {+ getFirstPreviewPageIndex,+ sanitizeSurveyAppearance,+ validateSurveyAppearance,+ withIntroScreenEnabled,+} from 'scenes/surveys/utils'import { urls } from 'scenes/urls'import { SceneContent } from '~/layout/scenes/components/SceneContent'@@ -36,9 +41,10 @@ import { Survey, SurveyQuestion, SurveyQuestionType, SurveyType } from '~/types'import { SurveyBranchingFlowModal } from './branching-flow/SurveyBranchingFlowModal'import { SurveyPublicContentNotice } from './components/SurveyPublicContentNotice'-import { defaultSurveyFieldValues, NewSurvey, SurveyQuestionLabel } from './constants'+import { defaultSurveyFieldValues, INTRO_SCREEN_PAGE_INDEX, NewSurvey, SurveyQuestionLabel } from './constants'import { CopySurveyLink } from './CopySurveyLink'import { HostedSurveyCanvas } from './hosted-canvas/HostedSurveyCanvas'+import { getHostedSurveyPageKind } from './hosted-canvas/hostedSurveyPageKind'import { HostedSurveySettingsPanel } from './hosted-canvas/HostedSurveySettingsPanel'import { surveyLogic } from './surveyLogic'import { SurveyResponsesCollection } from './SurveyResponsesCollection'@@ -57,6 +63,7 @@ function HostedSurveyQuestionRail({selectedPageIndex,onSelectPage,onAddQuestion,+ onAddIntro,onAddConfirmation,onMoveQuestion,onDeleteQuestion,@@ -68,6 +75,7 @@ function HostedSurveyQuestionRail({selectedPageIndex: numberonSelectPage: (pageIndex: number) => voidonAddQuestion: (type: SurveyQuestionType) => void+ onAddIntro: () => voidonAddConfirmation: () => voidonMoveQuestion: (from: number, to: number) => voidonDeleteQuestion: (index: number) => void@@ -98,6 +106,18 @@ function HostedSurveyQuestionRail({</div></div><div className="flex flex-col gap-2">+ {survey.appearance?.displayIntroScreen ? (+ <HostedSurveyRailScreen+ title="Intro"+ subtitle="Start screen"+ isSelected={selectedPageIndex === INTRO_SCREEN_PAGE_INDEX}+ onSelect={() => onSelectPage(INTRO_SCREEN_PAGE_INDEX)}+ />+ ) : (+ <LemonButton type="secondary" size="small" onClick={onAddIntro} className="mb-1" fullWidth>+ Add intro screen+ </LemonButton>+ )}<DndContext onDragEnd={handleDragEnd}><SortableContextdisabled={survey.questions.length <= 1}@@ -122,18 +142,12 @@ function HostedSurveyQuestionRail({</SortableContext></DndContext>{survey.appearance?.displayThankYouMessage ? (- <button- type="button"- className={`min-h-11 rounded border px-3 py-2 text-left text-sm transition-colors ${- selectedPageIndex === survey.questions.length- ? 'border-primary bg-primary-highlight text-primary'- : 'bg-bg-light hover:bg-fill-highlight-50'- }`}- onClick={() => onSelectPage(survey.questions.length)}- >- <span className="block font-medium">Confirmation</span>- <span className="block text-xs text-secondary">End screen</span>- </button>+ <HostedSurveyRailScreen+ title="Confirmation"+ subtitle="End screen"+ isSelected={selectedPageIndex === survey.questions.length}+ onSelect={() => onSelectPage(survey.questions.length)}+ />) : (<LemonButton type="secondary" size="small" onClick={onAddConfirmation} className="mt-1" fullWidth>Add confirmation@@ -151,6 +165,33 @@ function HostedSurveyQuestionRail({)}+function HostedSurveyRailScreen({+ title,+ subtitle,+ isSelected,+ onSelect,+}: {+ title: string+ subtitle: string+ isSelected: boolean+ onSelect: () => void+}): JSX.Element {+ return (+ <button+ type="button"+ className={`min-h-11 rounded border px-3 py-2 text-left text-sm transition-colors ${+ isSelected+ ? 'border-primary bg-primary-highlight text-primary'+ : 'bg-bg-light hover:bg-fill-highlight-50'+ }`}+ onClick={onSelect}+ >+ <span className="block font-medium">{title}</span>+ <span className="block text-xs text-secondary">{subtitle}</span>+ </button>+ )+}+function HostedSurveyQuestionRailItem({id,question,@@ -422,11 +463,18 @@ export function HostedSurveyEdit({ id }: { id: string }): JSX.Element {[survey, activeLanguage])const maxPageIndex = Math.max(survey.questions.length + (survey.appearance?.displayThankYouMessage ? 1 : 0) - 1, 0)- const activePageIndex = Math.min(Math.max(selectedPageIndex ?? 0, 0), maxPageIndex)- const isConfirmationSelected =- !!survey.appearance?.displayThankYouMessage && activePageIndex === survey.questions.length+ const activePageIndex = Math.min(Math.max(selectedPageIndex ?? 0, getFirstPreviewPageIndex(survey)), maxPageIndex)+ const pageKind = getHostedSurveyPageKind(survey, activePageIndex)const hostedSurveyUrl = id === 'new' ? null : getHostedSurveyUrl(id)+ const removeIntroScreen = (): void => {+ setSurveyValue('appearance', {+ ...survey.appearance,+ displayIntroScreen: false,+ })+ setSelectedPageIndex(0)+ }+const removeConfirmationScreen = (): void => {setSurveyValue('appearance', {...survey.appearance,@@ -525,6 +573,10 @@ export function HostedSurveyEdit({ id }: { id: string }): JSX.Element {selectedPageIndex={activePageIndex}onSelectPage={setSelectedPageIndex}onAddQuestion={addQuestion}+ onAddIntro={() => {+ setSurveyValue('appearance', withIntroScreenEnabled(survey.appearance))+ setSelectedPageIndex(INTRO_SCREEN_PAGE_INDEX)+ }}onAddConfirmation={() => {setSurveyValue('appearance', {...survey.appearance,@@ -540,14 +592,15 @@ export function HostedSurveyEdit({ id }: { id: string }): JSX.Element {<HostedSurveyCanvassurvey={previewSurvey}activePageIndex={activePageIndex}- isConfirmation={isConfirmationSelected}+ pageKind={pageKind}viewport={viewport}/><HostedSurveySettingsPanelactivePageIndex={activePageIndex}- isConfirmation={isConfirmationSelected}+ pageKind={pageKind}viewport={viewport}onViewportChange={setViewport}+ onRemoveIntro={removeIntroScreen}onRemoveConfirmation={removeConfirmationScreen}/></div>diff --git a/frontend/src/scenes/surveys/hosted-canvas/HostedSurveyCanvas.scss b/frontend/src/scenes/surveys/hosted-canvas/HostedSurveyCanvas.scssindex 2a27c3824519..178b9a5a9ea1 100644--- a/frontend/src/scenes/surveys/hosted-canvas/HostedSurveyCanvas.scss+++ b/frontend/src/scenes/surveys/hosted-canvas/HostedSurveyCanvas.scss@@ -44,7 +44,8 @@// 3. Titles compress slightly on phones..survey-question,- .thank-you-message-header {+ .thank-you-message-header,+ .intro-screen-header {font-size: 1.5rem;}}diff --git a/frontend/src/scenes/surveys/hosted-canvas/HostedSurveyCanvas.test.tsx b/frontend/src/scenes/surveys/hosted-canvas/HostedSurveyCanvas.test.tsxnew file mode 100644index 000000000000..0b3b648fb86f--- /dev/null+++ b/frontend/src/scenes/surveys/hosted-canvas/HostedSurveyCanvas.test.tsx@@ -0,0 +1,150 @@+import '@testing-library/jest-dom'++import { cleanup, fireEvent, render, screen } from '@testing-library/react'+import { BindLogic } from 'kea'++import { surveyLogic } from 'scenes/surveys/surveyLogic'+import { getSurveyWithTranslatedContent } from 'scenes/surveys/surveyTranslationUtils'++import { useMocks } from '~/mocks/jest'+import { initKeaTests } from '~/test/init'+import { AccessControlLevel, Survey, SurveyQuestionType, SurveySchedule, SurveyType } from '~/types'++import { HostedSurveyCanvas } from './HostedSurveyCanvas'++const baseSurvey: Survey = {+ id: 'test-survey',+ name: 'Test survey',+ description: '',+ type: SurveyType.ExternalSurvey,+ linked_flag: null,+ linked_flag_id: null,+ targeting_flag: null,+ questions: [{ type: SurveyQuestionType.Open, question: 'What do you think?', description: '' }],+ conditions: null,+ appearance: {+ displayIntroScreen: true,+ introScreenHeader: 'Welcome',+ displayThankYouMessage: true,+ thankYouMessageHeader: 'Thanks',+ },+ translations: { fr: { introScreenHeader: 'Bienvenue', thankYouMessageHeader: 'Merci' } },+ created_at: '2026-01-01T00:00:00.000Z',+ created_by: null,+ start_date: null,+ end_date: null,+ archived: false,+ targeting_flag_filters: undefined,+ responses_limit: null,+ schedule: SurveySchedule.Once,+ user_access_level: AccessControlLevel.Editor,+}++describe('HostedSurveyCanvas', () => {+ beforeEach(() => {+ useMocks({+ get: {+ '/api/projects/:team/surveys/': () => [200, { count: 0, results: [], next: null, previous: null }],+ '/api/projects/:team/surveys/test-survey/': () => [200, baseSurvey],+ '/api/projects/:team/surveys/responses_count': () => [200, {}],+ },+ patch: {+ '/api/environments/:team_id/add_product_intent/': () => [200, {}],+ },+ })+ initKeaTests()+ })++ afterEach(cleanup)++ it.each([+ ['intro', 'intro', 'Intro header', 'introScreenHeader', 'thankYouMessageHeader', 'Thanks'],+ ['confirmation', 'confirmation', 'Thank you header', 'thankYouMessageHeader', 'introScreenHeader', 'Welcome'],+ ] as const)(+ 'editing the %s while a translation is shown keeps the untouched base text',+ (_name, pageKind, ariaLabel, editedField, untouchedField, untouchedBaseValue) => {+ const logic = surveyLogic({ id: baseSurvey.id })+ logic.mount()+ logic.actions.loadSurveySuccess(baseSurvey)++ render(+ <BindLogic logic={surveyLogic} props={{ id: baseSurvey.id }}>+ <HostedSurveyCanvas+ survey={getSurveyWithTranslatedContent(baseSurvey, 'fr')}+ activePageIndex={pageKind === 'intro' ? -1 : 1}+ pageKind={pageKind}+ viewport="desktop"+ />+ </BindLogic>+ )+ fireEvent.click(screen.getByLabelText(ariaLabel))+ fireEvent.change(screen.getByLabelText(ariaLabel), { target: { value: 'Edited' } })+ fireEvent.blur(screen.getByLabelText(ariaLabel))++ expect(logic.values.survey.appearance?.[editedField]).toBe('Edited')+ expect(logic.values.survey.appearance?.[untouchedField]).toBe(untouchedBaseValue)+ }+ )++ it('keeps a typed intro description editable when the content type was unset', () => {+ const survey: Survey = {+ ...baseSurvey,+ appearance: {+ ...baseSurvey.appearance,+ introScreenDescription: '',+ introScreenDescriptionContentType: undefined,+ },+ }+ const logic = surveyLogic({ id: survey.id })+ logic.mount()+ logic.actions.loadSurveySuccess(survey)+ const renderCanvas = (): JSX.Element => (+ <BindLogic logic={surveyLogic} props={{ id: survey.id }}>+ <HostedSurveyCanvas+ survey={logic.values.survey as Survey}+ activePageIndex={-1}+ pageKind="intro"+ viewport="desktop"+ />+ </BindLogic>+ )+ const { rerender } = render(renderCanvas())++ for (const text of ['First draft', 'Second draft']) {+ fireEvent.click(screen.getByLabelText('Intro description'))+ fireEvent.change(screen.getByLabelText('Intro description'), { target: { value: text } })+ fireEvent.blur(screen.getByLabelText('Intro description'))+ rerender(renderCanvas())+ }++ expect(logic.values.survey.appearance?.introScreenDescription).toBe('Second draft')+ expect(logic.values.survey.appearance?.introScreenDescriptionContentType).toBe('text')+ })++ it.each([+ ['an unset content type', undefined, true],+ ['an html content type', 'html', true],+ ['a text content type', 'text', false],+ ] as const)('renders the intro description as %s', (_name, contentType, rendersHtml) => {+ const survey: Survey = {+ ...baseSurvey,+ appearance: {+ ...baseSurvey.appearance,+ introScreenDescription: '<b>Takes a minute</b>',+ introScreenDescriptionContentType: contentType,+ },+ }+ const logic = surveyLogic({ id: survey.id })+ logic.mount()+ logic.actions.loadSurveySuccess(survey)++ render(+ <BindLogic logic={surveyLogic} props={{ id: survey.id }}>+ <HostedSurveyCanvas survey={survey} activePageIndex={-1} pageKind="intro" viewport="desktop" />+ </BindLogic>+ )++ expect(!!screen.queryByText('Takes a minute')).toBe(rendersHtml)+ expect(!!screen.queryByLabelText('Intro description')).toBe(!rendersHtml)+ })+})diff --git a/frontend/src/scenes/surveys/hosted-canvas/HostedSurveyCanvas.tsx b/frontend/src/scenes/surveys/hosted-canvas/HostedSurveyCanvas.tsxindex 4cd125bf76b3..9853284ed218 100644--- a/frontend/src/scenes/surveys/hosted-canvas/HostedSurveyCanvas.tsx+++ b/frontend/src/scenes/surveys/hosted-canvas/HostedSurveyCanvas.tsx@@ -24,7 +24,9 @@ import {} from '~/types'import { type NewSurvey } from '../constants'+import { type HostedSurveyPageKind } from './hostedSurveyPageKind'import { InlineEditable } from './InlineEditable'+import { IntroCanvas } from './IntroCanvas'// Per-scale lists mirroring posthog-js emojiScaleLists; scale 2 (thumbs) renders icons instead.const RATING_EMOJI_PREVIEW: Record<number, string[]> = {@@ -145,8 +147,11 @@ function buildCanvasStyles(appearance: SurveyAppearance, progress: number): Canv}}-function getProgress(survey: Survey | NewSurvey, pageIndex: number): number {- if (pageIndex >= survey.questions.length) {+function getProgress(survey: Survey | NewSurvey, pageIndex: number, pageKind: HostedSurveyPageKind): number {+ if (pageKind === 'intro') {+ return 0+ }+ if (pageKind === 'confirmation') {return 100}if (survey.questions.length === 0) {@@ -158,8 +163,7 @@ function getProgress(survey: Survey | NewSurvey, pageIndex: number): number {interface HostedSurveyCanvasProps {survey: Survey | NewSurveyactivePageIndex: number- /** True when active page is the confirmation/thank-you screen. */- isConfirmation: boolean+ pageKind: HostedSurveyPageKind/** Mobile vs desktop frame for visual context. */viewport: 'desktop' | 'mobile'}@@ -167,11 +171,11 @@ interface HostedSurveyCanvasProps {export function HostedSurveyCanvas({survey,activePageIndex,- isConfirmation,+ pageKind,viewport,}: HostedSurveyCanvasProps): JSX.Element {const appearance = buildCanvasAppearance(survey)- const progress = getProgress(survey, activePageIndex)+ const progress = getProgress(survey, activePageIndex, pageKind)const styles = buildCanvasStyles(appearance, progress)const activeQuestion = survey.questions[activePageIndex] as SurveyQuestion | undefinedconst frameClassName =@@ -197,7 +201,9 @@ export function HostedSurveyCanvas({</div><div className="survey-stage"><div className="posthog-survey-container">- {isConfirmation ? (+ {pageKind === 'intro' ? (+ <IntroCanvas survey={survey} />+ ) : pageKind === 'confirmation' ? (<ConfirmationCanvas survey={survey} />) : activeQuestion ? (<QuestionCanvas question={activeQuestion} index={activePageIndex} />@@ -649,11 +655,12 @@ function RatingCanvas({}function ConfirmationCanvas({ survey }: { survey: Survey | NewSurvey }): JSX.Element {+ const { survey: baseSurvey } = useValues(surveyLogic)const { setSurveyValue } = useActions(surveyLogic)const appearance = survey.appearance ?? {}const updateAppearance = (patch: Partial<NonNullable<(Survey | NewSurvey)['appearance']>>): void => {- setSurveyValue('appearance', { ...survey.appearance, ...patch })+ setSurveyValue('appearance', { ...baseSurvey.appearance, ...patch })}return (diff --git a/frontend/src/scenes/surveys/hosted-canvas/HostedSurveySettingsPanel.test.tsx b/frontend/src/scenes/surveys/hosted-canvas/HostedSurveySettingsPanel.test.tsxnew file mode 100644index 000000000000..c7e0fa4b5e7f--- /dev/null+++ b/frontend/src/scenes/surveys/hosted-canvas/HostedSurveySettingsPanel.test.tsx@@ -0,0 +1,76 @@+import '@testing-library/jest-dom'++import { cleanup, render, screen } from '@testing-library/react'+import { BindLogic } from 'kea'++import { surveyLogic } from 'scenes/surveys/surveyLogic'++import { useMocks } from '~/mocks/jest'+import { initKeaTests } from '~/test/init'+import { AccessControlLevel, Survey, SurveyAppearance, SurveyQuestionType, SurveySchedule, SurveyType } from '~/types'++import { HostedSurveySettingsPanel } from './HostedSurveySettingsPanel'++const buildSurvey = (appearance: SurveyAppearance): Survey => ({+ id: 'test-survey',+ name: 'Test survey',+ description: '',+ type: SurveyType.ExternalSurvey,+ linked_flag: null,+ linked_flag_id: null,+ targeting_flag: null,+ questions: [{ type: SurveyQuestionType.Open, question: 'What do you think?', description: '' }],+ conditions: null,+ appearance,+ created_at: '2026-01-01T00:00:00.000Z',+ created_by: null,+ start_date: null,+ end_date: null,+ archived: false,+ targeting_flag_filters: undefined,+ responses_limit: null,+ schedule: SurveySchedule.Once,+ user_access_level: AccessControlLevel.Editor,+})++describe('HostedSurveySettingsPanel', () => {+ beforeEach(() => {+ useMocks({+ get: {+ '/api/projects/:team/surveys/': () => [200, { count: 0, results: [], next: null, previous: null }],+ '/api/projects/:team/surveys/test-survey/': () => [200, buildSurvey({})],+ '/api/projects/:team/surveys/responses_count': () => [200, {}],+ },+ })+ initKeaTests()+ })++ afterEach(cleanup)++ it.each([+ ['an intro with no content', 'intro', { displayIntroScreen: true }, true],+ ['an intro with a header', 'intro', { displayIntroScreen: true, introScreenHeader: 'Welcome' }, false],+ ['the confirmation page', 'confirmation', { displayIntroScreen: true }, false],+ ] as const)('warns that the intro will not show for %s', (_name, pageKind, appearance, warns) => {+ const survey = buildSurvey(appearance)+ const logic = surveyLogic({ id: survey.id })+ logic.mount()+ logic.actions.loadSurveySuccess(survey)++ render(+ <BindLogic logic={surveyLogic} props={{ id: survey.id }}>+ <HostedSurveySettingsPanel+ activePageIndex={pageKind === 'intro' ? -1 : 1}+ pageKind={pageKind}+ viewport="desktop"+ onViewportChange={jest.fn()}+ onRemoveIntro={jest.fn()}+ onRemoveConfirmation={jest.fn()}+ />+ </BindLogic>+ )++ const warning = screen.queryByText("The intro screen won't show until it has a header or a description.")+ expect(!!warning).toBe(warns)+ })+})diff --git a/frontend/src/scenes/surveys/hosted-canvas/HostedSurveySettingsPanel.tsx b/frontend/src/scenes/surveys/hosted-canvas/HostedSurveySettingsPanel.tsxindex ee214ab6cc0c..fb246ee1ab72 100644--- a/frontend/src/scenes/surveys/hosted-canvas/HostedSurveySettingsPanel.tsx+++ b/frontend/src/scenes/surveys/hosted-canvas/HostedSurveySettingsPanel.tsx@@ -2,11 +2,19 @@ import { useActions, useValues } from 'kea'import { Group } from 'kea-forms'import { IconPhone, IconPlusSmall, IconTrash } from '@posthog/icons'-import { LemonButton, LemonCheckbox, LemonDialog, LemonSegmentedButton, LemonSelect } from '@posthog/lemon-ui'+import {+ LemonBanner,+ LemonButton,+ LemonCheckbox,+ LemonDialog,+ LemonSegmentedButton,+ LemonSelect,+} from '@posthog/lemon-ui'import { IconMonitor } from 'lib/lemon-ui/icons'import { QuestionBranchingInput } from 'scenes/surveys/components/question-branching/QuestionBranchingInput'import { SCALE_OPTIONS, SURVEY_RATING_SCALE, SurveyQuestionLabel } from 'scenes/surveys/constants'+import { isIntroScreenShown } from 'scenes/surveys/surveyIntroScreen'import { surveyLogic } from 'scenes/surveys/surveyLogic'import { canQuestionSkipSubmitButton, isThumbQuestion } from 'scenes/surveys/utils'@@ -17,15 +25,31 @@ import {SurveyQuestionType,} from '~/types'+import { type HostedSurveyPageKind } from './hostedSurveyPageKind'+interface HostedSurveySettingsPanelProps {/** Active page in the canvas — used to pick the question to render settings for. */activePageIndex: number- isConfirmation: boolean+ pageKind: HostedSurveyPageKindviewport: 'desktop' | 'mobile'onViewportChange: (viewport: 'desktop' | 'mobile') => void+ onRemoveIntro: () => voidonRemoveConfirmation: () => void}+const SCREEN_SETTINGS = {+ intro: {+ title: 'Intro screen',+ subtitle: 'Shown before the first question.',+ removeTooltip: 'Remove the intro screen',+ },+ confirmation: {+ title: 'End screen',+ subtitle: 'Shown after the final answer.',+ removeTooltip: 'Remove the end screen',+ },+} as const+const QUESTION_TYPE_OPTIONS = [{ label: SurveyQuestionLabel[SurveyQuestionType.Open], value: SurveyQuestionType.Open },{ label: 'Link / Notification', value: SurveyQuestionType.Link },@@ -41,9 +65,10 @@ const QUESTION_TYPE_OPTIONS = [*/export function HostedSurveySettingsPanel({activePageIndex,- isConfirmation,+ pageKind,viewport,onViewportChange,+ onRemoveIntro,onRemoveConfirmation,}: HostedSurveySettingsPanelProps): JSX.Element {const { survey } = useValues(surveyLogic)@@ -51,6 +76,7 @@ export function HostedSurveySettingsPanel({useActions(surveyLogic)const question = survey.questions[activePageIndex] as SurveyQuestion | undefined+ const screen = pageKind === 'question' ? null : SCREEN_SETTINGS[pageKind]const handleQuestionTypeChange = (newType: SurveyQuestionType): void => {if (!question) {@@ -99,29 +125,31 @@ export function HostedSurveySettingsPanel({return (<aside className="flex min-w-0 flex-col gap-4 rounded border bg-surface-primary p-4"><SettingsSection- title={isConfirmation ? 'End screen' : `Question ${activePageIndex + 1}`}+ title={screen ? screen.title : `Question ${activePageIndex + 1}`}subtitle={- isConfirmation- ? 'Shown after the final answer.'- : question- ? SurveyQuestionLabel[question.type]- : 'No question selected'+ screen ? screen.subtitle : question ? SurveyQuestionLabel[question.type] : 'No question selected'}actions={- isConfirmation ? (+ screen ? (<LemonButtontype="tertiary"size="small"status="danger"icon={<IconTrash />}- onClick={onRemoveConfirmation}- tooltip="Remove the end screen"+ onClick={pageKind === 'intro' ? onRemoveIntro : onRemoveConfirmation}+ tooltip={screen.removeTooltip}/>) : null}/>- {!isConfirmation && question ? (+ {pageKind === 'intro' && !isIntroScreenShown(survey.appearance) ? (+ <LemonBanner type="warning">+ The intro screen won't show until it has a header or a description.+ </LemonBanner>+ ) : null}++ {pageKind === 'question' && question ? (<><LabelledControl label="Type"><LemonSelect@@ -202,9 +230,9 @@ export function HostedSurveySettingsPanel({/>)}- {/* Keep this block inside the `!isConfirmation && question` guard: the Group- binds to `questions.${activePageIndex}`, which is only a valid question- index for real questions, never the confirmation page. */}+ {/* Keep this block inside the `pageKind === 'question' && question` guard: the+ Group binds to `questions.${activePageIndex}`, which is only a valid question+ index for real questions, never the intro or confirmation page. */}<div className="border-t pt-3"><SettingsSectiontitle="Branching"diff --git a/frontend/src/scenes/surveys/hosted-canvas/IntroCanvas.tsx b/frontend/src/scenes/surveys/hosted-canvas/IntroCanvas.tsxnew file mode 100644index 000000000000..edd9c8149e8c--- /dev/null+++ b/frontend/src/scenes/surveys/hosted-canvas/IntroCanvas.tsx@@ -0,0 +1,64 @@+import { useActions, useValues } from 'kea'++import { getIntroScreenDescriptionContentType } from 'scenes/surveys/surveyIntroScreen'+import { surveyLogic } from 'scenes/surveys/surveyLogic'+import { sanitizeHTML } from 'scenes/surveys/utils'++import { type Survey } from '~/types'++import { type NewSurvey } from '../constants'+import { InlineEditable } from './InlineEditable'++export function IntroCanvas({ survey }: { survey: Survey | NewSurvey }): JSX.Element {+ const { survey: baseSurvey } = useValues(surveyLogic)+ const { setSurveyValue } = useActions(surveyLogic)+ const appearance = survey.appearance ?? {}++ const updateAppearance = (patch: Partial<NonNullable<(Survey | NewSurvey)['appearance']>>): void => {+ setSurveyValue('appearance', { ...baseSurvey.appearance, ...patch })+ }++ return (+ <div className="intro-screen">+ <InlineEditable+ as="h1"+ className="intro-screen-header"+ value={appearance.introScreenHeader || ''}+ onChange={(value) => updateAppearance({ introScreenHeader: value })}+ placeholder="Help us improve"+ ariaLabel="Intro header"+ />+ {getIntroScreenDescriptionContentType(appearance) === 'html' && appearance.introScreenDescription ? (+ // HTML descriptions keep their rendered form; v1 doesn't inline-edit raw HTML.+ <div+ className="intro-screen-body"+ dangerouslySetInnerHTML={{ __html: sanitizeHTML(appearance.introScreenDescription) }}+ />+ ) : (+ <InlineEditable+ as="p"+ className="intro-screen-body"+ value={appearance.introScreenDescription || ''}+ onChange={(value) =>+ updateAppearance({+ introScreenDescription: value,+ introScreenDescriptionContentType: 'text',+ })+ }+ placeholder="Add an opening message (optional)"+ ariaLabel="Intro description"+ multiline+ />+ )}+ <div className="bottom-section">+ <InlineEditable+ value={appearance.introScreenButtonText || ''}+ onChange={(value) => updateAppearance({ introScreenButtonText: value })}+ placeholder="Get started"+ ariaLabel="Intro button label"+ className="form-submit"+ />+ </div>+ </div>+ )+}diff --git a/frontend/src/scenes/surveys/hosted-canvas/hostedSurveyPageKind.test.ts b/frontend/src/scenes/surveys/hosted-canvas/hostedSurveyPageKind.test.tsnew file mode 100644index 000000000000..9e0cf093b4ed--- /dev/null+++ b/frontend/src/scenes/surveys/hosted-canvas/hostedSurveyPageKind.test.ts@@ -0,0 +1,22 @@+import { Survey } from '~/types'++import { getHostedSurveyPageKind } from './hostedSurveyPageKind'++describe('getHostedSurveyPageKind', () => {+ it.each([+ ['intro page with the intro enabled', -1, { displayIntroScreen: true }, 'intro'],+ ['first question with the intro enabled', 0, { displayIntroScreen: true }, 'question'],+ ['intro index with the intro disabled', -1, { displayThankYouMessage: true }, 'question'],+ [+ 'page after the last question with the confirmation enabled',+ 2,+ { displayThankYouMessage: true },+ 'confirmation',+ ],+ ['page after the last question with the confirmation disabled', 2, {}, 'question'],+ ] as const)('%s', (_name, pageIndex, appearance, expected) => {+ const survey = { questions: [{}, {}], appearance } as Survey++ expect(getHostedSurveyPageKind(survey, pageIndex)).toBe(expected)+ })+})diff --git a/frontend/src/scenes/surveys/hosted-canvas/hostedSurveyPageKind.ts b/frontend/src/scenes/surveys/hosted-canvas/hostedSurveyPageKind.tsnew file mode 100644index 000000000000..1b6c04ce7faa--- /dev/null+++ b/frontend/src/scenes/surveys/hosted-canvas/hostedSurveyPageKind.ts@@ -0,0 +1,15 @@+import { Survey } from '~/types'++import { INTRO_SCREEN_PAGE_INDEX, NewSurvey } from '../constants'++export type HostedSurveyPageKind = 'intro' | 'question' | 'confirmation'++export function getHostedSurveyPageKind(survey: Survey | NewSurvey, pageIndex: number): HostedSurveyPageKind {+ if (survey.appearance?.displayIntroScreen && pageIndex === INTRO_SCREEN_PAGE_INDEX) {+ return 'intro'+ }+ if (survey.appearance?.displayThankYouMessage && pageIndex === survey.questions.length) {+ return 'confirmation'+ }+ return 'question'+}