: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 hosted-only templates and mode-aware filtering (#58921)
Lucas Faria07ed749967cd
diff --git a/frontend/src/scenes/surveys/constants.tsx b/frontend/src/scenes/surveys/constants.tsxindex 24f239ea80cc..7af2287e9c76 100644--- a/frontend/src/scenes/surveys/constants.tsx+++ b/frontend/src/scenes/surveys/constants.tsx@@ -253,8 +253,12 @@ export enum SurveyTemplateType {OnboardingFeedback = 'Onboarding feedback',BetaFeedback = 'Beta feedback',Announcement = 'Announcement',+ UserResearchIntake = 'User research intake',+ ProductResearch = 'Product research',}+export type SurveyTemplateMode = 'in_app' | 'hosted'+export interface QuickSurveyFromTemplate {context: QuickSurveyContextmodalTitle?: string@@ -268,6 +272,8 @@ export type SurveyTemplate = Partial<Survey> & {badge?: stringfeatured?: booleanquickSurvey?: QuickSurveyFromTemplate+ // Which template modes this template should appear in. Omitted = available in all modes.+ modes?: SurveyTemplateMode[]}export const defaultSurveyTemplates: SurveyTemplate[] = [@@ -310,6 +316,7 @@ export const defaultSurveyTemplates: SurveyTemplate[] = [category: 'Business',badge: 'New!',featured: true,+ modes: ['in_app'],quickSurvey: {context: { type: QuickSurveyType.ANNOUNCEMENT },modalTitle: 'New announcement',@@ -511,6 +518,7 @@ export const defaultSurveyTemplates: SurveyTemplate[] = [description: 'Get user context when errors occur to debug faster.',tagType: 'default',category: 'General',+ modes: ['in_app'],appearance: {...defaultSurveyAppearance,surveyPopupDelaySeconds: 2,@@ -576,6 +584,7 @@ export const defaultSurveyTemplates: SurveyTemplate[] = [description: "Capture first impressions while they're fresh.",tagType: 'primary',category: 'Product',+ modes: ['in_app'],appearance: defaultSurveyAppearance,},{@@ -617,6 +626,103 @@ export const defaultSurveyTemplates: SurveyTemplate[] = [category: 'Product',appearance: defaultSurveyAppearance,},+ {+ type: SurveyType.ExternalSurvey,+ templateType: SurveyTemplateType.UserResearchIntake,+ questions: [+ {+ type: SurveyQuestionType.SingleChoice,+ question: 'Would you be open to a 30-minute conversation with our team?',+ description: 'We are exploring how customers use our product and would love to hear from you.',+ descriptionContentType: 'text' as SurveyQuestionDescriptionContentType,+ choices: ['Yes, I am interested', 'Maybe later', 'No thanks'],+ skipSubmitButton: true,+ },+ {+ type: SurveyQuestionType.Open,+ question: 'What is the best email to reach you at?',+ description: 'We will send a calendar invite within one business day.',+ descriptionContentType: 'text' as SurveyQuestionDescriptionContentType,+ buttonText: 'Submit',+ },+ {+ type: SurveyQuestionType.Open,+ question: 'Anything specific you would like to talk about?',+ description: 'Optional. Helps us prepare for the call.',+ descriptionContentType: 'text' as SurveyQuestionDescriptionContentType,+ optional: true,+ buttonText: 'Send',+ },+ ],+ appearance: {+ ...defaultSurveyAppearance,+ displayThankYouMessage: true,+ thankYouMessageHeader: 'Thanks — we will be in touch shortly!',+ },+ description: 'Recruit research participants via a shareable link.',+ tagType: 'completion',+ category: 'Business',+ modes: ['hosted'],+ },+ {+ type: SurveyType.ExternalSurvey,+ templateType: SurveyTemplateType.ProductResearch,+ questions: [+ {+ type: SurveyQuestionType.SingleChoice,+ question: 'How would you describe your role?',+ choices: ['Founder / leadership', 'Product manager', 'Engineer', 'Designer', 'Marketing', 'Other'],+ hasOpenChoice: true,+ skipSubmitButton: true,+ },+ {+ type: SurveyQuestionType.SingleChoice,+ question: 'How often do you use the product?',+ choices: ['Daily', 'A few times a week', 'A few times a month', 'Rarely', 'Never'],+ skipSubmitButton: true,+ },+ {+ type: SurveyQuestionType.Rating,+ question: 'How likely are you to recommend us to a colleague?',+ description: '',+ descriptionContentType: 'text' as SurveyQuestionDescriptionContentType,+ display: 'number',+ scale: SURVEY_RATING_SCALE.NPS_10_POINT,+ lowerBoundLabel: 'Not at all likely',+ upperBoundLabel: 'Extremely likely',+ isNpsQuestion: true,+ skipSubmitButton: true,+ },+ {+ type: SurveyQuestionType.Open,+ question: 'What is the single biggest benefit you get from our product?',+ description: '',+ descriptionContentType: 'text' as SurveyQuestionDescriptionContentType,+ },+ {+ type: SurveyQuestionType.Open,+ question: 'What would you like us to improve next?',+ description: '',+ descriptionContentType: 'text' as SurveyQuestionDescriptionContentType,+ },+ {+ type: SurveyQuestionType.Open,+ question: 'What would you use instead if our product did not exist?',+ description: '',+ descriptionContentType: 'text' as SurveyQuestionDescriptionContentType,+ optional: true,+ },+ ],+ appearance: {+ ...defaultSurveyAppearance,+ displayThankYouMessage: true,+ thankYouMessageHeader: 'Thanks for sharing your perspective!',+ },+ description: 'Go deep on segmentation, satisfaction, and roadmap signal.',+ tagType: 'primary',+ category: 'Product',+ modes: ['hosted'],+ },]export const WEB_SAFE_FONTS = [diff --git a/frontend/src/scenes/surveys/wizard/steps/TemplateStep.tsx b/frontend/src/scenes/surveys/wizard/steps/TemplateStep.tsxindex d9bb7a866ad5..c2bbcf5fcc43 100644--- a/frontend/src/scenes/surveys/wizard/steps/TemplateStep.tsx+++ b/frontend/src/scenes/surveys/wizard/steps/TemplateStep.tsx@@ -11,7 +11,9 @@ import {IconGraph,IconHandwave,IconMegaphone,+ IconNotebook,IconPeople,+ IconPhone,IconPulse,IconSparkles,IconTarget,@@ -26,9 +28,9 @@ import { featureFlagLogic } from 'lib/logic/featureFlagLogic'import { eventUsageLogic } from 'lib/utils/eventUsageLogic'import { useMaxTool } from 'scenes/max/useMaxTool'-import { SURVEY_CREATED_SOURCE, SurveyTemplate, SurveyTemplateType } from '../../constants'+import { SURVEY_CREATED_SOURCE, SurveyTemplate, SurveyTemplateMode, SurveyTemplateType } from '../../constants'import { surveysLogic } from '../../surveysLogic'-import { SurveyTemplateMode, surveyWizardLogic } from '../surveyWizardLogic'+import { surveyWizardLogic } from '../surveyWizardLogic'const TEMPLATE_ICONS: Partial<Record<SurveyTemplateType, React.ComponentType<{ className?: string }>>> = {[SurveyTemplateType.NPS]: IconGraph,@@ -44,6 +46,8 @@ const TEMPLATE_ICONS: Partial<Record<SurveyTemplateType, React.ComponentType<{ c[SurveyTemplateType.OnboardingFeedback]: IconHandwave,[SurveyTemplateType.BetaFeedback]: IconFlask,[SurveyTemplateType.Announcement]: IconMegaphone,+ [SurveyTemplateType.UserResearchIntake]: IconPhone,+ [SurveyTemplateType.ProductResearch]: IconNotebook,}interface TemplateCardProps {diff --git a/frontend/src/scenes/surveys/wizard/surveyWizardLogic.test.ts b/frontend/src/scenes/surveys/wizard/surveyWizardLogic.test.tsindex 3c4c318722b1..e926a22e8c0b 100644--- a/frontend/src/scenes/surveys/wizard/surveyWizardLogic.test.ts+++ b/frontend/src/scenes/surveys/wizard/surveyWizardLogic.test.ts@@ -362,5 +362,45 @@ describe('surveyWizardLogic', () => {}),})})++ it.each([+ {+ mode: 'in_app' as const,+ expectedCore: [+ SurveyTemplateType.NPS,+ SurveyTemplateType.CSAT,+ SurveyTemplateType.PMF,+ SurveyTemplateType.OpenFeedback,+ ],+ otherContains: [SurveyTemplateType.Announcement, SurveyTemplateType.ErrorTracking],+ otherExcludes: [SurveyTemplateType.UserResearchIntake, SurveyTemplateType.ProductResearch],+ },+ {+ mode: 'hosted' as const,+ expectedCore: [+ SurveyTemplateType.UserResearchIntake,+ SurveyTemplateType.ProductResearch,+ SurveyTemplateType.NPS,+ SurveyTemplateType.CCR,+ ],+ otherContains: [SurveyTemplateType.FeatureRequest],+ otherExcludes: [+ SurveyTemplateType.Announcement,+ SurveyTemplateType.ErrorTracking,+ SurveyTemplateType.OnboardingFeedback,+ ],+ },+ ])('exposes mode-specific templates for $mode mode', ({ mode, expectedCore, otherContains, otherExcludes }) => {+ const logic = surveyWizardLogic({ id: 'new' })+ logic.mount()+ logic.actions.setTemplateMode(mode)++ const coreTypes = logic.values.coreTemplates.map((t) => t.templateType)+ expect(coreTypes).toEqual(expectedCore)++ const otherTypes = logic.values.otherTemplates.map((t) => t.templateType)+ otherContains.forEach((type) => expect(otherTypes).toContain(type))+ otherExcludes.forEach((type) => expect(otherTypes).not.toContain(type))+ })})})diff --git a/frontend/src/scenes/surveys/wizard/surveyWizardLogic.ts b/frontend/src/scenes/surveys/wizard/surveyWizardLogic.tsindex 99ba65e8bef3..9ad5d9cbe654 100644--- a/frontend/src/scenes/surveys/wizard/surveyWizardLogic.ts+++ b/frontend/src/scenes/surveys/wizard/surveyWizardLogic.ts@@ -16,6 +16,8 @@ import { Breadcrumb, LinkSurveyQuestion, Survey, SurveyQuestionType, SurveySchedimport {SURVEY_CREATED_SOURCE,SurveyTemplate,+ SurveyTemplateMode,+ SurveyTemplateType,defaultSurveyAppearance,defaultSurveyTemplates,surveyThemes,@@ -26,18 +28,26 @@ import type { surveyWizardLogicType } from './surveyWizardLogicType'export type WizardStep = 'template' | 'questions' | 'where' | 'when' | 'appearance' | 'success'-export type SurveyTemplateMode = 'in_app' | 'hosted'+// Re-exported for convenience — the canonical definition lives in ../constants.+export type { SurveyTemplateMode } from '../constants'// Main flow steps (appearance is optional, branched from 'when')const WIZARD_STEPS: WizardStep[] = ['template', 'questions', 'where', 'when']-// Core templates to show prominently-const CORE_TEMPLATE_TYPES = [- 'Net promoter score (NPS)',- 'Customer satisfaction score (CSAT)',- 'Product-market fit (PMF)',- 'Open feedback',-]+// Core templates to show prominently, per template mode.+const CORE_TEMPLATE_TYPES: Record<SurveyTemplateMode, SurveyTemplateType[]> = {+ in_app: [SurveyTemplateType.NPS, SurveyTemplateType.CSAT, SurveyTemplateType.PMF, SurveyTemplateType.OpenFeedback],+ hosted: [+ SurveyTemplateType.UserResearchIntake,+ SurveyTemplateType.ProductResearch,+ SurveyTemplateType.NPS,+ SurveyTemplateType.CCR,+ ],+}++function templateMatchesMode(template: SurveyTemplate, mode: SurveyTemplateMode): boolean {+ return !template.modes || template.modes.includes(mode)+}export interface SurveyWizardLogicProps {id: string // 'new' for new surveys, or a UUID for editing@@ -151,15 +161,22 @@ export const surveyWizardLogic = kea<surveyWizardLogicType>([selectors({coreTemplates: [- () => [],- (): SurveyTemplate[] => {- return defaultSurveyTemplates.filter((t) => CORE_TEMPLATE_TYPES.includes(t.templateType))+ (s) => [s.templateMode],+ (mode: SurveyTemplateMode): SurveyTemplate[] => {+ const coreTypes = CORE_TEMPLATE_TYPES[mode]+ // Preserve the order declared in CORE_TEMPLATE_TYPES so featured cards stay positioned.+ return coreTypes+ .map((type) => defaultSurveyTemplates.find((t) => t.templateType === type))+ .filter((t): t is SurveyTemplate => !!t && templateMatchesMode(t, mode))},],otherTemplates: [- () => [],- (): SurveyTemplate[] => {- return defaultSurveyTemplates.filter((t) => !CORE_TEMPLATE_TYPES.includes(t.templateType))+ (s) => [s.templateMode],+ (mode: SurveyTemplateMode): SurveyTemplate[] => {+ const coreTypes = new Set<SurveyTemplateType>(CORE_TEMPLATE_TYPES[mode])+ return defaultSurveyTemplates.filter(+ (t) => !coreTypes.has(t.templateType) && templateMatchesMode(t, mode)+ )},],stepNumber: [(s) => [s.currentStep], (currentStep: WizardStep): number => WIZARD_STEPS.indexOf(currentStep)],