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.

feat(workflows): let people set the conversion window in the builder (#101588)

Daniel Marchuk295c177ed9ce
diff --git a/products/workflows/frontend/Workflows/hogflows/hogFlowEditorLogic.tsx b/products/workflows/frontend/Workflows/hogflows/hogFlowEditorLogic.tsx
index 939588df78a0..0ff737c0e09b 100644
--- a/products/workflows/frontend/Workflows/hogflows/hogFlowEditorLogic.tsx
+++ b/products/workflows/frontend/Workflows/hogflows/hogFlowEditorLogic.tsx
@@ -901,7 +901,8 @@ export interface hogFlowEditorLogicActions {
}[]
| undefined
filters: any
- window_minutes: number | null
+ window?: string | undefined
+ window_minutes?: number | null | undefined
}
| undefined
created_at: string
@@ -1758,7 +1759,8 @@ export interface hogFlowEditorLogicActions {
}[]
| undefined
filters: any
- window_minutes: number | null
+ window?: string | undefined
+ window_minutes?: number | null | undefined
}
| undefined
created_at: string
diff --git a/products/workflows/frontend/Workflows/hogflows/steps/StepTrigger.tsx b/products/workflows/frontend/Workflows/hogflows/steps/StepTrigger.tsx
index e05f884051a3..a2b8eae6b6b4 100644
--- a/products/workflows/frontend/Workflows/hogflows/steps/StepTrigger.tsx
+++ b/products/workflows/frontend/Workflows/hogflows/steps/StepTrigger.tsx
@@ -60,6 +60,7 @@ import { TriggerFrequencyOption, getRegisteredTriggerTypes } from '../registry/t
import { HogFlowAction } from '../types'
import { createAccountAssignmentFilterUpdate, parseAccountAssignmentFilter } from './accountAssignmentFilter'
import { batchTriggerLogic, getAudienceDedupeKey, hogFlowSendsEmail } from './batchTriggerLogic'
+import { HogFlowDuration, MAX_CONVERSION_WINDOW_FOR_DURATION_UNIT } from './components/HogFlowDuration'
import { HogFlowFunctionConfiguration } from './components/HogFlowFunctionConfiguration'
import { RecurringSchedulePicker } from './components/RecurringSchedulePicker'
import { ScheduleStatusBadge } from './components/ScheduleStatusBadge'
@@ -923,11 +924,31 @@ function FrequencySection({
)
}
+const DEFAULT_CONVERSION_WINDOW = '90d'
+// The worker measures a legacy window_minutes at most this long, so a longer stored value is shown
+// as what it actually measures rather than as a number the API would now reject.
+const LEGACY_CONVERSION_WINDOW_CEILING_MINUTES = 90 * 24 * 60
+
+function conversionWindowFromMinutes(minutes: number): string {
+ const capped = Math.min(minutes, LEGACY_CONVERSION_WINDOW_CEILING_MINUTES)
+ if (capped % (24 * 60) === 0) {
+ return `${capped / (24 * 60)}d`
+ }
+ if (capped % 60 === 0) {
+ return `${capped / 60}h`
+ }
+ return `${capped}m`
+}
+
function ConversionGoalSection(): JSX.Element {
const { setWorkflowValue } = useActions(workflowLogic)
const { workflow } = useValues(workflowLogic)
const conversionEventFilters = workflow.conversion?.events?.[0]?.filters ?? {}
+ const legacyWindowMinutes = workflow.conversion?.window_minutes
+ const conversionWindow =
+ workflow.conversion?.window ??
+ (legacyWindowMinutes ? conversionWindowFromMinutes(legacyWindowMinutes) : DEFAULT_CONVERSION_WINDOW)
return (
<div className="flex flex-col py-2 w-full">
@@ -977,6 +998,29 @@ function ConversionGoalSection(): JSX.Element {
buttonCopy="Add event"
/>
</div>
+
+ <div className="flex flex-col gap-1 items-start">
+ <span className="flex gap-1 items-center">
+ <LemonLabel>Conversion window</LemonLabel>
+ <Tooltip title="A person who meets the goal after this window is not counted as converted. The window runs from the moment they enter the workflow.">
+ <IconInfo className="text-secondary" />
+ </Tooltip>
+ </span>
+ <HogFlowDuration
+ value={conversionWindow}
+ onChange={(next) => {
+ // Dropping window_minutes keeps the two forms from arriving together, which
+ // the API rejects. A cleared amount arrives as a bare unit such as "d", so
+ // omitting window restores the default instead of failing the save.
+ const { window_minutes, window, ...conversion } = workflow.conversion ?? {}
+ setWorkflowValue(
+ 'conversion',
+ /\d/.test(next) ? { ...conversion, window: next } : conversion
+ )
+ }}
+ maxValueForUnit={MAX_CONVERSION_WINDOW_FOR_DURATION_UNIT}
+ />
+ </div>
</div>
</div>
)
diff --git a/products/workflows/frontend/Workflows/hogflows/steps/components/HogFlowDuration.tsx b/products/workflows/frontend/Workflows/hogflows/steps/components/HogFlowDuration.tsx
index 7c4844e04d5b..95f2ea6ef1b9 100644
--- a/products/workflows/frontend/Workflows/hogflows/steps/components/HogFlowDuration.tsx
+++ b/products/workflows/frontend/Workflows/hogflows/steps/components/HogFlowDuration.tsx
@@ -12,6 +12,15 @@ const MAX_VALUE_FOR_DURATION_UNIT: Record<string, number> = {
s: 60,
}
+// A conversion window runs to 365 days, which the API enforces, so it needs its own ceilings rather
+// than the ones that bound how long a single delay step waits.
+export const MAX_CONVERSION_WINDOW_FOR_DURATION_UNIT: Record<string, number> = {
+ d: 365,
+ h: 365 * 24,
+ m: 365 * 24 * 60,
+ s: 365 * 24 * 60 * 60,
+}
+
// Type=number lets browsers accept "e", "+" and "-", none of which the executor's duration parser
// understands. "." and "," stay allowed because fractional durations like 1.5d are valid, and "," is
// the decimal separator the browser expects in some locales.
@@ -27,12 +36,15 @@ export function HogFlowDuration({
value,
onChange,
allowUnbounded = false,
+ maxValueForUnit = MAX_VALUE_FOR_DURATION_UNIT,
}: {
value: string
onChange: (value: string) => void
// The per-unit ceilings bound how long a fixed delay waits. A date offset is bounded by the
// step's max_delay_duration instead, so it opts out and keeps its full magnitude ("45 days before").
allowUnbounded?: boolean
+ // Per-unit ceilings for fields whose limit is not a delay step's. Ignored when allowUnbounded.
+ maxValueForUnit?: Record<string, number>
}): JSX.Element {
const inputRef = useRef<HTMLInputElement>(null)
const parts = value.match(DURATION_REGEX)
@@ -53,15 +65,14 @@ export function HogFlowDuration({
}, [numberValue])
// Holds an amount to the unit's ceiling, unless the field opts out (a date offset).
- const capToUnit = (n: number, u: string): number =>
- allowUnbounded ? n : Math.min(n, MAX_VALUE_FOR_DURATION_UNIT[u])
+ const capToUnit = (n: number, u: string): number => (allowUnbounded ? n : Math.min(n, maxValueForUnit[u]))
// Fractions are allowed, so the only lower bound is "greater than zero". Anything at or below it
// would save a delay that never waits, so snap those back up to one whole unit.
const clamp = (n: number): number => (n > 0 ? capToUnit(n, unit) : 1)
const normalizeAmount = (n: number): number =>
- n >= EXPONENT_THRESHOLD ? MAX_VALUE_FOR_DURATION_UNIT[unit] : Number(n.toFixed(MAX_FRACTION_DIGITS))
+ n >= EXPONENT_THRESHOLD ? maxValueForUnit[unit] : Number(n.toFixed(MAX_FRACTION_DIGITS))
return (
<div className="flex gap-2">
@@ -70,7 +81,7 @@ export function HogFlowDuration({
inputRef={inputRef}
value={displayNumber ?? NaN}
min={0}
- max={allowUnbounded ? undefined : MAX_VALUE_FOR_DURATION_UNIT[unit]}
+ max={allowUnbounded ? undefined : maxValueForUnit[unit]}
step="any"
onKeyDown={(e) => {
if (BLOCKED_NUMBER_INPUT_KEYS.has(e.key)) {
diff --git a/products/workflows/frontend/Workflows/hogflows/types.ts b/products/workflows/frontend/Workflows/hogflows/types.ts
index 891b8eed23a0..37d8c151cb71 100644
--- a/products/workflows/frontend/Workflows/hogflows/types.ts
+++ b/products/workflows/frontend/Workflows/hogflows/types.ts
@@ -36,7 +36,8 @@ export const HogFlowSchema = z.object({
.nullable(),
conversion: z
.object({
- window_minutes: z.number().nullable(),
+ window: z.string().optional(),
+ window_minutes: z.number().nullable().optional(),
filters: z.any(),
events: z
.array(
diff --git a/products/workflows/frontend/Workflows/workflowLogic.ts b/products/workflows/frontend/Workflows/workflowLogic.ts
index 9d20137ab2d0..866dc22fcadb 100644
--- a/products/workflows/frontend/Workflows/workflowLogic.ts
+++ b/products/workflows/frontend/Workflows/workflowLogic.ts
@@ -1006,7 +1006,8 @@ export interface workflowLogicActions {
}[]
| undefined
filters: any
- window_minutes: number | null
+ window?: string | undefined
+ window_minutes?: number | null | undefined
}
| undefined
created_at: string
@@ -1863,7 +1864,8 @@ export interface workflowLogicActions {
}[]
| undefined
filters: any
- window_minutes: number | null
+ window?: string | undefined
+ window_minutes?: number | null | undefined
}
| undefined
created_at: string