Skip to content

: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.

refactor(surveys): tidy legacy Display conditions section (#58893)

Lucas Fariaf78a86e740dc
diff --git a/frontend/snapshots.yml b/frontend/snapshots.yml
index 2a5e7cfe2164..9621adad13ef 100644
--- a/frontend/snapshots.yml
+++ b/frontend/snapshots.yml
@@ -5563,9 +5563,9 @@ snapshots:
scenes-app-surveys--new-survey-customisation-section--light:
hash: v1.k794b7964.288fec0f91326deccbaf9910189134f14be62162013df6c8364e438e90e095cc.IuLmX5ajln3b3KtOTFFdHZMGlJk9iaCRitsBWvb2bzU
scenes-app-surveys--new-survey-targeting-section--dark:
- hash: v1.k794b7964.3bfc8b6bf633d952b40bb28397b317a7d0c7ce937aa00c1c36fb8296c8fdc5ca.Y00qyQ4JDGcqi4wwbMhuyofDZc_5xZWP42_JrLZ0lLE
+ hash: v1.k794b7964.291b22007c1e8f4fd06d46e9c7d1f87ae70ebd3ec766328340ad89ea3f2ab16b.xS2De9yYBV2JVrvQlzbqMjD2i3HpALi7iVI7TczcfdI
scenes-app-surveys--new-survey-targeting-section--light:
- hash: v1.k794b7964.8a3821d75dfea493f5a9e3586d5057e5da30dc9e6a9c37cf40c4b80e78792988.fX3miFzzpV66ZEeVZJQjO-UUmvlQggLHZRAwAkCsuMg
+ hash: v1.k794b7964.428c3041d4d8a23ad1faa0c885f06cb34a166c344f7b74c39450107279a68b69.SYss9mta5gXUBO6hDBww3B8CJc0HtI-8EoCgtobBtO0
scenes-app-surveys--new-survey-with-html-question-description--dark:
hash: v1.k794b7964.70d82e0de54aa3a0982efc2faed7b69936d09f4d24571e270fc6291130ac7af4.SK36SUGAETwqhQUwRQp_oZ8E4AgSWRrZSN5pt-H9xKU
scenes-app-surveys--new-survey-with-html-question-description--light:
diff --git a/frontend/src/scenes/surveys/SurveyEdit.tsx b/frontend/src/scenes/surveys/SurveyEdit.tsx
index 3986fc82a3d5..be4eb2d1a146 100644
--- a/frontend/src/scenes/surveys/SurveyEdit.tsx
+++ b/frontend/src/scenes/surveys/SurveyEdit.tsx
@@ -29,7 +29,6 @@ import { PropertyValue } from 'lib/components/PropertyFilters/components/Propert
import { TaxonomicFilterGroupType } from 'lib/components/TaxonomicFilter/types'
import { FEATURE_FLAGS } from 'lib/constants'
import { dayjs } from 'lib/dayjs'
-import { IconCancel } from 'lib/lemon-ui/icons'
import { LemonField } from 'lib/lemon-ui/LemonField'
import { LemonRadio, LemonRadioOption } from 'lib/lemon-ui/LemonRadio'
import { Tooltip } from 'lib/lemon-ui/Tooltip'
@@ -1333,48 +1332,46 @@ export default function SurveyEdit({ id }: { id: string }): JSX.Element {
dataAttr: 'survey-display-conditions',
content: (
<LemonField.Pure>
- <LemonSelect
+ <LemonRadio
+ value={hasTargetingSet ? 'matching' : 'all'}
onChange={(value) => {
- if (value) {
+ if (value === 'all') {
resetTargeting()
} else {
- // TRICKY: When attempting to set user match conditions
- // we want a proxy value to be set so that the user
- // can then edit these, or decide to go back to all user targeting
+ // Proxy value so the conditions block renders and the
+ // user can start editing or return to "all users".
setSurveyValue('conditions', { url: '' })
}
}}
- value={!hasTargetingSet}
options={[
- { label: 'All users', value: true },
{
- label: 'Users who match all of the following...',
- value: false,
+ value: 'all',
+ label: 'All users',
+ description: 'Show this survey to everyone',
+ },
+ {
+ value: 'matching',
+ label: 'Only users who match conditions',
+ description:
+ 'Show this survey only when every condition below is met',
'data-attr': 'survey-display-conditions-select-users',
},
]}
data-attr="survey-display-conditions-select"
/>
- {!hasTargetingSet ? (
- <span className="text-secondary">
- Survey <b>will be released to everyone</b>
- </span>
- ) : (
+ {hasTargetingSet && (
<>
+ <h3 className="text-xs font-semibold text-secondary uppercase tracking-wider mt-3 mb-0">
+ Targeting
+ </h3>
<LemonField
name="linked_flag_id"
- label="Link feature flag (optional)"
- info={
- <>
- Connecting to a feature flag will
- automatically enable this survey for everyone
- in the feature flag.
- </>
- }
+ label="Feature flag targeting"
+ help="Linking a flag also enables the survey for everyone the flag is on for."
>
{({ value, onChange }) => (
<div
- className="flex"
+ className="flex items-center gap-2"
data-attr="survey-display-conditions-linked-flag"
>
<FlagSelector
@@ -1431,9 +1428,9 @@ export default function SurveyEdit({ id }: { id: string }): JSX.Element {
/>
{value && (
<LemonButton
- className="ml-2"
- icon={<IconCancel />}
+ type="tertiary"
size="small"
+ icon={<IconTrash />}
onClick={() => {
onChange(null)
setSurveyValue(
@@ -1448,8 +1445,9 @@ export default function SurveyEdit({ id }: { id: string }): JSX.Element {
...conditions,
})
}}
- aria-label="close"
- />
+ >
+ Clear
+ </LemonButton>
)}
</div>
)}
@@ -1499,11 +1497,11 @@ export default function SurveyEdit({ id }: { id: string }): JSX.Element {
<LemonField.Pure
label="URL targeting"
error={urlMatchTypeValidationError}
- info="Targeting by regex or exact match requires at least version 1.82 of posthog-js"
+ help="Regex and exact match need posthog-js 1.82+."
>
<div className="flex flex-row gap-2 items-center">
- URL
<LemonSelect
+ className="w-40 shrink-0"
value={
value?.urlMatchType ||
SurveyMatchType.Contains
@@ -1545,27 +1543,22 @@ export default function SurveyEdit({ id }: { id: string }): JSX.Element {
</div>
</LemonField.Pure>
<LemonField.Pure
- label="Device Types"
+ label="Device types"
error={
deviceTypesMatchTypeValidationError
}
- info={
+ help={
<>
- Add the device types to show the
- survey on. Possible values:
- 'Desktop', 'Mobile', 'Tablet'. For
- the full list and caveats,{' '}
<Link to="https://posthog.com/docs/surveys/creating-surveys#display-conditions">
- check the documentation here
+ See accepted values
</Link>
- . Requires at least version 1.214
- of posthog-js
+ . Needs posthog-js 1.214+.
</>
}
>
<div className="flex flex-row gap-2 items-center">
- Device Types
<LemonSelect
+ className="w-40 shrink-0"
value={
value?.deviceTypesMatchType ||
SurveyMatchType.Contains
@@ -1617,41 +1610,43 @@ export default function SurveyEdit({ id }: { id: string }): JSX.Element {
placeholder="ex: Desktop|Mobile"
/>
) : (
- <PropertyValue
- propertyKey={getPropertyKey(
- 'Device Type',
- TaxonomicFilterGroupType.EventProperties
- )}
- type={
- PropertyFilterType.Event
- }
- onSet={(
- deviceTypes:
- | string
- | string[]
- ) => {
- onChange({
- ...value,
+ <div className="flex-1 min-w-0">
+ <PropertyValue
+ propertyKey={getPropertyKey(
+ 'Device Type',
+ TaxonomicFilterGroupType.EventProperties
+ )}
+ type={
+ PropertyFilterType.Event
+ }
+ onSet={(
deviceTypes:
- Array.isArray(
- deviceTypes
- )
- ? deviceTypes
- : [
- deviceTypes,
- ],
- })
- }}
- operator={
- PropertyOperator.Exact
- }
- value={value?.deviceTypes}
- inputClassName="flex-1"
- />
+ | string
+ | string[]
+ ) => {
+ onChange({
+ ...value,
+ deviceTypes:
+ Array.isArray(
+ deviceTypes
+ )
+ ? deviceTypes
+ : [
+ deviceTypes,
+ ],
+ })
+ }}
+ operator={
+ PropertyOperator.Exact
+ }
+ value={value?.deviceTypes}
+ inputClassName="w-full"
+ />
+ </div>
)}
</div>
</LemonField.Pure>
- <LemonField.Pure label="CSS selector matches:">
+ <LemonField.Pure label="CSS selector matches">
<LemonInput
value={value?.selector}
onChange={(selectorVal) =>
@@ -1665,73 +1660,56 @@ export default function SurveyEdit({ id }: { id: string }): JSX.Element {
</LemonField.Pure>
<LemonField.Pure
label="Survey wait period"
- info="Note that this condition will only apply reliably for identified users within a single browser session. Anonymous users or users who switch browsers, use incognito sessions, or log out and log back in may see the survey again. Additionally, responses submitted while a user is anonymous may be associated with their account if they log in during the same session."
+ help="Reliable only for identified users in the same browser session — incognito, browser switches, and logout/login may still see the survey again."
>
- <div className="flex flex-row gap-2 items-center">
+ <div className="flex flex-wrap gap-2 items-center text-sm">
<LemonCheckbox
checked={
!!value?.seenSurveyWaitPeriodInDays
}
onChange={(checked) => {
- if (checked) {
- onChange({
- ...value,
- seenSurveyWaitPeriodInDays:
- value?.seenSurveyWaitPeriodInDays ||
- 30,
- })
- } else {
- const {
- seenSurveyWaitPeriodInDays,
- ...rest
- } = value || {}
- onChange(rest)
- }
+ onChange({
+ ...value,
+ seenSurveyWaitPeriodInDays:
+ checked
+ ? value?.seenSurveyWaitPeriodInDays ||
+ 30
+ : null,
+ })
}}
+ label="Don't show this survey if another one was shown to the user in the last"
/>
- Don't show to users who saw any survey
- in the last
- <LemonInput
- type="number"
- size="xsmall"
- min={0}
- value={
- value?.seenSurveyWaitPeriodInDays ||
- NaN
- }
- onChange={(val) => {
- if (
- val !== undefined &&
- val > 0
- ) {
- onChange({
- ...value,
- seenSurveyWaitPeriodInDays:
- val,
- })
- } else {
+ <div className="flex items-center gap-2">
+ <LemonInput
+ type="number"
+ size="xsmall"
+ min={1}
+ value={
+ value?.seenSurveyWaitPeriodInDays ??
+ undefined
+ }
+ onChange={(val) =>
onChange({
...value,
seenSurveyWaitPeriodInDays:
- null,
+ val && val > 0
+ ? val
+ : null,
})
}
- }}
- className="w-12"
- id="survey-wait-period-input"
- />{' '}
- {value?.seenSurveyWaitPeriodInDays ===
- 1 ? (
- <span>day.</span>
- ) : (
- <span>days.</span>
- )}
+ className="w-16 tabular-nums"
+ id="survey-wait-period-input"
+ />
+ <span className="text-secondary">
+ days.
+ </span>
+ </div>
</div>
</LemonField.Pure>
</>
)}
</LemonField>
- <LemonField.Pure label="Properties">
+ <LemonField.Pure label="Audience filters">
<BindLogic
logic={featureFlagLogic}
props={{
@@ -1802,12 +1780,12 @@ export default function SurveyEdit({ id }: { id: string }): JSX.Element {
)}
</BindLogic>
</LemonField.Pure>
+ <h3 className="text-xs font-semibold text-secondary uppercase tracking-wider mt-4 mb-0">
+ Triggers
+ </h3>
{featureFlags[FEATURE_FLAGS.SURVEYS_ACTIONS] ? (
- <LemonField.Pure
- label="Activation triggers"
- info="Survey will activate when any of these conditions are met"
- >
- <div className="border rounded p-3 space-y-3">
+ <LemonField.Pure label="Activation triggers">
+ <div className="space-y-4">
<SurveyEventTrigger />
<div className="flex items-center gap-2">
<div className="flex-1 border-t border-dashed" />
diff --git a/frontend/src/scenes/surveys/SurveyEventTrigger.test.tsx b/frontend/src/scenes/surveys/SurveyEventTrigger.test.tsx
index 6be5cad1a3df..318346d8a8e6 100644
--- a/frontend/src/scenes/surveys/SurveyEventTrigger.test.tsx
+++ b/frontend/src/scenes/surveys/SurveyEventTrigger.test.tsx
@@ -78,8 +78,7 @@ describe('Survey event trigger property filters', () => {
</Provider>
)
- expect(await screen.findByText('Narrow this trigger to matching events only.')).toBeInTheDocument()
- expect(screen.getByText('No filters yet')).toBeInTheDocument()
+ expect(await screen.findByText('No filters')).toBeInTheDocument()
expect(screen.getByText('Property filters for signed_up')).toBeInTheDocument()
})
diff --git a/frontend/src/scenes/surveys/SurveyEventTrigger.tsx b/frontend/src/scenes/surveys/SurveyEventTrigger.tsx
index f4703ee37e1c..332001e6bb8b 100644
--- a/frontend/src/scenes/surveys/SurveyEventTrigger.tsx
+++ b/frontend/src/scenes/surveys/SurveyEventTrigger.tsx
@@ -172,39 +172,32 @@ function SurveyEventSelector({
{
key: panelKey,
header: (
- <div className="flex items-center gap-2 flex-1">
- <span className="font-semibold text-sm">{event.name}</span>
- <span className="text-xs text-muted bg-border px-1.5 py-0.5 rounded">
- {hasPropertyFilters
- ? `${propertyFilterCount} filter${propertyFilterCount !== 1 ? 's' : ''}`
- : 'No filters yet'}
- </span>
- <span className="text-xs text-muted-alt">
- {hasPropertyFilters
- ? 'Refine this trigger'
- : 'Optional: add property filters'}
- </span>
+ <div className="flex items-center gap-2 flex-1 justify-between">
+ <div className="flex items-center gap-2 min-w-0">
+ <span className="font-semibold text-sm truncate">
+ {event.name}
+ </span>
+ <span className="text-xs text-muted bg-border px-1.5 py-0.5 rounded shrink-0">
+ {hasPropertyFilters
+ ? `${propertyFilterCount} filter${propertyFilterCount !== 1 ? 's' : ''}`
+ : 'No filters'}
+ </span>
+ </div>
+ <LemonButton
+ size="xsmall"
+ icon={<IconX />}
+ onClick={(e) => {
+ e.stopPropagation()
+ removeEventAtIndex(index)
+ }}
+ type="tertiary"
+ status="alt"
+ tooltip="Remove event"
+ />
</div>
),
content: (
- <div>
- <div className="flex justify-end mb-2">
- <LemonButton
- size="xsmall"
- icon={<IconX />}
- onClick={() => removeEventAtIndex(index)}
- type="tertiary"
- status="alt"
- >
- Remove event
- </LemonButton>
- </div>
- <div className="text-xs font-medium text-muted-alt mb-2 uppercase tracking-wide">
- Event property filters
- </div>
- <div className="text-xs text-muted mb-3">
- Narrow this trigger to matching events only.
- </div>
+ <div className="space-y-2">
<PropertyFilters
propertyFilters={convertPropertyFiltersToArray(
event.propertyFilters
@@ -224,11 +217,9 @@ function SurveyEventSelector({
buttonSize="small"
operatorAllowlist={SUPPORTED_OPERATORS}
/>
- <span className="text-xs text-muted">
- Only primitive types (strings, numbers, booleans) are supported
- for property filters. Array and object properties are not
- supported and will not be shown.
- </span>
+ <p className="text-xs text-muted m-0">
+ Array and object properties aren't supported here.
+ </p>
</div>
),
},
@@ -241,7 +232,7 @@ function SurveyEventSelector({
{showRepeatedActivation && surveyRepeatedActivationAvailable && (
<LemonCheckbox
- label="Display the survey every time events occur, instead of only once per user"
+ label="Show every time these events fire (otherwise: once per user)"
checked={survey.conditions?.events?.repeatedActivation || false}
onChange={(checked) => {
setSurveyValue('conditions', {
@@ -270,9 +261,9 @@ export function SurveyEventTrigger(): JSX.Element {
<SurveyEventSelector
conditionField="events"
label="User sends events"
- info="It only triggers when the event is captured in the current user session and using the PostHog SDK. Filtering by event properties requires posthog-js >= v1.268.0 or posthog-react-native >= v4.15.0. Not supported for other SDKs."
+ info="Triggers fire when the event is captured in the current user session via a PostHog SDK. Property filtering requires posthog-js 1.268+ or posthog-react-native 4.15+."
emptyTitle="No events selected"
- emptyDescription="Add events to trigger this survey when those events are captured in the current user session"
+ emptyDescription="Pick events that should trigger this survey."
showRepeatedActivation
/>
)
@@ -286,9 +277,9 @@ export function SurveyCancelEventTrigger(): JSX.Element {
<SurveyEventSelector
conditionField="cancelEvents"
label="Cancel survey on events"
- info="It only triggers when the event is captured in the current user session and using the PostHog SDK. Requires posthog-js SDK at least v1.299.0, and it's supported only for web surveys."
+ info="Triggers fire when the event is captured in the current user session via a PostHog SDK. Requires posthog-js 1.299+. Web surveys only."
emptyTitle={`During your ${delaySeconds} second delay...`}
- emptyDescription="If any of these events fire, the survey will be cancelled. Useful for not interrupting users who complete an action successfully."
+ emptyDescription="If any of these events fire, the survey is cancelled — useful when the user has already completed the action."
addButtonText="Add cancel event"
/>
)
diff --git a/frontend/src/scenes/surveys/SurveyTranslations.tsx b/frontend/src/scenes/surveys/SurveyTranslations.tsx
index 663bddf664e3..f862c770c311 100644
--- a/frontend/src/scenes/surveys/SurveyTranslations.tsx
+++ b/frontend/src/scenes/surveys/SurveyTranslations.tsx
@@ -228,7 +228,6 @@ export function SurveyTranslations(): JSX.Element {
placeholder="Add a language (e.g., 'fr', 'French', 'fr-CA')"
className="grow"
allowCustomValues
- autoFocus={addedLanguages.length === 0}
value={[]}
/>
<LemonButton
diff --git a/frontend/src/scenes/surveys/utils.ts b/frontend/src/scenes/surveys/utils.ts
index 519b3ede0464..3af79c32b3d5 100644
--- a/frontend/src/scenes/surveys/utils.ts
+++ b/frontend/src/scenes/surveys/utils.ts
@@ -28,6 +28,7 @@ import {
SurveyQuestion,
SurveyQuestionType,
SurveyRates,
+ SurveySchedule,
SurveyStats,
SurveyType,
} from '~/types'
@@ -509,6 +510,12 @@ export function canUseSurveyWizard(survey: Survey | NewSurvey): boolean {
if (survey.type !== SurveyType.Popover) {
return false
}
+ // SurveySchedule.Always — the wizard offers Once + recurring frequencies, but not "every time
+ // the display conditions are met". Keep Always surveys in the legacy editor where the option
+ // is actually visible, so the wizard never silently misrepresents the cadence.
+ if (survey.schedule === SurveySchedule.Always) {
+ return false
+ }
// Adaptive sampling — WhenStep exposes a simple responses_limit but not
// the adaptive sampling controls
if (survey.response_sampling_limit || survey.response_sampling_start_date) {