: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(workflows): add view list, per-step edit on review, and goal results to broadcasts (#109574)
Daniel Marchuk8a7e716adb78
diff --git a/products/workflows/frontend/Broadcasts/BroadcastPerformance.tsx b/products/workflows/frontend/Broadcasts/BroadcastPerformance.tsxindex d095a74b441e..6f99872a2e03 100644--- a/products/workflows/frontend/Broadcasts/BroadcastPerformance.tsx+++ b/products/workflows/frontend/Broadcasts/BroadcastPerformance.tsx@@ -13,7 +13,10 @@ function share(part: number, whole: number): string {return whole > 0 ? percentage(part / whole, 1) : '-'}-export function BroadcastPerformance(props: BroadcastPerformanceLogicProps): JSX.Element {+export function BroadcastPerformance({+ hasGoal = false,+ ...props+}: BroadcastPerformanceLogicProps & { hasGoal?: boolean }): JSX.Element {const logic = broadcastPerformanceLogic(props)const { stats, totalsLoading, totalsFailed, links, linksLoading } = useValues(logic)const { loadTotals } = useActions(logic)@@ -43,6 +46,7 @@ export function BroadcastPerformance(props: BroadcastPerformanceLogicProps): JSX{ label: 'Opened', part: stats.opened, whole: stats.trackedSends },{ label: 'Clicked', part: stats.clicked, whole: stats.trackedSends },{ label: 'Clicked to opened', part: stats.clicked, whole: stats.opened },+ ...(hasGoal ? [{ label: 'Converted', part: stats.converted, whole: stats.sent }] : []),]return (@@ -70,7 +74,10 @@ export function BroadcastPerformance(props: BroadcastPerformanceLogicProps): JSX<LemonProgress percent={whole > 0 ? (part / whole) * 100 : 0} size="large" /></div>))}- <span className="text-xs text-muted">Opens and clicks are counted against sends with tracking on.</span>+ <span className="text-xs text-muted">+ Opens and clicks are counted against sends with tracking on.+ {hasGoal ? ' Conversions are counted against all sends.' : ''}+ </span></div><BroadcastSendActivity {...props} />diff --git a/products/workflows/frontend/Broadcasts/BroadcastSummary.tsx b/products/workflows/frontend/Broadcasts/BroadcastSummary.tsxindex 9987de7259bc..89acc4e5fbcb 100644--- a/products/workflows/frontend/Broadcasts/BroadcastSummary.tsx+++ b/products/workflows/frontend/Broadcasts/BroadcastSummary.tsx@@ -17,12 +17,13 @@ import { TZLabel } from 'lib/components/TZLabel'import { LemonMenu } from 'lib/lemon-ui/LemonMenu'import { LemonTable, LemonTableColumns } from 'lib/lemon-ui/LemonTable'import { LemonTabs } from 'lib/lemon-ui/LemonTabs'+import { cn } from 'lib/utils/css-classes'import { humanFriendlyNumber } from 'lib/utils/numbers'import { capitalizeFirstLetter } from 'lib/utils/strings'import { SceneContent } from '~/layout/scenes/components/SceneContent'-import type { HogFlowBatchJobApi } from 'products/workflows/frontend/generated/api.schemas'+import type { HogFlowBatchJobApi, HogFlowConversionApi } from 'products/workflows/frontend/generated/api.schemas'import { EmailViewerModal } from '../Workflows/EmailViewerModal'import type { MessageAsset } from '../Workflows/messageAssetsApi'@@ -273,6 +274,8 @@ export function BroadcastSummary(): JSX.Element {duplicating,summaryStatus,summaryTab,+ goalEnabled,+ conversion,} = useValues(broadcastWizardLogic)const { moveToDraft, duplicateBroadcast, setSummaryTab, archiveBroadcast, restoreBroadcast, deleteBroadcast } =useActions(broadcastWizardLogic)@@ -405,7 +408,12 @@ export function BroadcastSummary(): JSX.Element {label: 'Overview',content: (<div className="flex flex-col gap-4">- <div className="grid grid-cols-1 gap-4 rounded-lg border border-border bg-surface-primary p-4 @2xl:grid-cols-3">+ <div+ className={cn(+ 'grid grid-cols-1 gap-4 rounded-lg border border-border bg-surface-primary p-4',+ goalEnabled ? '@2xl:grid-cols-4' : '@2xl:grid-cols-3'+ )}+ ><SummaryRow label="Audience">{audienceProperties.length > 0 ? (<div className="flex flex-col gap-2">@@ -440,6 +448,7 @@ export function BroadcastSummary(): JSX.Element {<SummaryRow label="Subject">{email.subject || <span className="text-muted">No subject</span>}</SummaryRow>+ {goalEnabled && <SummaryRow label="Goal">{goalSummary(conversion)}</SummaryRow>}</div><div className="flex flex-col gap-2"><h2 className="m-0 text-base font-semibold">@@ -449,6 +458,7 @@ export function BroadcastSummary(): JSX.Element {<BroadcastPerformancerunId={latestBatchJob.id}runStartedAt={latestBatchJob.created_at}+ hasGoal={goalEnabled}/>) : (<span className="text-muted">@@ -487,6 +497,22 @@ export function BroadcastSummary(): JSX.Element {)}+const WINDOW_UNITS: Record<string, string> = { m: 'minute', h: 'hour', d: 'day', w: 'week' }++function goalSummary(conversion: HogFlowConversionApi): string {+ const events = (conversion.events?.[0]?.filters?.events ?? []).map(+ (event: { name?: string; id?: string }) => event.name || String(event.id)+ )+ const target = events.length > 0 ? events.join(' or ') : 'Matches the goal filters'+ const match = /^(\d+)([mhdw])$/.exec(conversion.window ?? '')+ if (!match) {+ return target+ }+ const amount = Number(match[1])+ const unit = WINDOW_UNITS[match[2]]+ return `${target} within ${amount} ${unit}${amount === 1 ? '' : 's'}`+}+function SummaryRow({ label, children }: { label: string; children: React.ReactNode }): JSX.Element {return (<div className="flex flex-col gap-1">diff --git a/products/workflows/frontend/Broadcasts/broadcastPerformanceLogic.ts b/products/workflows/frontend/Broadcasts/broadcastPerformanceLogic.tsindex 78cf96caecda..e99b77ee6ecf 100644--- a/products/workflows/frontend/Broadcasts/broadcastPerformanceLogic.ts+++ b/products/workflows/frontend/Broadcasts/broadcastPerformanceLogic.ts@@ -24,6 +24,8 @@ export interface BroadcastPerformanceStats {failed: number/** Sends with open and click tracking, the denominator for engagement rates. */trackedSends: number+ /** Recipients who met the broadcast's goal. */+ converted: number}const TOTALS_METRICS = [@@ -35,6 +37,7 @@ const TOTALS_METRICS = ['email_blocked','email_failed','email_untracked',+ 'conversion',]/** Hourly buckets read well for a few days after a send, then the tail of late opens needs daily ones. */@@ -207,6 +210,7 @@ export const broadcastPerformanceLogic = kea<broadcastPerformanceLogicType>([markedAsSpam: totals.email_blocked ?? 0,failed: totals.email_failed ?? 0,trackedSends: Math.max(sent - (totals.email_untracked ?? 0), 0),+ converted: totals.conversion ?? 0,}},],diff --git a/products/workflows/frontend/Broadcasts/steps/BroadcastRecipientsStep.tsx b/products/workflows/frontend/Broadcasts/steps/BroadcastRecipientsStep.tsxindex 9cf4e11b9c4f..1893fec90ee5 100644--- a/products/workflows/frontend/Broadcasts/steps/BroadcastRecipientsStep.tsx+++ b/products/workflows/frontend/Broadcasts/steps/BroadcastRecipientsStep.tsx@@ -1,14 +1,18 @@import { useActions, useValues } from 'kea'+import { useState } from 'react'import { IconWarning } from '@posthog/icons'-import { Spinner } from '@posthog/lemon-ui'+import { LemonButton, LemonModal, Spinner } from '@posthog/lemon-ui'import { PropertyFilters } from 'lib/components/PropertyFilters/PropertyFilters'import { TaxonomicFilterGroupType } from 'lib/components/TaxonomicFilter/types'import { humanFriendlyNumber } from 'lib/utils/numbers'import { COHORTS_ONLY_SUPPORT_IN_PICKER_PROPS } from 'scenes/feature-flags/cohortPickerProps'+import { Scene } from 'scenes/sceneTypes'-import { PropertyFilterType } from '~/types'+import { DataTable } from '~/queries/nodes/DataTable/DataTable'+import { ActorsQuery, DataTableNode, NodeKind, ProductKey } from '~/queries/schema/schema-general'+import { AnyPersonScopeFilter, PropertyFilterType } from '~/types'import { WORKFLOW_OPERATOR_ALLOWLIST } from '../../Workflows/hogflows/filters/HogFlowFilters'import { BroadcastAudienceCohorts } from '../audience/BroadcastAudienceCohorts'@@ -48,9 +52,43 @@ function AudienceSizePreview(): JSX.Element | null {)}+function AudienceListTable(): JSX.Element {+ const { audienceProperties } = useValues(broadcastWizardLogic)+ const [query, setQuery] = useState<DataTableNode>(() => ({+ kind: NodeKind.DataTableNode,+ source: {+ kind: NodeKind.ActorsQuery,+ tags: { productKey: ProductKey.WORKFLOWS, scene: Scene.Broadcast },+ select: ['person_display_name -- Person', 'properties.email -- Email', 'created_at'],+ properties: audienceProperties as AnyPersonScopeFilter[],+ orderBy: ['created_at DESC'],+ } as ActorsQuery,+ full: false,+ showSearch: true,+ }))++ return <DataTable query={query} setQuery={setQuery} uniqueKey="broadcast-audience-list" readOnly />+}++function AudienceListModal({ isOpen, onClose }: { isOpen: boolean; onClose: () => void }): JSX.Element {+ return (+ <LemonModal+ isOpen={isOpen}+ onClose={onClose}+ title="People who match now"+ description="The list updates at send time. People who share an email address get one email."+ width={900}+ >+ {/* Mounted per open, so the list always reflects the current conditions. */}+ {isOpen && <AudienceListTable />}+ </LemonModal>+ )+}+export function BroadcastRecipientsStep(): JSX.Element {const { audienceProperties } = useValues(broadcastWizardLogic)const { setAudienceProperties } = useActions(broadcastWizardLogic)+ const [audienceListOpen, setAudienceListOpen] = useState(false)return (<div className="flex flex-col gap-2">@@ -60,9 +98,20 @@ export function BroadcastRecipientsStep(): JSX.Element {Filter by person properties or cohorts. Without filters, the broadcast goes to everyone.</p></div>- <div>- <span className="font-semibold">This broadcast will reach</span> <AudienceSizePreview />+ <div className="flex items-start justify-between gap-2">+ <div>+ <span className="font-semibold">This broadcast will reach</span> <AudienceSizePreview />+ </div>+ <LemonButton+ size="small"+ type="secondary"+ onClick={() => setAudienceListOpen(true)}+ data-attr="broadcast-audience-view-list"+ >+ View list+ </LemonButton></div>+ <AudienceListModal isOpen={audienceListOpen} onClose={() => setAudienceListOpen(false)} /><PropertyFilterspageKey="broadcast-wizard-recipients"propertyFilters={audienceProperties}diff --git a/products/workflows/frontend/Broadcasts/steps/BroadcastReviewStep.tsx b/products/workflows/frontend/Broadcasts/steps/BroadcastReviewStep.tsxindex 497932748806..b76a8a7e1688 100644--- a/products/workflows/frontend/Broadcasts/steps/BroadcastReviewStep.tsx+++ b/products/workflows/frontend/Broadcasts/steps/BroadcastReviewStep.tsx@@ -1,5 +1,6 @@import { useActions, useMountedLogic, useValues } from 'kea'+import { IconWarning } from '@posthog/icons'import { LemonButton, Spinner } from '@posthog/lemon-ui'import PropertyFiltersDisplay from 'lib/components/PropertyFilters/components/PropertyFiltersDisplay'@@ -9,12 +10,48 @@ import { humanFriendlyNumber } from 'lib/utils/numbers'import { BroadcastAudienceCohorts } from '../audience/BroadcastAudienceCohorts'import { broadcastAudienceCohortsLogic } from '../audience/broadcastAudienceCohortsLogic'import { BroadcastEmailPreview } from '../BroadcastEmailPreview'-import { SENDERS_LOAD_FAILED_ERROR, broadcastWizardLogic } from '../broadcastWizardLogic'+import { BroadcastWizardStep, SENDERS_LOAD_FAILED_ERROR, broadcastWizardLogic } from '../broadcastWizardLogic'++function ReviewRow({+ label,+ step,+ showErrors = true,+ children,+}: {+ label: string+ step: Exclude<BroadcastWizardStep, 'review'>+ showErrors?: boolean+ children: React.ReactNode+}): JSX.Element {+ const { stepValidationErrors } = useValues(broadcastWizardLogic)+ const { setStep } = useActions(broadcastWizardLogic)+ const errors = showErrors ? stepValidationErrors[step] : []-function ReviewRow({ label, children }: { label: string; children: React.ReactNode }): JSX.Element {return (<div className="flex flex-col gap-1 border-b border-border pb-3 last:border-b-0">- <span className="text-xs font-semibold uppercase tracking-wide text-muted">{label}</span>+ <div className="flex items-center justify-between gap-2">+ <span className="text-xs font-semibold uppercase tracking-wide text-muted">{label}</span>+ <LemonButton+ size="xsmall"+ type="secondary"+ onClick={() => setStep(step)}+ data-attr={`broadcast-review-edit-${step}`}+ >+ Edit+ </LemonButton>+ </div>+ {errors.map((error) => (+ <LemonButton+ key={error}+ size="small"+ status="danger"+ icon={<IconWarning />}+ onClick={() => setStep(step)}+ data-attr={`broadcast-review-fix-${step}`}+ >+ {error}+ </LemonButton>+ ))}<div>{children}</div></div>)@@ -37,6 +74,15 @@ export function BroadcastReviewStep(): JSX.Element {const { integrationsLoading } = useValues(integrationsLogic)const { loadIntegrations } = useActions(integrationsLogic)+ // Errors a step owns show in that step's row, with a way to fix them.+ const stepErrors = new Set([+ ...stepValidationErrors.recipients,+ ...stepValidationErrors.goal,+ ...stepValidationErrors.content,+ ...stepValidationErrors.schedule,+ ])+ const reviewOnlyErrors = stepValidationErrors.review.filter((error) => !stepErrors.has(error))+const goalEventNames: string[] = goalEnabled? (conversion.events?.[0]?.filters?.events ?? []).map((event: { name?: string; id?: string }) => event.name || String(event.id)@@ -51,7 +97,7 @@ export function BroadcastReviewStep(): JSX.Element {</div><div className="flex flex-col gap-3 rounded-lg border border-border bg-surface-primary p-4">- <ReviewRow label="Recipients">+ <ReviewRow label="Recipients" step="recipients">{blastRadiusLoading ? (<Spinner />) : blastRadius ? (@@ -74,7 +120,7 @@ export function BroadcastReviewStep(): JSX.Element {)}</ReviewRow>- <ReviewRow label="Goal">+ <ReviewRow label="Goal" step="goal">{goalEnabled ? (goalEventNames.length > 0 ? (<span>Conversion when a person performs: {goalEventNames.join(', ')}</span>@@ -86,28 +132,30 @@ export function BroadcastReviewStep(): JSX.Element {)}</ReviewRow>- <ReviewRow label="Email">+ <ReviewRow label="Email" step="content"><BroadcastEmailPreview /></ReviewRow>- <ReviewRow label="Schedule">{scheduleSummary}</ReviewRow>+ <ReviewRow label="Schedule" step="schedule">+ {scheduleSummary}+ </ReviewRow>{emailRateLimit && (- <ReviewRow label="Sending rate">+ <ReviewRow label="Sending rate" step="schedule" showErrors={false}>At most {humanFriendlyNumber(emailRateLimit.count)} emails per {emailRateLimit.period}{rateLimitedSendDuration ? `, so about ${rateLimitedSendDuration} to reach everyone` : ''}</ReviewRow>)}</div>- {stepValidationErrors.review.length > 0 && (+ {reviewOnlyErrors.length > 0 && (<div className="flex flex-col gap-1">- {stepValidationErrors.review.map((error) => (+ {reviewOnlyErrors.map((error) => (<div key={error} className="text-danger text-xs">{error}</div>))}- {stepValidationErrors.review.includes(SENDERS_LOAD_FAILED_ERROR) && (+ {reviewOnlyErrors.includes(SENDERS_LOAD_FAILED_ERROR) && (<div><LemonButtontype="secondary"