: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 back button option to the survey editor (#62812)
Lucas Fariae9985b5a9a8b
diff --git a/frontend/public/surveys/hosted-survey.css b/frontend/public/surveys/hosted-survey.cssindex b6c3f960e273..2874ad4670e4 100644--- a/frontend/public/surveys/hosted-survey.css+++ b/frontend/public/surveys/hosted-survey.css@@ -426,6 +426,43 @@ body.PostHogHostedSurvey {opacity: 1;}+.PostHogHostedSurvey .form-buttons {+ display: flex;+ flex-flow: row wrap;+ gap: 0.875rem 1rem;+ align-items: center;+}++.PostHogHostedSurvey .form-back {+ min-width: 7rem;+ min-height: 3rem;+ padding: 0.75rem 1.5rem;+ font: inherit;+ font-size: 1rem;+ font-weight: 600;++ /* Question text color so the label stays readable on any background. */+ color: var(--ph-survey-text-primary-color, #111);+ cursor: pointer;+ user-select: none;+ background: transparent;+ border: 1.5px solid var(--ph-survey-border-color, rgb(17 17 17 / 10%));+ border-radius: var(--ph-survey-border-radius, 10px);+ transition:+ opacity 140ms ease,+ transform 140ms ease,+ color 140ms ease;+}++.PostHogHostedSurvey .form-back:hover {+ opacity: 0.92;+ transform: translateY(-1px);+}++.PostHogHostedSurvey .form-back:active {+ transform: scale(0.98);+}+.PostHogHostedSurvey .footer-branding {z-index: 10;display: inline-flex;diff --git a/frontend/snapshots.yml b/frontend/snapshots.ymlindex 3b53d2fd7ad0..63c67b4ae829 100644--- a/frontend/snapshots.yml+++ b/frontend/snapshots.yml@@ -5991,9 +5991,9 @@ snapshots:scenes-app-settings-environment--settings-environment-revenue-analytics--light:hash: v1.k794b7964.04851f0a142107a0ca73c531427a593a575f3bec7881fb44d73d9b1f48e458ed.Hkxoqoh3ny3AqLOdF74bFN-N3tzTotBhQB7F4iBVdrkscenes-app-settings-environment--settings-environment-surveys--dark:- hash: v1.k794b7964.fe811f7826d3103a70b79b54fbfe0ea61e730daecf90e824c16254969d443f55.-d8-KDjlHFr2I6wPUoKBbw7jFEtMQVueTTuGteUxsZk+ hash: v1.k794b7964.ccc19cc1b470ab11f5e2c97924e6a17429b3677f1da846d84285434dc1b12dbb.qsa8VudJgOk77De_910PoqQQbpJRgFfdRAcS5n7YAcgscenes-app-settings-environment--settings-environment-surveys--light:- hash: v1.k794b7964.e53e2074b69b9848b6c143f9a4c1da28113064eeb94476cb29c419f3134eb8e6.Z-igIs9gPsshRLKDL9hzt8JSXNUhd1NZ1yI2ffUxkLk+ hash: v1.k794b7964.7c73464003f05a2ffb000cd73a5b5d0fcf9858e478acd7dc28e657bc88ed8f67.AxcEcVcod65KqgCexhT1dFon9ieEo66EBq2xAA-3Wdoscenes-app-settings-environment--settings-environment-web-analytics--dark:hash: v1.k794b7964.0f233886788b9f18aef311921579318427f04141fb1503a56105ba245ac3fa4e.vgLQFSwpcl9PCxwS8RT8vpU02mqhHOc3eVkKdM5vnU0scenes-app-settings-environment--settings-environment-web-analytics--light:@@ -6059,9 +6059,9 @@ snapshots:scenes-app-settings-project--settings-project-replay--light:hash: v1.k794b7964.c9478fa31ea024f0f01038d33f41d359ad02c809d0a2eb3868e382c39f7dc91f.ZtIw0iZbRRa0-Q7jRSLBfSr8h220b0TcGA8bqRIAT-gscenes-app-settings-project--settings-project-surveys--dark:- hash: v1.k794b7964.fcd7c3f51e479c01cd914eb2ae65deb88561074aac19f2135ec15b7435487207.M2If7pEUuhyfgfGTbxgjef9HYzpGwAI97z9Hfdyxrlo+ hash: v1.k794b7964.9de7aa543fc7e1921df96fc61c58ee45edcab684082c3b030a7fab17ca7d8188.KTsEcD3ill1gnaBMK9ftFDSVWv5qvgfy-fyMhjSPX0Iscenes-app-settings-project--settings-project-surveys--light:- hash: v1.k794b7964.104a6bec174029e27b7da3add529fed34ece774a899eaf8577221f3dc5f7667e.a4Rq8-EKVDpDuQSAinApWFnk87V20wUZLeQ_jnhVlF0+ hash: v1.k794b7964.292492b384495e9ca389151687fa504c001a013a360542f3eaea1c96bef4e258.Mhavj0kTzgkEwgmYCmbONFwEf44hCXf8IxLpPMXxtz0scenes-app-settings-user--settings-user-api-keys--dark:hash: v1.k794b7964.3eacfbb0f25c2ce0e4c29de4b98b272d552eab85f77a7666262596375cf17a23.BxuGgAF0n5ON-eYosJKw-skkRU0yZTU1jOWAwAKLbXIscenes-app-settings-user--settings-user-api-keys--light:@@ -6151,9 +6151,9 @@ snapshots:scenes-app-surveys--new-survey--light:hash: v1.k794b7964.3e417546463c9173b5e53e299b5bba005b021668b9061d946f13a056cc106be6.-O9LwsJxY6CNrcfWhZ-eTILm7pSwsSYsYIfe9-8PCZAscenes-app-surveys--new-survey-customisation-section--dark:- hash: v1.k794b7964.951e2436f63b51b81ea5eafa2518daebbc0dd4fbc91815c5fbf77fd707f613f4.gYlPcgks_iU0epfsI-rgBz4Hnt3uUoHFJ2QykvFrwc0+ hash: v1.k794b7964.2c01809bc1c28eb8368b9edae82851c9055fa5e6945a077dbecae09bad8c7bc4.XUSEQL7XnRP4zu6kOle-M6yEuh8clS3NXnwXMk4oZMYscenes-app-surveys--new-survey-customisation-section--light:- hash: v1.k794b7964.288fec0f91326deccbaf9910189134f14be62162013df6c8364e438e90e095cc.IuLmX5ajln3b3KtOTFFdHZMGlJk9iaCRitsBWvb2bzU+ hash: v1.k794b7964.c8a77d09dddf9313dd30abdf4efaca272659a218796dcefd52d39ddd62bf6fc5.DroPH2PZyADyGtp6e0Hbb7KoTkn4YZatjzWp15VZBYwscenes-app-surveys--new-survey-targeting-section--dark:hash: v1.k794b7964.291b22007c1e8f4fd06d46e9c7d1f87ae70ebd3ec766328340ad89ea3f2ab16b.xS2De9yYBV2JVrvQlzbqMjD2i3HpALi7iVI7TczcfdIscenes-app-surveys--new-survey-targeting-section--light:@@ -6167,9 +6167,9 @@ snapshots:scenes-app-surveys--new-survey-with-text-question-description-that-does-not-render-html--light:hash: v1.k794b7964.da042d485c41af9617b77ef27301d4a4a2b693e8e301199ee0ab270d289b023a.ygKH5sOow6s1H1TEjac-I9uemRPLdaaqpAcFFvmOWnEscenes-app-surveys--surveys-global-settings--dark:- hash: v1.k794b7964.2764ff2aa3042dc8c552711a02c208d295cc41725ac962ab126020751f96916a.KzHRBiHIqzLz4IrA_-guvYmYc-MWU9MiuQT4hjPxtAg+ hash: v1.k794b7964.427cfe9d37f22f4541a7229a96d8911f0a952d21249e07b33e7ee6e52a29c5ba.G5JF2D7oalvStlE95BvDNYjoSVukCgnScl8oOVxIOSsscenes-app-surveys--surveys-global-settings--light:- hash: v1.k794b7964.3ad76c80e61a19734ea9ff275620b874c2cffc3021a8325ac90f1d2ffb75acff.Hxa-zfbCJqIbFXC21H3vWNQa_by4uLNKUdEaFptE1oo+ hash: v1.k794b7964.5632c4905d65137c0e8640a81bb90ba4d4ccf45932669df0132def05274dc357.c3Gya7Cu9PAljYl5NstZ92nXL2liftgZKKFwdTsOLuMscenes-app-surveys--surveys-list--dark:hash: v1.k794b7964.c4f8be2d8a16e5c0d2af0c328afd13c81eadabe39254faf0425e4be15038f2d0.oDhX1xzvLKZb4fA-nS1RHH0HT0wGkExsBJZki_2_1eYscenes-app-surveys--surveys-list--light:diff --git a/frontend/src/queries/schema.json b/frontend/src/queries/schema.jsonindex ddfcb029ee64..92c8d3771cde 100644--- a/frontend/src/queries/schema.json+++ b/frontend/src/queries/schema.json@@ -40592,6 +40592,12 @@"SurveyAppearanceSchema": {"additionalProperties": false,"properties": {+ "allowGoBack": {+ "type": "boolean"+ },+ "backButtonText": {+ "type": "string"+ },"backgroundColor": {"type": "string"},diff --git a/frontend/src/queries/schema/schema-surveys.ts b/frontend/src/queries/schema/schema-surveys.tsindex f06717c130dd..34da9041cec1 100644--- a/frontend/src/queries/schema/schema-surveys.ts+++ b/frontend/src/queries/schema/schema-surveys.ts@@ -98,6 +98,8 @@ export interface SurveyAppearanceSchema {thankYouMessageCloseButtonText?: stringshuffleQuestions?: booleansurveyPopupDelaySeconds?: number+ allowGoBack?: boolean+ backButtonText?: stringwidgetType?: SurveyWidgetTypewidgetLabel?: stringwidgetSelector?: stringdiff --git a/frontend/src/scenes/surveys/HostedSurveyEdit.tsx b/frontend/src/scenes/surveys/HostedSurveyEdit.tsxindex e05d1df7a7b2..8a303068a5f4 100644--- a/frontend/src/scenes/surveys/HostedSurveyEdit.tsx+++ b/frontend/src/scenes/surveys/HostedSurveyEdit.tsx@@ -25,6 +25,7 @@ import { SortableDragIcon } from 'lib/lemon-ui/icons'import { LemonField } from 'lib/lemon-ui/LemonField'import { featureFlagLogic } from 'lib/logic/featureFlagLogic'import { Customization } from 'scenes/surveys/survey-appearance/SurveyCustomization'+import { SurveyTranslationFields } from 'scenes/surveys/SurveyTranslationFields'import { SurveyTranslations } from 'scenes/surveys/SurveyTranslations'import { getSurveyWithTranslatedContent } from 'scenes/surveys/surveyTranslationUtils'import { sanitizeSurveyAppearance, validateSurveyAppearance } from 'scenes/surveys/utils'@@ -606,6 +607,7 @@ export function HostedSurveyEdit({ id }: { id: string }): JSX.Element {</div>) : null}<SurveyTranslations />+ {activeLanguage ? <SurveyTranslationFields activeLanguage={activeLanguage} /> : null}</div></section>) : null}@@ -623,6 +625,9 @@ export function HostedSurveyEdit({ id }: { id: string }): JSX.Element {survey={survey}hasBranchingLogic={hasBranchingLogic}deleteBranchingLogic={deleteBranchingLogic}+ onTranslationsChange={(translations) =>+ setSurveyValue('translations', translations)+ }hasRatingButtons={survey.questions.some((question) => question.type === SurveyQuestionType.Rating)}diff --git a/frontend/src/scenes/surveys/SurveyAppearancePreview.tsx b/frontend/src/scenes/surveys/SurveyAppearancePreview.tsxindex 2cc352e8735a..8e9990cd6d04 100644--- a/frontend/src/scenes/surveys/SurveyAppearancePreview.tsx+++ b/frontend/src/scenes/surveys/SurveyAppearancePreview.tsx@@ -11,6 +11,7 @@ interface Props {survey: Survey | NewSurveypreviewPageIndex: numberonPreviewSubmit?: (res: string | string[] | number | null) => void+ onPreviewBack?: () => voidpositionStyles?: React.CSSProperties}@@ -31,6 +32,7 @@ export function SurveyAppearancePreview({survey,previewPageIndex,onPreviewSubmit = () => {},+ onPreviewBack = () => {},positionStyles = DEFAULT_POSITION_STYLES,}: Props): JSX.Element {const surveyPreviewRef = useRef<HTMLDivElement>(null)@@ -55,6 +57,7 @@ export function SurveyAppearancePreview({parentElement: surveyPreviewRef.current,previewPageIndex,onPreviewSubmit,+ onPreviewBack,positionStyles,})}@@ -65,7 +68,7 @@ export function SurveyAppearancePreview({root: feedbackWidgetPreviewRef.current,})}- }, [survey, previewPageIndex, onPreviewSubmit, positionStyles]) // oxlint-disable-line react-hooks/exhaustive-deps+ }, [survey, previewPageIndex, onPreviewSubmit, onPreviewBack, positionStyles]) // oxlint-disable-line react-hooks/exhaustive-depsreturn <div ref={surveyPreviewRef} className="flex w-full min-w-0 justify-center" />}diff --git a/frontend/src/scenes/surveys/SurveyEdit.tsx b/frontend/src/scenes/surveys/SurveyEdit.tsxindex 8c92713ae540..dfcfbc98c613 100644--- a/frontend/src/scenes/surveys/SurveyEdit.tsx+++ b/frontend/src/scenes/surveys/SurveyEdit.tsx@@ -1319,6 +1319,9 @@ export default function SurveyEdit({ id }: { id: string }): JSX.Element {survey={survey}hasBranchingLogic={hasBranchingLogic}deleteBranchingLogic={deleteBranchingLogic}+ onTranslationsChange={(translations) =>+ setSurveyValue('translations', translations)+ }hasRatingButtons={survey.questions.some((question) =>question.type === SurveyQuestionType.Ratingdiff --git a/frontend/src/scenes/surveys/SurveyFormAppearance.tsx b/frontend/src/scenes/surveys/SurveyFormAppearance.tsxindex dcdfa93b4445..ade0c7796e86 100644--- a/frontend/src/scenes/surveys/SurveyFormAppearance.tsx+++ b/frontend/src/scenes/surveys/SurveyFormAppearance.tsx@@ -44,6 +44,7 @@ export function SurveyFormAppearance({nextStep === SurveyQuestionBranchingType.End ? survey.questions.length : nextStep)}}+ onPreviewBack={() => handleSetSelectedPageIndex(Math.max(0, previewPageIndex - 1))}/><LemonField.Pure label="Current question" className="max-w-xs gap-1" htmlFor="current-question-select"><LemonSelectdiff --git a/frontend/src/scenes/surveys/SurveyTranslationFields.tsx b/frontend/src/scenes/surveys/SurveyTranslationFields.tsxnew file mode 100644index 000000000000..e0b757f85806--- /dev/null+++ b/frontend/src/scenes/surveys/SurveyTranslationFields.tsx@@ -0,0 +1,262 @@+import { useActions, useValues } from 'kea'++import { LemonInput, LemonTag, LemonTextArea } from '@posthog/lemon-ui'++import { LemonField } from 'lib/lemon-ui/LemonField'++import { SurveyQuestion } from '~/types'++import { defaultSurveyAppearance } from './constants'+import { isChoiceQuestion, isLinkQuestion, isRatingQuestion } from './questionTypeGuards'+import { surveyLogic } from './surveyLogic'++type QuestionTranslation = NonNullable<SurveyQuestion['translations']>[string]++function GuidedTranslationInput({+ label,+ value,+ source,+ onChange,+ multiline = false,+ aiGenerated = false,+}: {+ label: string+ value: string+ source?: string | null+ onChange: (value: string) => void+ multiline?: boolean+ aiGenerated?: boolean+}): JSX.Element {+ const labelWithState = aiGenerated ? (+ <span className="flex items-center gap-1">+ <span>{label}</span>+ <LemonTag type="highlight">AI draft</LemonTag>+ </span>+ ) : (+ label+ )+ const aiGeneratedClassName = aiGenerated+ ? 'border border-dashed border-accent bg-accent-highlight-secondary'+ : undefined++ return (+ <LemonField.Pure label={labelWithState} className="gap-1">+ {multiline ? (+ <LemonTextArea+ value={value}+ onChange={onChange}+ placeholder={source || undefined}+ minRows={2}+ className={aiGeneratedClassName}+ />+ ) : (+ <LemonInput+ value={value}+ onChange={onChange}+ placeholder={source || undefined}+ fullWidth+ className={aiGeneratedClassName}+ />+ )}+ </LemonField.Pure>+ )+}++/**+ * Per-field translation inputs (questions, buttons, confirmation) for a single language.+ * Shared by the wizard's Translations step and the hosted survey editor, which provide+ * their own language-management chrome around it.+ */+export function SurveyTranslationFields({ activeLanguage }: { activeLanguage: string }): JSX.Element {+ const { survey, aiGeneratedTranslationFields } = useValues(surveyLogic)+ const { setSurveyValue, clearAiGeneratedTranslationField } = useActions(surveyLogic)++ const translations = survey.translations ?? {}+ const appearance = { ...defaultSurveyAppearance, ...survey.appearance }++ const updateSurveyTranslation = (updates: Partial<NonNullable<(typeof survey)['translations']>[string]>): void => {+ for (const field of Object.keys(updates)) {+ clearAiGeneratedTranslationField(`translations.${activeLanguage}.${field}`)+ }+ setSurveyValue('translations', {+ ...translations,+ [activeLanguage]: { ...translations[activeLanguage], ...updates },+ })+ }++ const updateQuestionTranslation = (questionIndex: number, updates: Partial<QuestionTranslation>): void => {+ for (const field of Object.keys(updates)) {+ clearAiGeneratedTranslationField(`questions.${questionIndex}.translations.${activeLanguage}.${field}`)+ }+ setSurveyValue(+ 'questions',+ survey.questions.map((question, index) => {+ if (index !== questionIndex) {+ return question+ }+ const questionTranslations = question.translations ?? {}+ return {+ ...question,+ translations: {+ ...questionTranslations,+ [activeLanguage]: { ...question.translations?.[activeLanguage], ...updates },+ },+ }+ })+ )+ }++ const updateChoiceTranslation = (questionIndex: number, choiceIndex: number, value: string): void => {+ const question = survey.questions[questionIndex]+ if (!isChoiceQuestion(question)) {+ return+ }+ const translatedChoices = [...(question.translations?.[activeLanguage]?.choices || question.choices || [])]+ translatedChoices[choiceIndex] = value+ clearAiGeneratedTranslationField(+ `questions.${questionIndex}.translations.${activeLanguage}.choices.${choiceIndex}`+ )+ updateQuestionTranslation(questionIndex, { choices: translatedChoices })+ }++ const isGeneratedSurveyField = (field: string): boolean =>+ aiGeneratedTranslationFields.includes(`translations.${activeLanguage}.${field}`)++ const isGeneratedQuestionField = (questionIndex: number, field: string): boolean =>+ aiGeneratedTranslationFields.includes(`questions.${questionIndex}.translations.${activeLanguage}.${field}`)++ const isGeneratedChoiceField = (questionIndex: number, choiceIndex: number): boolean =>+ aiGeneratedTranslationFields.includes(+ `questions.${questionIndex}.translations.${activeLanguage}.choices.${choiceIndex}`+ )++ return (+ <div className="space-y-6">+ {survey.questions.map((question, questionIndex) => {+ const questionTranslation = question.translations?.[activeLanguage] ?? {}+ const ratingQuestion = isRatingQuestion(question) ? question : null+ const linkQuestion = isLinkQuestion(question) ? question : null++ return (+ <section key={questionIndex} className="space-y-3">+ <h4 className="m-0 text-xs font-semibold uppercase tracking-wide text-muted">+ Question {questionIndex + 1}+ </h4>+ <GuidedTranslationInput+ label="Question"+ value={questionTranslation.question || ''}+ source={question.question}+ aiGenerated={isGeneratedQuestionField(questionIndex, 'question')}+ onChange={(questionText) =>+ updateQuestionTranslation(questionIndex, { question: questionText })+ }+ />+ {question.description ? (+ <GuidedTranslationInput+ label="Description"+ value={questionTranslation.description || ''}+ source={question.description}+ aiGenerated={isGeneratedQuestionField(questionIndex, 'description')}+ onChange={(description) => updateQuestionTranslation(questionIndex, { description })}+ multiline+ />+ ) : null}+ <GuidedTranslationInput+ label="Button text"+ value={questionTranslation.buttonText || ''}+ source={+ question.buttonText ||+ (linkQuestion ? 'Continue' : appearance.submitButtonText || 'Submit')+ }+ aiGenerated={isGeneratedQuestionField(questionIndex, 'buttonText')}+ onChange={(buttonText) => updateQuestionTranslation(questionIndex, { buttonText })}+ />+ {ratingQuestion ? (+ <div className="grid gap-3 sm:grid-cols-2">+ <GuidedTranslationInput+ label="Lower label"+ value={questionTranslation.lowerBoundLabel || ''}+ source={ratingQuestion.lowerBoundLabel}+ aiGenerated={isGeneratedQuestionField(questionIndex, 'lowerBoundLabel')}+ onChange={(lowerBoundLabel) =>+ updateQuestionTranslation(questionIndex, { lowerBoundLabel })+ }+ />+ <GuidedTranslationInput+ label="Upper label"+ value={questionTranslation.upperBoundLabel || ''}+ source={ratingQuestion.upperBoundLabel}+ aiGenerated={isGeneratedQuestionField(questionIndex, 'upperBoundLabel')}+ onChange={(upperBoundLabel) =>+ updateQuestionTranslation(questionIndex, { upperBoundLabel })+ }+ />+ </div>+ ) : null}+ {isChoiceQuestion(question) ? (+ <div className="grid gap-2 sm:grid-cols-2">+ {question.choices.map((choice, choiceIndex) => (+ <GuidedTranslationInput+ key={choiceIndex}+ label={`Choice ${choiceIndex + 1}`}+ value={questionTranslation.choices?.[choiceIndex] || ''}+ source={choice}+ aiGenerated={isGeneratedChoiceField(questionIndex, choiceIndex)}+ onChange={(value) => updateChoiceTranslation(questionIndex, choiceIndex, value)}+ />+ ))}+ </div>+ ) : null}+ {linkQuestion ? (+ <GuidedTranslationInput+ label="Link URL"+ value={questionTranslation.link || ''}+ source={linkQuestion.link}+ aiGenerated={isGeneratedQuestionField(questionIndex, 'link')}+ onChange={(link) => updateQuestionTranslation(questionIndex, { link })}+ />+ ) : null}+ </section>+ )+ })}++ {appearance.displayThankYouMessage ? (+ <section className="space-y-3">+ <h4 className="m-0 text-xs font-semibold uppercase tracking-wide text-muted">+ Confirmation screen+ </h4>+ <GuidedTranslationInput+ label="Header"+ value={translations[activeLanguage]?.thankYouMessageHeader || ''}+ source={appearance.thankYouMessageHeader}+ aiGenerated={isGeneratedSurveyField('thankYouMessageHeader')}+ onChange={(thankYouMessageHeader) => updateSurveyTranslation({ thankYouMessageHeader })}+ />+ {appearance.thankYouMessageDescription ? (+ <GuidedTranslationInput+ label="Description"+ value={translations[activeLanguage]?.thankYouMessageDescription || ''}+ source={appearance.thankYouMessageDescription}+ aiGenerated={isGeneratedSurveyField('thankYouMessageDescription')}+ onChange={(thankYouMessageDescription) =>+ updateSurveyTranslation({ thankYouMessageDescription })+ }+ multiline+ />+ ) : null}+ {appearance.thankYouMessageCloseButtonText ? (+ <GuidedTranslationInput+ label="Close button"+ value={translations[activeLanguage]?.thankYouMessageCloseButtonText || ''}+ source={appearance.thankYouMessageCloseButtonText}+ aiGenerated={isGeneratedSurveyField('thankYouMessageCloseButtonText')}+ onChange={(thankYouMessageCloseButtonText) =>+ updateSurveyTranslation({ thankYouMessageCloseButtonText })+ }+ />+ ) : null}+ </section>+ ) : null}+ </div>+ )+}diff --git a/frontend/src/scenes/surveys/constants.tsx b/frontend/src/scenes/surveys/constants.tsxindex df72968e067c..0de05407f4b5 100644--- a/frontend/src/scenes/surveys/constants.tsx+++ b/frontend/src/scenes/surveys/constants.tsx@@ -660,6 +660,7 @@ export const defaultSurveyTemplates: SurveyTemplate[] = [...defaultSurveyAppearance,displayThankYouMessage: true,thankYouMessageHeader: 'Thanks — we will be in touch shortly!',+ allowGoBack: true,},description: 'Recruit research participants via a shareable link.',tagType: 'completion',@@ -719,6 +720,7 @@ export const defaultSurveyTemplates: SurveyTemplate[] = [...defaultSurveyAppearance,displayThankYouMessage: true,thankYouMessageHeader: 'Thanks for sharing your perspective!',+ allowGoBack: true,},description: 'Go deep on segmentation, satisfaction, and roadmap signal.',tagType: 'primary',diff --git a/frontend/src/scenes/surveys/survey-appearance/SurveyBehaviorOptions.tsx b/frontend/src/scenes/surveys/survey-appearance/SurveyBehaviorOptions.tsxnew file mode 100644index 000000000000..4ac694bdf3f7--- /dev/null+++ b/frontend/src/scenes/surveys/survey-appearance/SurveyBehaviorOptions.tsx@@ -0,0 +1,114 @@+import { LemonCheckbox, LemonDialog, LemonDivider, LemonInput } from '@posthog/lemon-ui'++import { LemonField } from 'lib/lemon-ui/LemonField'+import { NewSurvey } from 'scenes/surveys/constants'++import { Survey, SurveyAppearance } from '~/types'++type SurveyTranslations = NonNullable<Survey['translations']>++interface SurveyBehaviorOptionsProps {+ survey: Survey | NewSurvey+ onAppearanceChange: (appearance: Partial<SurveyAppearance>) => void+ disabledReason?: string+ hasBranchingLogic?: boolean+ deleteBranchingLogic?: () => void+ /** When provided (i.e. inside the survey editor), enables inline per-language back button labels. */+ onTranslationsChange?: (translations: SurveyTranslations) => void+}++// Shared by the classic editor and the guided wizard so both expose the same behavior toggles.+export function SurveyBehaviorOptions({+ survey,+ onAppearanceChange,+ disabledReason,+ hasBranchingLogic,+ deleteBranchingLogic,+ onTranslationsChange,+}: SurveyBehaviorOptionsProps): JSX.Element {+ const translations: SurveyTranslations = survey.translations ?? {}+ const translatedLanguages = onTranslationsChange ? Object.keys(translations) : []++ const setBackButtonTranslation = (language: string, value: string): void => {+ onTranslationsChange?.({+ ...translations,+ [language]: { ...translations[language], backButtonText: value || undefined },+ })+ }++ return (+ <div className="flex flex-col gap-3">+ <LemonCheckbox+ disabledReason={disabledReason}+ label="Shuffle questions"+ onChange={(checked) => {+ if (checked && hasBranchingLogic) {+ onAppearanceChange({ shuffleQuestions: false })++ LemonDialog.open({+ title: 'Your survey has active branching logic',+ description: (+ <p className="py-2">+ Enabling this option will remove your branching logic. Are you sure you want to+ continue?+ </p>+ ),+ primaryButton: {+ children: 'Continue',+ status: 'danger',+ onClick: () => {+ deleteBranchingLogic?.()+ onAppearanceChange({ shuffleQuestions: true })+ },+ },+ secondaryButton: {+ children: 'Cancel',+ },+ })+ } else {+ onAppearanceChange({ shuffleQuestions: checked })+ }+ }}+ checked={survey.appearance?.shuffleQuestions}+ />+ <LemonDivider className="my-0" />+ <LemonCheckbox+ disabledReason={disabledReason}+ label="Allow going back to previous questions"+ onChange={(checked) =>+ onAppearanceChange({+ allowGoBack: checked,+ backButtonText: checked ? survey.appearance?.backButtonText : undefined,+ })+ }+ checked={survey.appearance?.allowGoBack}+ />+ {survey.appearance?.allowGoBack && (+ <LemonField.Pure label="Back button text" className="ml-6">+ <div className="flex max-w-xs flex-col gap-1">+ <LemonInput+ size="small"+ placeholder="Back"+ value={survey.appearance?.backButtonText ?? ''}+ onChange={(backButtonText) => onAppearanceChange({ backButtonText })}+ className="ignore-error-border"+ disabledReason={disabledReason}+ />+ {translatedLanguages.map((language) => (+ <LemonInput+ key={language}+ size="small"+ prefix={<span className="text-xs font-medium uppercase text-muted">{language}</span>}+ placeholder={survey.appearance?.backButtonText || 'Back'}+ value={translations[language]?.backButtonText ?? ''}+ onChange={(value) => setBackButtonTranslation(language, value)}+ className="ignore-error-border"+ disabledReason={disabledReason}+ />+ ))}+ </div>+ </LemonField.Pure>+ )}+ </div>+ )+}diff --git a/frontend/src/scenes/surveys/survey-appearance/SurveyCustomization.tsx b/frontend/src/scenes/surveys/survey-appearance/SurveyCustomization.tsxindex e3a51ab75c70..c0e10daca78b 100644--- a/frontend/src/scenes/surveys/survey-appearance/SurveyCustomization.tsx+++ b/frontend/src/scenes/surveys/survey-appearance/SurveyCustomization.tsx@@ -1,7 +1,7 @@import { useValues } from 'kea'import type { ReactNode } from 'react'-import { LemonCheckbox, LemonDialog, LemonDivider, LemonInput } from '@posthog/lemon-ui'+import { LemonCheckbox, LemonDivider, LemonInput } from '@posthog/lemon-ui'import { PayGateMini } from 'lib/components/PayGateMini/PayGateMini'import { upgradeModalLogic } from 'lib/components/UpgradeModal/upgradeModalLogic'@@ -12,6 +12,7 @@ import {SurveyColorsAppearance,SurveyContainerAppearance,} from 'scenes/surveys/survey-appearance/SurveyAppearanceSections'+import { SurveyBehaviorOptions } from 'scenes/surveys/survey-appearance/SurveyBehaviorOptions'import { CustomizationProps } from 'scenes/surveys/survey-appearance/types'import { SurveyThemeSelector } from 'scenes/surveys/wizard/SurveyThemeSelector'@@ -48,6 +49,7 @@ export function Customization({deleteBranchingLogic,validationErrors,disabledReason,+ onTranslationsChange,}: CustomizationProps): JSX.Element {const { surveysStylingAvailable } = useValues(surveysLogic)const { guardAvailableFeature } = useValues(upgradeModalLogic)@@ -126,40 +128,13 @@ export function Customization({disabledReason={disabledReason}/><LemonDivider className="my-0" />- <LemonCheckbox+ <SurveyBehaviorOptions+ survey={survey}+ onAppearanceChange={onAppearanceChange}disabledReason={disabledReason}- label="Shuffle questions"- onChange={(checked) => {- if (checked && hasBranchingLogic) {- onAppearanceChange({ shuffleQuestions: false })-- LemonDialog.open({- title: 'Your survey has active branching logic',- description: (- <p className="py-2">- Enabling this option will remove your branching logic. Are you sure you want- to continue?- </p>- ),- primaryButton: {- children: 'Continue',- status: 'danger',- onClick: () => {- if (deleteBranchingLogic) {- deleteBranchingLogic()- }- onAppearanceChange({ shuffleQuestions: true })- },- },- secondaryButton: {- children: 'Cancel',- },- })- } else {- onAppearanceChange({ shuffleQuestions: checked })- }- }}- checked={survey.appearance?.shuffleQuestions}+ hasBranchingLogic={hasBranchingLogic}+ deleteBranchingLogic={deleteBranchingLogic}+ onTranslationsChange={onTranslationsChange}/></div>{survey.type !== SurveyType.ExternalSurvey && (diff --git a/frontend/src/scenes/surveys/survey-appearance/types.ts b/frontend/src/scenes/surveys/survey-appearance/types.tsindex 8a617ee8a730..66ee2d237957 100644--- a/frontend/src/scenes/surveys/survey-appearance/types.ts+++ b/frontend/src/scenes/surveys/survey-appearance/types.ts@@ -19,4 +19,6 @@ export interface CommonProps {export interface CustomizationProps extends CommonProps {hasBranchingLogic: booleandeleteBranchingLogic?: () => void+ /** When provided (i.e. inside the survey editor), enables inline per-language back button labels. */+ onTranslationsChange?: (translations: NonNullable<Survey['translations']>) => void}diff --git a/frontend/src/scenes/surveys/surveyActivityDescriber.tsx b/frontend/src/scenes/surveys/surveyActivityDescriber.tsxindex f7a4814a5037..f46552397287 100644--- a/frontend/src/scenes/surveys/surveyActivityDescriber.tsx+++ b/frontend/src/scenes/surveys/surveyActivityDescriber.tsx@@ -187,6 +187,8 @@ const surveyActionsMapping: Record<tabPosition: 'survey button position',shuffleQuestions: 'question shuffling',surveyPopupDelaySeconds: 'survey popup delay',+ allowGoBack: 'back button',+ backButtonText: 'back button text',widgetType: 'widget type',widgetSelector: 'widget selector',widgetLabel: 'widget label',diff --git a/frontend/src/scenes/surveys/surveyTranslationUtils.test.ts b/frontend/src/scenes/surveys/surveyTranslationUtils.test.tsindex 3360deee7fec..5f51cfa0f0f3 100644--- a/frontend/src/scenes/surveys/surveyTranslationUtils.test.ts+++ b/frontend/src/scenes/surveys/surveyTranslationUtils.test.ts@@ -94,6 +94,28 @@ describe('getSurveyWithTranslatedContent', () => {expect(survey.questions[0].question).toBe('How was onboarding?')})+ it('applies submit and back button label translations to the appearance', () => {+ const survey = createSurvey()+ survey.appearance = {+ ...survey.appearance,+ submitButtonText: 'Submit',+ allowGoBack: true,+ backButtonText: 'Back',+ }+ survey.translations = {+ fr: {+ ...survey.translations?.fr,+ submitButtonText: 'Envoyer',+ backButtonText: 'Retour',+ },+ }++ const translatedSurvey = getSurveyWithTranslatedContent(survey, 'fr')++ expect(translatedSurvey.appearance?.submitButtonText).toBe('Envoyer')+ expect(translatedSurvey.appearance?.backButtonText).toBe('Retour')+ })+it('returns the original survey when the language has no root translation', () => {const survey = createSurvey()diff --git a/frontend/src/scenes/surveys/surveyTranslationUtils.ts b/frontend/src/scenes/surveys/surveyTranslationUtils.tsindex c83fde9e2ee6..c424dcfc045f 100644--- a/frontend/src/scenes/surveys/surveyTranslationUtils.ts+++ b/frontend/src/scenes/surveys/surveyTranslationUtils.ts@@ -22,6 +22,12 @@ export function getSurveyWithTranslatedContent<TSurvey extends Survey | NewSurveif (translation.thankYouMessageCloseButtonText) {appearanceUpdates.thankYouMessageCloseButtonText = translation.thankYouMessageCloseButtonText}+ if (translation.submitButtonText) {+ appearanceUpdates.submitButtonText = translation.submitButtonText+ }+ if (translation.backButtonText) {+ appearanceUpdates.backButtonText = translation.backButtonText+ }return {...survey,diff --git a/frontend/src/scenes/surveys/wizard/steps/AppearanceStep.tsx b/frontend/src/scenes/surveys/wizard/steps/AppearanceStep.tsxindex a106402dcf1b..56d759ab1169 100644--- a/frontend/src/scenes/surveys/wizard/steps/AppearanceStep.tsx+++ b/frontend/src/scenes/surveys/wizard/steps/AppearanceStep.tsx@@ -27,6 +27,7 @@ import {defaultSurveyAppearance,getMatchingSurveyThemeId,} from '../../constants'+import { SurveyBehaviorOptions } from '../../survey-appearance/SurveyBehaviorOptions'import { SurveyAppearancePreview } from '../../SurveyAppearancePreview'import { surveyLogic } from '../../surveyLogic'import { surveysLogic } from '../../surveysLogic'@@ -35,8 +36,8 @@ import { SurveyThemeSelector } from '../SurveyThemeSelector'import { WizardSection } from '../WizardLayout'export function AppearanceStep(): JSX.Element {- const { survey } = useValues(surveyLogic)- const { setSurveyValue } = useActions(surveyLogic)+ const { survey, hasBranchingLogic } = useValues(surveyLogic)+ const { setSurveyValue, deleteBranchingLogic } = useActions(surveyLogic)const { surveysStylingAvailable } = useValues(surveysLogic)const { guardAvailableFeature } = useValues(upgradeModalLogic)const { isDarkModeOn } = useValues(themeLogic)@@ -171,6 +172,17 @@ export function AppearanceStep(): JSX.Element {}}/>+ {/* Question behavior */}+ <WizardSection title="Behavior" titleClassName="text-sm font-medium">+ <SurveyBehaviorOptions+ survey={survey}+ onAppearanceChange={onAppearanceChange}+ hasBranchingLogic={hasBranchingLogic}+ deleteBranchingLogic={deleteBranchingLogic}+ onTranslationsChange={(translations) => setSurveyValue('translations', translations)}+ />+ </WizardSection>+{/* Advanced options */}<LemonCollapsepanels={[diff --git a/frontend/src/scenes/surveys/wizard/steps/TranslationsSection.tsx b/frontend/src/scenes/surveys/wizard/steps/TranslationsSection.tsxindex 2398cfd86eb7..d66dce0bd4b7 100644--- a/frontend/src/scenes/surveys/wizard/steps/TranslationsSection.tsx+++ b/frontend/src/scenes/surveys/wizard/steps/TranslationsSection.tsx@@ -1,23 +1,16 @@import { useActions, useValues } from 'kea'import { IconSparkles, IconTrash } from '@posthog/icons'-import { LemonButton, LemonDialog, LemonInput, LemonInputSelect, LemonTag, LemonTextArea } from '@posthog/lemon-ui'--import { LemonField } from 'lib/lemon-ui/LemonField'--import { SurveyQuestion } from '~/types'+import { LemonButton, LemonDialog, LemonInputSelect, LemonTag } from '@posthog/lemon-ui'import { BaseLanguagePicker } from '../../BaseLanguagePicker'-import { defaultSurveyAppearance } from '../../constants'import { COMMON_LANGUAGES, getSurveyLanguageLabel, getSurveyLanguageName } from '../../language'import { LegacyTranslationKeysPanel } from '../../LegacyTranslationKeysPanel'-import { isChoiceQuestion, isLinkQuestion, isRatingQuestion } from '../../questionTypeGuards'import { surveyLogic } from '../../surveyLogic'+import { SurveyTranslationFields } from '../../SurveyTranslationFields'import { useSurveyTranslationsForm } from '../../useSurveyTranslationsForm'import { WizardPanel, WizardSection } from '../WizardLayout'-type QuestionTranslation = NonNullable<SurveyQuestion['translations']>[string]-function getLanguageLabel(language: string): string {return (COMMON_LANGUAGES.find((commonLanguage) => commonLanguage.value === language)?.label ||@@ -25,56 +18,6 @@ function getLanguageLabel(language: string): string {)}-function GuidedTranslationInput({- label,- value,- source,- onChange,- multiline = false,- aiGenerated = false,-}: {- label: string- value: string- source?: string | null- onChange: (value: string) => void- multiline?: boolean- aiGenerated?: boolean-}): JSX.Element {- const labelWithState = aiGenerated ? (- <span className="flex items-center gap-1">- <span>{label}</span>- <LemonTag type="highlight">AI draft</LemonTag>- </span>- ) : (- label- )- const aiGeneratedClassName = aiGenerated- ? 'border border-dashed border-accent bg-accent-highlight-secondary'- : undefined-- return (- <LemonField.Pure label={labelWithState} className="gap-1">- {multiline ? (- <LemonTextArea- value={value}- onChange={onChange}- placeholder={source || undefined}- minRows={2}- className={aiGeneratedClassName}- />- ) : (- <LemonInput- value={value}- onChange={onChange}- placeholder={source || undefined}- fullWidth- className={aiGeneratedClassName}- />- )}- </LemonField.Pure>- )-}-interface TranslationsSectionProps {editingLanguage: string | nullsetEditingLanguage: (language: string | null) => void@@ -83,7 +26,7 @@ interface TranslationsSectionProps {export function TranslationsSection({ editingLanguage, setEditingLanguage }: TranslationsSectionProps): JSX.Element {const { survey, generatingTranslationDrafts, dataProcessingAccepted, aiGeneratedTranslationFields } =useValues(surveyLogic)- const { setSurveyValue, generateTranslationDrafts, clearAiGeneratedTranslationField } = useActions(surveyLogic)+ const { generateTranslationDrafts } = useActions(surveyLogic)const {baseLanguage,@@ -99,84 +42,6 @@ export function TranslationsSection({ editingLanguage, setEditingLanguage }: Traconst translations = survey.translations ?? {}const activeLanguage = editingLanguage && translations[editingLanguage] ? editingLanguage : null- const appearance = { ...defaultSurveyAppearance, ...survey.appearance }-- const updateSurveyTranslation = (updates: Partial<NonNullable<(typeof survey)['translations']>[string]>): void => {- if (!activeLanguage) {- return- }-- for (const field of Object.keys(updates)) {- clearAiGeneratedTranslationField(`translations.${activeLanguage}.${field}`)- }-- setSurveyValue('translations', {- ...translations,- [activeLanguage]: {- ...translations[activeLanguage],- ...updates,- },- })- }-- const updateQuestionTranslation = (questionIndex: number, updates: Partial<QuestionTranslation>): void => {- if (!activeLanguage) {- return- }-- for (const field of Object.keys(updates)) {- clearAiGeneratedTranslationField(`questions.${questionIndex}.translations.${activeLanguage}.${field}`)- }-- setSurveyValue(- 'questions',- survey.questions.map((question, index) => {- if (index !== questionIndex) {- return question- }-- const questionTranslations = question.translations ?? {}-- return {- ...question,- translations: {- ...questionTranslations,- [activeLanguage]: {- ...question.translations?.[activeLanguage],- ...updates,- },- },- }- })- )- }-- const updateChoiceTranslation = (questionIndex: number, choiceIndex: number, value: string): void => {- const question = survey.questions[questionIndex]- if (!activeLanguage || !isChoiceQuestion(question)) {- return- }-- const translatedChoices = [...(question.translations?.[activeLanguage]?.choices || question.choices || [])]- translatedChoices[choiceIndex] = value- clearAiGeneratedTranslationField(- `questions.${questionIndex}.translations.${activeLanguage}.choices.${choiceIndex}`- )- updateQuestionTranslation(questionIndex, { choices: translatedChoices })- }-- const isGeneratedSurveyField = (field: string): boolean =>- !!activeLanguage && aiGeneratedTranslationFields.includes(`translations.${activeLanguage}.${field}`)-- const isGeneratedQuestionField = (questionIndex: number, field: string): boolean =>- !!activeLanguage &&- aiGeneratedTranslationFields.includes(`questions.${questionIndex}.translations.${activeLanguage}.${field}`)-- const isGeneratedChoiceField = (questionIndex: number, choiceIndex: number): boolean =>- !!activeLanguage &&- aiGeneratedTranslationFields.includes(- `questions.${questionIndex}.translations.${activeLanguage}.choices.${choiceIndex}`- )const hasGeneratedFieldsForActiveLanguage =!!activeLanguage && aiGeneratedTranslationFields.some((path) => path.includes(`.${activeLanguage}.`))@@ -304,146 +169,7 @@ export function TranslationsSection({ editingLanguage, setEditingLanguage }: Tra</p>) : null}- <div className="space-y-6">- {survey.questions.map((question, questionIndex) => {- const questionTranslation = question.translations?.[activeLanguage] ?? {}- const ratingQuestion = isRatingQuestion(question) ? question : null- const linkQuestion = isLinkQuestion(question) ? question : null-- return (- <section key={questionIndex} className="space-y-3">- <h4 className="m-0 text-xs font-semibold uppercase tracking-wide text-muted">- Question {questionIndex + 1}- </h4>- <GuidedTranslationInput- label="Question"- value={questionTranslation.question || ''}- source={question.question}- aiGenerated={isGeneratedQuestionField(questionIndex, 'question')}- onChange={(questionText) =>- updateQuestionTranslation(questionIndex, { question: questionText })- }- />- {question.description ? (- <GuidedTranslationInput- label="Description"- value={questionTranslation.description || ''}- source={question.description}- aiGenerated={isGeneratedQuestionField(questionIndex, 'description')}- onChange={(description) =>- updateQuestionTranslation(questionIndex, { description })- }- multiline- />- ) : null}- {question.buttonText ? (- <GuidedTranslationInput- label="Button text"- value={questionTranslation.buttonText || ''}- source={question.buttonText}- aiGenerated={isGeneratedQuestionField(questionIndex, 'buttonText')}- onChange={(buttonText) =>- updateQuestionTranslation(questionIndex, { buttonText })- }- />- ) : null}- {ratingQuestion ? (- <div className="grid gap-3 sm:grid-cols-2">- <GuidedTranslationInput- label="Lower label"- value={questionTranslation.lowerBoundLabel || ''}- source={ratingQuestion.lowerBoundLabel}- aiGenerated={isGeneratedQuestionField(- questionIndex,- 'lowerBoundLabel'- )}- onChange={(lowerBoundLabel) =>- updateQuestionTranslation(questionIndex, { lowerBoundLabel })- }- />- <GuidedTranslationInput- label="Upper label"- value={questionTranslation.upperBoundLabel || ''}- source={ratingQuestion.upperBoundLabel}- aiGenerated={isGeneratedQuestionField(- questionIndex,- 'upperBoundLabel'- )}- onChange={(upperBoundLabel) =>- updateQuestionTranslation(questionIndex, { upperBoundLabel })- }- />- </div>- ) : null}- {isChoiceQuestion(question) ? (- <div className="grid gap-2 sm:grid-cols-2">- {question.choices.map((choice, choiceIndex) => (- <GuidedTranslationInput- key={choiceIndex}- label={`Choice ${choiceIndex + 1}`}- value={questionTranslation.choices?.[choiceIndex] || ''}- source={choice}- aiGenerated={isGeneratedChoiceField(questionIndex, choiceIndex)}- onChange={(value) =>- updateChoiceTranslation(questionIndex, choiceIndex, value)- }- />- ))}- </div>- ) : null}- {linkQuestion ? (- <GuidedTranslationInput- label="Link URL"- value={questionTranslation.link || ''}- source={linkQuestion.link}- aiGenerated={isGeneratedQuestionField(questionIndex, 'link')}- onChange={(link) => updateQuestionTranslation(questionIndex, { link })}- />- ) : null}- </section>- )- })}-- {appearance.displayThankYouMessage ? (- <section className="space-y-3">- <h4 className="m-0 text-xs font-semibold uppercase tracking-wide text-muted">- Confirmation screen- </h4>- <GuidedTranslationInput- label="Header"- value={translations[activeLanguage]?.thankYouMessageHeader || ''}- source={appearance.thankYouMessageHeader}- aiGenerated={isGeneratedSurveyField('thankYouMessageHeader')}- onChange={(thankYouMessageHeader) =>- updateSurveyTranslation({ thankYouMessageHeader })- }- />- {appearance.thankYouMessageDescription ? (- <GuidedTranslationInput- label="Description"- value={translations[activeLanguage]?.thankYouMessageDescription || ''}- source={appearance.thankYouMessageDescription}- aiGenerated={isGeneratedSurveyField('thankYouMessageDescription')}- onChange={(thankYouMessageDescription) =>- updateSurveyTranslation({ thankYouMessageDescription })- }- multiline- />- ) : null}- {appearance.thankYouMessageCloseButtonText ? (- <GuidedTranslationInput- label="Close button"- value={translations[activeLanguage]?.thankYouMessageCloseButtonText || ''}- source={appearance.thankYouMessageCloseButtonText}- aiGenerated={isGeneratedSurveyField('thankYouMessageCloseButtonText')}- onChange={(thankYouMessageCloseButtonText) =>- updateSurveyTranslation({ thankYouMessageCloseButtonText })- }- />- ) : null}- </section>- ) : null}- </div>+ <SurveyTranslationFields activeLanguage={activeLanguage} /></div>) : null}</WizardPanel>diff --git a/frontend/src/types.ts b/frontend/src/types.tsindex eba5b37e30b1..83f84ce44dab 100644--- a/frontend/src/types.ts+++ b/frontend/src/types.ts@@ -3903,6 +3903,8 @@ export interface Survey extends WithAccessControl {thankYouMessageHeader?: stringthankYouMessageDescription?: stringthankYouMessageCloseButtonText?: string+ submitButtonText?: string+ backButtonText?: string}> | null}@@ -3978,6 +3980,8 @@ export interface SurveyAppearance {zIndex?: stringshuffleQuestions?: booleansurveyPopupDelaySeconds?: number+ allowGoBack?: boolean+ backButtonText?: string// widget onlywidgetType?: SurveyWidgetTypewidgetSelector?: stringdiff --git a/posthog/schema.py b/posthog/schema.pyindex faeee73d091b..d6b36a3be399 100644--- a/posthog/schema.py+++ b/posthog/schema.py@@ -6752,6 +6752,8 @@ class SurveyAppearanceSchema(BaseModel):model_config = ConfigDict(extra="forbid",)+ allowGoBack: bool | None = None+ backButtonText: str | None = NonebackgroundColor: str | None = NoneborderColor: str | None = NonebuttonColor: str | None = Nonediff --git a/products/surveys/backend/api/survey.py b/products/surveys/backend/api/survey.pyindex 542944218465..4159502b121c 100644--- a/products/surveys/backend/api/survey.py+++ b/products/surveys/backend/api/survey.py@@ -536,6 +536,14 @@ class SurveyAppearanceSchemaSerializer(serializers.Serializer):placeholder = serializers.CharField(required=False)shuffleQuestions = serializers.BooleanField(required=False)surveyPopupDelaySeconds = serializers.IntegerField(required=False)+ allowGoBack = serializers.BooleanField(+ required=False,+ help_text="Whether to show a 'Back' button on web surveys after the first question, letting respondents return to a previously visited question. Defaults to false.",+ )+ backButtonText = serializers.CharField(+ required=False,+ help_text="Optional override for the back button label. Defaults to 'Back'.",+ )widgetType = serializers.ChoiceField(choices=["button", "tab", "selector"], required=False)widgetSelector = serializers.CharField(required=False)widgetLabel = serializers.CharField(required=False)diff --git a/products/surveys/backend/test_translation.py b/products/surveys/backend/test_translation.pyindex 22ad2ae5c083..09667f7d7dea 100644--- a/products/surveys/backend/test_translation.py+++ b/products/surveys/backend/test_translation.py@@ -78,6 +78,42 @@ def test_generate_survey_translation_preserves_manual_translations(mock_generateassert mock_generate_structured_output.call_args.kwargs["posthog_properties"]["ai_feature"] == "survey_translation"+@patch("products.surveys.backend.translation.generate_structured_output")+def test_generate_survey_translation_includes_submit_and_back_button_labels(+ mock_generate_structured_output: Mock,+) -> None:+ mock_generate_structured_output.return_value = (+ SurveyTranslationResponse.model_validate(+ {+ "root": {+ "submitButtonText": "Enviar",+ "backButtonText": "Atras",+ },+ "questions": [],+ }+ ),+ "trace-buttons",+ )+ survey = {+ "name": "Customer feedback",+ "type": "popover",+ "appearance": {"submitButtonText": "Submit", "allowGoBack": True, "backButtonText": "Back"},+ "translations": {},+ "questions": [],+ }++ translations, _questions, generated_paths, _trace_id = generate_survey_translation(+ survey=survey,+ target_language="es",+ source_language="en",+ team_id=1,+ )++ assert translations == {"es": {"submitButtonText": "Enviar", "backButtonText": "Atras"}}+ assert "translations.es.submitButtonText" in generated_paths+ assert "translations.es.backButtonText" in generated_paths++@patch("products.surveys.backend.translation.generate_structured_output")def test_generate_survey_translation_preserves_manual_choice_translations_after_choice_count_change(mock_generate_structured_output: Mock,diff --git a/products/surveys/backend/translation.py b/products/surveys/backend/translation.pyindex 7142f72085a8..6f9cabafcdac 100644--- a/products/surveys/backend/translation.py+++ b/products/surveys/backend/translation.py@@ -15,6 +15,8 @@ class SurveyRootTranslation(BaseModel):thankYouMessageHeader: str | None = NonethankYouMessageDescription: str | None = NonethankYouMessageCloseButtonText: str | None = None+ submitButtonText: str | None = None+ backButtonText: str | None = Noneclass SurveyQuestionTranslation(BaseModel):@@ -57,6 +59,8 @@ def _root_source(survey: dict[str, Any]) -> dict[str, Any]:"thankYouMessageHeader": appearance.get("thankYouMessageHeader"),"thankYouMessageDescription": appearance.get("thankYouMessageDescription"),"thankYouMessageCloseButtonText": appearance.get("thankYouMessageCloseButtonText"),+ "submitButtonText": appearance.get("submitButtonText"),+ "backButtonText": appearance.get("backButtonText"),"translations": survey.get("translations") or {},}diff --git a/products/surveys/frontend/generated/api.schemas.ts b/products/surveys/frontend/generated/api.schemas.tsindex d5ee6ac4637e..8db0bb59e7ba 100644--- a/products/surveys/frontend/generated/api.schemas.ts+++ b/products/surveys/frontend/generated/api.schemas.ts@@ -1200,6 +1200,10 @@ export interface SurveyAppearanceSchemaApi {placeholder?: stringshuffleQuestions?: booleansurveyPopupDelaySeconds?: number+ /** Whether to show a 'Back' button on web surveys after the first question, letting respondents return to a previously visited question. Defaults to false. */+ allowGoBack?: boolean+ /** Optional override for the back button label. Defaults to 'Back'. */+ backButtonText?: stringwidgetType?: WidgetTypeEnumApiwidgetSelector?: stringwidgetLabel?: stringdiff --git a/products/surveys/frontend/generated/api.zod.ts b/products/surveys/frontend/generated/api.zod.tsindex face42c7ced9..3c8c31d441fd 100644--- a/products/surveys/frontend/generated/api.zod.ts+++ b/products/surveys/frontend/generated/api.zod.ts@@ -706,6 +706,16 @@ export const SurveysCreateBody = /* @__PURE__ */ zod.object({placeholder: zod.string().optional(),shuffleQuestions: zod.boolean().optional(),surveyPopupDelaySeconds: zod.number().optional(),+ allowGoBack: zod+ .boolean()+ .optional()+ .describe(+ "Whether to show a 'Back' button on web surveys after the first question, letting respondents return to a previously visited question. Defaults to false."+ ),+ backButtonText: zod+ .string()+ .optional()+ .describe("Optional override for the back button label. Defaults to 'Back'."),widgetType: zod.enum(['button', 'tab', 'selector']).optional()@@ -1596,6 +1606,16 @@ export const SurveysPartialUpdateBody = /* @__PURE__ */ zod.object({placeholder: zod.string().optional(),shuffleQuestions: zod.boolean().optional(),surveyPopupDelaySeconds: zod.number().optional(),+ allowGoBack: zod+ .boolean()+ .optional()+ .describe(+ "Whether to show a 'Back' button on web surveys after the first question, letting respondents return to a previously visited question. Defaults to false."+ ),+ backButtonText: zod+ .string()+ .optional()+ .describe("Optional override for the back button label. Defaults to 'Back'."),widgetType: zod.enum(['button', 'tab', 'selector']).optional()diff --git a/services/mcp/src/api/generated.ts b/services/mcp/src/api/generated.tsindex 57989918e85d..385b32c909bd 100644--- a/services/mcp/src/api/generated.ts+++ b/services/mcp/src/api/generated.ts@@ -34126,6 +34126,10 @@ export namespace Schemas {placeholder?: string;shuffleQuestions?: boolean;surveyPopupDelaySeconds?: number;+ /** Whether to show a 'Back' button on web surveys after the first question, letting respondents return to a previously visited question. Defaults to false. */+ allowGoBack?: boolean;+ /** Optional override for the back button label. Defaults to 'Back'. */+ backButtonText?: string;widgetType?: WidgetTypeEnum;widgetSelector?: string;widgetLabel?: string;diff --git a/services/mcp/src/generated/surveys/api.ts b/services/mcp/src/generated/surveys/api.tsindex c08152dabed6..6186645c9370 100644--- a/services/mcp/src/generated/surveys/api.ts+++ b/services/mcp/src/generated/surveys/api.ts@@ -725,6 +725,16 @@ export const SurveysCreateBody = /* @__PURE__ */ zod.object({placeholder: zod.string().optional(),shuffleQuestions: zod.boolean().optional(),surveyPopupDelaySeconds: zod.number().optional(),+ allowGoBack: zod+ .boolean()+ .optional()+ .describe(+ "Whether to show a 'Back' button on web surveys after the first question, letting respondents return to a previously visited question. Defaults to false."+ ),+ backButtonText: zod+ .string()+ .optional()+ .describe("Optional override for the back button label. Defaults to 'Back'."),widgetType: zod.enum(['button', 'tab', 'selector']).optional()@@ -1522,6 +1532,16 @@ export const SurveysPartialUpdateBody = /* @__PURE__ */ zod.object({placeholder: zod.string().optional(),shuffleQuestions: zod.boolean().optional(),surveyPopupDelaySeconds: zod.number().optional(),+ allowGoBack: zod+ .boolean()+ .optional()+ .describe(+ "Whether to show a 'Back' button on web surveys after the first question, letting respondents return to a previously visited question. Defaults to false."+ ),+ backButtonText: zod+ .string()+ .optional()+ .describe("Optional override for the back button label. Defaults to 'Back'."),widgetType: zod.enum(['button', 'tab', 'selector']).optional()diff --git a/services/mcp/tests/unit/__snapshots__/tool-schemas/survey-create.json b/services/mcp/tests/unit/__snapshots__/tool-schemas/survey-create.jsonindex 055a7448e5c6..84673681d98d 100644--- a/services/mcp/tests/unit/__snapshots__/tool-schemas/survey-create.json+++ b/services/mcp/tests/unit/__snapshots__/tool-schemas/survey-create.json@@ -5,9 +5,17 @@"anyOf": [{"properties": {+ "allowGoBack": {+ "description": "Whether to show a 'Back' button on web surveys after the first question, letting respondents return to a previously visited question. Defaults to false.",+ "type": "boolean"+ },"autoDisappear": {"type": "boolean"},+ "backButtonText": {+ "description": "Optional override for the back button label. Defaults to 'Back'.",+ "type": "string"+ },"backgroundColor": {"type": "string"},diff --git a/services/mcp/tests/unit/__snapshots__/tool-schemas/survey-update.json b/services/mcp/tests/unit/__snapshots__/tool-schemas/survey-update.jsonindex 7766aea33fef..8dea1fa8ec0e 100644--- a/services/mcp/tests/unit/__snapshots__/tool-schemas/survey-update.json+++ b/services/mcp/tests/unit/__snapshots__/tool-schemas/survey-update.json@@ -5,9 +5,17 @@"anyOf": [{"properties": {+ "allowGoBack": {+ "description": "Whether to show a 'Back' button on web surveys after the first question, letting respondents return to a previously visited question. Defaults to false.",+ "type": "boolean"+ },"autoDisappear": {"type": "boolean"},+ "backButtonText": {+ "description": "Optional override for the back button label. Defaults to 'Back'.",+ "type": "string"+ },"backgroundColor": {"type": "string"},