:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
fix(surveys): hide wizard schedule when survey repeats on every event (#68095)
Ben Lea20a07d725c9e
diff --git a/frontend/src/scenes/surveys/SurveyRepeatSchedule.tsx b/frontend/src/scenes/surveys/SurveyRepeatSchedule.tsxindex d00e2ad1ffb1..cd83c3e1293c 100644--- a/frontend/src/scenes/surveys/SurveyRepeatSchedule.tsx+++ b/frontend/src/scenes/surveys/SurveyRepeatSchedule.tsx@@ -10,6 +10,7 @@ import { LemonRadio } from 'lib/lemon-ui/LemonRadio'import { pluralize } from 'lib/utils/strings'import { LinkToSurveyFormSection } from 'scenes/surveys/components/LinkToSurveyFormSection'import { SURVEY_FORM_INPUT_IDS } from 'scenes/surveys/constants'+import { doesSurveyRepeatOnEveryEvent } from 'scenes/surveys/utils'import { Survey, SurveySchedule, SurveyType } from '~/types'@@ -199,13 +200,11 @@ function SurveyIterationOptions(): JSX.Element {export function SurveyRepeatSchedule(): JSX.Element {const { survey } = useValues(surveyLogic)- const canSurveyBeRepeated = Boolean(- survey.conditions?.events?.repeatedActivation && survey.conditions?.events?.values?.length > 0- )+ const repeatsOnEveryEvent = doesSurveyRepeatOnEveryEvent(survey)return (<div className="mt-4">- {canSurveyBeRepeated ? (+ {repeatsOnEveryEvent ? (<span className="font-medium"><h3 className="mb-0">How often should we show this survey to a person?</h3><IconInfo className="mr-0.5" /> This survey is displayed whenever the diff --git a/frontend/src/scenes/surveys/utils.test.ts b/frontend/src/scenes/surveys/utils.test.tsindex 63b8c53c15c9..42b336374294 100644--- a/frontend/src/scenes/surveys/utils.test.ts+++ b/frontend/src/scenes/surveys/utils.test.ts@@ -24,6 +24,7 @@ import {buildSurveyTimestampFilter,calculateNpsBreakdown,createAnswerFilterHogQLExpression,+ doesSurveyRepeatOnEveryEvent,getSurveyNotificationFilters,getResolvedSurveyDateRange,getSurveyAudienceSummaryValue,@@ -1444,3 +1445,23 @@ describe('splitChoicesOnPaste', () => {expect(splitChoicesOnPaste('two\nthree', ['one', 'Other'], 1, true)).toEqual(['one', 'two', 'three', 'Other'])})})++describe('doesSurveyRepeatOnEveryEvent', () => {+ it.each([+ [+ 'repeated activation with a trigger event',+ true,+ { values: [{ name: 'purchase' }], repeatedActivation: true },+ ],+ ['repeated activation without trigger events', false, { values: [], repeatedActivation: true }],+ [+ 'trigger events without repeated activation',+ false,+ { values: [{ name: 'purchase' }], repeatedActivation: false },+ ],+ ['no events object', false, null],+ ])('%s -> %s', (_name, expected, events) => {+ const survey = { conditions: events ? { events } : null } as Pick<Survey, 'conditions'>+ expect(doesSurveyRepeatOnEveryEvent(survey)).toBe(expected)+ })+})diff --git a/frontend/src/scenes/surveys/utils.ts b/frontend/src/scenes/surveys/utils.tsindex 015dddf302d9..b907e7ffb586 100644--- a/frontend/src/scenes/surveys/utils.ts+++ b/frontend/src/scenes/surveys/utils.ts@@ -536,6 +536,10 @@ export function canUseSurveyWizard(survey: Survey | NewSurvey): boolean {return true}+export function doesSurveyRepeatOnEveryEvent(survey: Pick<Survey, 'conditions'>): boolean {+ return !!(survey.conditions?.events?.repeatedActivation && (survey.conditions?.events?.values?.length ?? 0) > 0)+}+export function doesSurveyHaveDisplayConditions(survey: Survey | NewSurvey): boolean {const conditions = sanitizeSurveyDisplayConditions(survey.conditions)if (!conditions) {diff --git a/frontend/src/scenes/surveys/wizard/steps/SuccessStep.test.tsx b/frontend/src/scenes/surveys/wizard/steps/SuccessStep.test.tsxnew file mode 100644index 000000000000..33fa2b1b5895--- /dev/null+++ b/frontend/src/scenes/surveys/wizard/steps/SuccessStep.test.tsx@@ -0,0 +1,61 @@+import '@testing-library/jest-dom'++import { cleanup, render, screen } from '@testing-library/react'++import { NEW_SURVEY } from 'scenes/surveys/constants'++import { initKeaTests } from '~/test/init'+import { Survey, SurveySchedule } from '~/types'++import { SuccessStep } from './SuccessStep'++jest.mock('../../SurveyAppearancePreview', () => ({+ SurveyAppearancePreview: () => <div data-testid="survey-preview" />,+}))++const createLaunchedSurvey = (overrides: Partial<Survey>): Survey =>+ ({ ...NEW_SURVEY, id: 'test-survey', ...overrides }) as Survey++describe('SuccessStep', () => {+ beforeEach(() => {+ initKeaTests()+ })++ afterEach(() => {+ cleanup()+ })++ it('summarizes frequency as event-driven when the survey repeats on every event', () => {+ render(+ <SuccessStep+ survey={createLaunchedSurvey({+ conditions: {+ actions: null,+ events: { values: [{ name: 'payment_completed' }], repeatedActivation: true },+ },+ // Stored cadence left over from a template — must not be presented as the effective frequency+ schedule: SurveySchedule.Recurring,+ iteration_count: 10,+ iteration_frequency_days: 30,+ })}+ />+ )++ expect(screen.getByText('Every time a trigger event is captured')).toBeInTheDocument()+ expect(screen.queryByText(/Up to 10 times/)).not.toBeInTheDocument()+ })++ it('summarizes the stored cadence when the survey does not repeat on events', () => {+ render(+ <SuccessStep+ survey={createLaunchedSurvey({+ schedule: SurveySchedule.Recurring,+ iteration_count: 2,+ iteration_frequency_days: 90,+ })}+ />+ )++ expect(screen.getByText('Up to 2 times, every 90 days')).toBeInTheDocument()+ })+})diff --git a/frontend/src/scenes/surveys/wizard/steps/SuccessStep.tsx b/frontend/src/scenes/surveys/wizard/steps/SuccessStep.tsxindex f36008624855..ac6331e46b25 100644--- a/frontend/src/scenes/surveys/wizard/steps/SuccessStep.tsx+++ b/frontend/src/scenes/surveys/wizard/steps/SuccessStep.tsx@@ -3,6 +3,7 @@ import { useEffect, useState } from 'react'import { LemonButton } from '@posthog/lemon-ui'+import { doesSurveyRepeatOnEveryEvent } from 'scenes/surveys/utils'import { urls } from 'scenes/urls'import { Survey, SurveySchedule, SurveyType } from '~/types'@@ -17,6 +18,7 @@ interface SuccessStepProps {export function SuccessStep({ survey }: SuccessStepProps): JSX.Element {const isHostedSurvey = survey.type === SurveyType.ExternalSurvey+ const repeatsOnEveryEvent = doesSurveyRepeatOnEveryEvent(survey)const [countdown, setCountdown] = useState(5)useEffect(() => {@@ -88,9 +90,11 @@ export function SuccessStep({ survey }: SuccessStepProps): JSX.Element {<div className="flex justify-between"><dt className="text-secondary">Frequency</dt><dd>- {survey.schedule === SurveySchedule.Once || !survey.iteration_frequency_days- ? 'Once ever'- : `Up to ${survey.iteration_count ?? 10} times, every ${survey.iteration_frequency_days} days`}+ {repeatsOnEveryEvent+ ? 'Every time a trigger event is captured'+ : survey.schedule === SurveySchedule.Once || !survey.iteration_frequency_days+ ? 'Once ever'+ : `Up to ${survey.iteration_count ?? 10} times, every ${survey.iteration_frequency_days} days`}</dd></div>{survey.conditions?.seenSurveyWaitPeriodInDays != null && (diff --git a/frontend/src/scenes/surveys/wizard/steps/WhenStep.test.tsx b/frontend/src/scenes/surveys/wizard/steps/WhenStep.test.tsxnew file mode 100644index 000000000000..0433b09aa3c7--- /dev/null+++ b/frontend/src/scenes/surveys/wizard/steps/WhenStep.test.tsx@@ -0,0 +1,99 @@+import '@testing-library/jest-dom'++import { cleanup, render, screen } from '@testing-library/react'+import { BindLogic, Provider } from 'kea'++import { useMocks } from '~/mocks/jest'+import { initKeaTests } from '~/test/init'+import { AccessControlLevel, Survey, SurveyPosition, SurveyQuestionType, SurveySchedule, SurveyType } from '~/types'++import { surveyLogic } from '../../surveyLogic'+import { WhenStep } from './WhenStep'++jest.mock('lib/components/PropertyFilters/PropertyFilters', () => ({+ PropertyFilters: () => <div data-testid="property-filters" />,+}))++const createEventTriggeredSurvey = (repeatedActivation: boolean): Survey => ({+ id: 'test-survey',+ name: 'Test survey',+ description: '',+ type: SurveyType.Popover,+ linked_flag: null,+ linked_flag_id: null,+ targeting_flag: null,+ questions: [+ {+ type: SurveyQuestionType.Open,+ question: 'What do you think?',+ description: '',+ buttonText: 'Submit',+ },+ ],+ conditions: {+ actions: null,+ events: { values: [{ name: 'payment_completed' }], repeatedActivation },+ },+ appearance: {+ position: SurveyPosition.Right,+ },+ 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,+})++const surveyMocks = (survey: Survey): Parameters<typeof useMocks>[0] => ({+ get: {+ '/api/projects/:team/surveys/': () => [200, { count: 0, results: [], next: null, previous: null }],+ '/api/projects/:team/surveys/test-survey/': () => [200, survey],+ '/api/projects/:team/surveys/responses_count': () => [200, {}],+ },+})++describe('WhenStep', () => {+ beforeEach(() => {+ initKeaTests()+ })++ afterEach(() => {+ cleanup()+ })++ const renderWhenStep = (): void => {+ render(+ <Provider>+ <BindLogic logic={surveyLogic} props={{ id: 'test-survey' }}>+ <WhenStep />+ </BindLogic>+ </Provider>+ )+ }++ it('replaces the schedule options with an explanation when the survey shows on every event capture', async () => {+ useMocks(surveyMocks(createEventTriggeredSurvey(true)))+ renderWhenStep()++ expect(await screen.findByText(/the schedule options don't apply/)).toBeInTheDocument()+ expect(screen.queryByText('Once ever')).not.toBeInTheDocument()+ // The wait period and response limit still apply at runtime, so they stay configurable+ expect(+ screen.getByText("Don't show this survey if another one was shown to the user in the last")+ ).toBeInTheDocument()+ expect(screen.getByText('Stop after')).toBeInTheDocument()+ })++ it('keeps the schedule options for event-triggered surveys that show once per user', async () => {+ useMocks(surveyMocks(createEventTriggeredSurvey(false)))+ renderWhenStep()++ expect(await screen.findByText('payment_completed')).toBeInTheDocument()+ expect(screen.getByText('Once ever')).toBeInTheDocument()+ expect(screen.queryByText(/the schedule options don't apply/)).not.toBeInTheDocument()+ })+})diff --git a/frontend/src/scenes/surveys/wizard/steps/WhenStep.tsx b/frontend/src/scenes/surveys/wizard/steps/WhenStep.tsxindex 0a983217ef9f..e604e7a1fc40 100644--- a/frontend/src/scenes/surveys/wizard/steps/WhenStep.tsx+++ b/frontend/src/scenes/surveys/wizard/steps/WhenStep.tsx@@ -1,12 +1,13 @@import { useActions, useValues } from 'kea'-import { IconX } from '@posthog/icons'-import { LemonButton, LemonCheckbox, LemonInput, LemonSegmentedButton } from '@posthog/lemon-ui'+import { IconInfo, IconX } from '@posthog/icons'+import { LemonButton, LemonCheckbox, LemonInput, LemonSegmentedButton, LemonSnack } from '@posthog/lemon-ui'import { PropertyFilters } from 'lib/components/PropertyFilters/PropertyFilters'import { TaxonomicFilterGroupType } from 'lib/components/TaxonomicFilter/types'import { LemonRadio } from 'lib/lemon-ui/LemonRadio'import { AddEventButton } from 'scenes/surveys/AddEventButton'+import { doesSurveyRepeatOnEveryEvent } from 'scenes/surveys/utils'import {AnyPropertyFilter,@@ -49,6 +50,12 @@ export function WhenStep(): JSX.Element {// Check if events object exists (even if empty) to determine modeconst triggerMode = conditions.events !== null && conditions.events !== undefined ? 'event' : 'pageview'const repeatedActivation = conditions.events?.repeatedActivation ?? false+ // Repeated event activation makes the SDK re-show the survey on every trigger-event capture,+ // bypassing the schedule — so render the schedule as not applicable, the same treatment as+ // SurveyRepeatSchedule in the full editor (the explanation is deliberately not shared with it:+ // the contexts differ too much). The stored schedule/iteration fields are left untouched so+ // unchecking the box restores the previous cadence.+ const repeatsOnEveryEvent = doesSurveyRepeatOnEveryEvent(survey)const delaySeconds = appearance.surveyPopupDelaySeconds ?? 0const excludedObjectProperties = useExcludedObjectProperties()// Derive frequency strictly from the iteration model — the universal wait-period is a separate@@ -277,37 +284,51 @@ export function WhenStep(): JSX.Element {description="How many times the same user can see this survey, and how often."descriptionClassName="text-sm">- <LemonSegmentedButton- value={frequency}- onChange={setFrequency}- options={FREQUENCY_OPTIONS.map((opt) => ({- ...opt,- tooltip:- opt.value === recommendedFrequency.value ? `Recommended for this survey type` : undefined,- }))}- fullWidth- />+ {repeatsOnEveryEvent ? (+ <div className="text-sm" data-attr="survey-schedule-repeats-on-event-note">+ <IconInfo className="mr-0.5" />+ This survey is displayed whenever the{' '}+ <LemonSnack>{triggerEvents.map((event) => event.name).join(', ')}</LemonSnack>{' '}+ {triggerEvents.length === 1 ? 'event is' : 'events are'} captured, so the schedule options don't+ apply. To set a schedule instead, uncheck 'Show every time the event is captured' above.+ </div>+ ) : (+ <>+ <LemonSegmentedButton+ value={frequency}+ onChange={setFrequency}+ options={FREQUENCY_OPTIONS.map((opt) => ({+ ...opt,+ tooltip:+ opt.value === recommendedFrequency.value+ ? `Recommended for this survey type`+ : undefined,+ }))}+ fullWidth+ />- {recommendedFrequency.value === frequency && (- <p className="text-sm text-success mt-2 mb-0">{recommendedFrequency.reason}</p>- )}+ {recommendedFrequency.value === frequency && (+ <p className="text-sm text-success mt-2 mb-0">{recommendedFrequency.reason}</p>+ )}- {frequency !== 'once' && (- <div className="flex flex-wrap items-center gap-2 text-sm mt-5">- <span>Show up to</span>- <LemonInput- type="number"- min={MIN_ITERATION_COUNT}- max={MAX_ITERATION_COUNT}- value={iterationCount}- onChange={(val) => setIterationCount(val ?? undefined)}- onBlur={commitIterationCount}- className="w-20 tabular-nums"- />- <span className="text-secondary">- times in total ({MIN_ITERATION_COUNT}–{MAX_ITERATION_COUNT}).- </span>- </div>+ {frequency !== 'once' && (+ <div className="flex flex-wrap items-center gap-2 text-sm mt-5">+ <span>Show up to</span>+ <LemonInput+ type="number"+ min={MIN_ITERATION_COUNT}+ max={MAX_ITERATION_COUNT}+ value={iterationCount}+ onChange={(val) => setIterationCount(val ?? undefined)}+ onBlur={commitIterationCount}+ className="w-20 tabular-nums"+ />+ <span className="text-secondary">+ times in total ({MIN_ITERATION_COUNT}–{MAX_ITERATION_COUNT}).+ </span>+ </div>+ )}+ </>)}<div className="flex flex-wrap items-center gap-2 text-sm mt-5">