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 broadcasts pick a message category and turn off tracking (#110004)

Daniel Marchuk04f8ea045e3d
diff --git a/products/workflows/frontend/Broadcasts/broadcastWizardLogic.test.ts b/products/workflows/frontend/Broadcasts/broadcastWizardLogic.test.ts
index bf087168a0ab..8b9876eaf360 100644
--- a/products/workflows/frontend/Broadcasts/broadcastWizardLogic.test.ts
+++ b/products/workflows/frontend/Broadcasts/broadcastWizardLogic.test.ts
@@ -60,6 +60,7 @@ describe('broadcastWizardLogic', () => {
let latest: HogFlowApi
let releaseCreate: () => void
let patchedSubjects: string[]
+ let patchedTracking: unknown[]
let patchedNames: string[]
let holdPatch: Promise<void> | null
let onPatchStarted: (() => void) | null
@@ -67,6 +68,7 @@ describe('broadcastWizardLogic', () => {
beforeEach(() => {
patchedSubjects = []
+ patchedTracking = []
patchedNames = []
holdPatch = null
onPatchStarted = null
@@ -95,13 +97,14 @@ describe('broadcastWizardLogic', () => {
savedBroadcast({ name: body.name ?? '', subject: '', updatedAt: '2026-09-24T10:00:05Z' }),
]
}
- const subject = body.actions.find((action) => action.type === 'function_email').config.inputs.email
- .value.subject
+ const emailConfig = body.actions.find((action) => action.type === 'function_email').config
+ const subject = emailConfig.inputs.email.value.subject
if (failPatches > 0) {
failPatches -= 1
return [500, { detail: 'Simulated outage' }]
}
patchedSubjects.push(subject)
+ patchedTracking.push(emailConfig.tracking_enabled)
onPatchStarted?.()
if (holdPatch) {
await holdPatch
@@ -188,16 +191,31 @@ describe('broadcastWizardLogic', () => {
expect(router.values.searchParams).toEqual({ step: 'content' })
})
- it('saves an email edit made while the draft is created before leaving /broadcasts/new', async () => {
+ it.each([
+ {
+ edit: 'an email edit',
+ apply: (): void =>
+ logic.actions.setEmail({ ...DEFAULT_BROADCAST_EMAIL, subject: 'Typed during the create' }),
+ subject: 'Typed during the create',
+ tracking: true,
+ },
+ {
+ edit: 'turning tracking off',
+ apply: (): void => logic.actions.setEmailSettings({ trackingEnabled: false }),
+ subject: '',
+ tracking: false,
+ },
+ ])('saves $edit made while the draft is created before leaving /broadcasts/new', async (testCase) => {
router.actions.push('/broadcasts/new')
logic.actions.setStep('content')
- logic.actions.setEmail({ ...DEFAULT_BROADCAST_EMAIL, subject: 'Typed during the create' })
+ testCase.apply()
releaseCreate()
await expectLogic(logic).toDispatchActions(['draftAutosaved', 'draftAutosaved'])
await expectLogic(logic).toDispatchActions(['showSavedDraftUrl']).toFinishAllListeners()
- expect(patchedSubjects).toEqual(['Typed during the create'])
+ expect(patchedSubjects).toEqual([testCase.subject])
+ expect(patchedTracking).toEqual([testCase.tracking])
expect(router.values.location.pathname).toContain('/broadcasts/broadcast-1')
})
diff --git a/products/workflows/frontend/Broadcasts/broadcastWizardLogic.ts b/products/workflows/frontend/Broadcasts/broadcastWizardLogic.ts
index d2047a436b55..d5944e849f72 100644
--- a/products/workflows/frontend/Broadcasts/broadcastWizardLogic.ts
+++ b/products/workflows/frontend/Broadcasts/broadcastWizardLogic.ts
@@ -113,6 +113,43 @@ export const DEFAULT_BROADCAST_EMAIL: BroadcastEmailValue = {
design: null,
}
+/** Settings on the email step that the email content itself does not carry. */
+export interface BroadcastEmailSettings {
+ /** The opt-out category. People who opted out of it are skipped. */
+ messageCategoryId: string | null
+ messageCategoryType: string | null
+ trackingEnabled: boolean
+}
+
+export const DEFAULT_BROADCAST_EMAIL_SETTINGS: BroadcastEmailSettings = {
+ messageCategoryId: null,
+ messageCategoryType: null,
+ trackingEnabled: true,
+}
+
+function readEmailSettings(broadcast: HogFlowApi): BroadcastEmailSettings | null {
+ const config = findAction(broadcast, 'function_email')?.config
+ if (!config) {
+ return null
+ }
+ return {
+ messageCategoryId: config.message_category_id ?? null,
+ messageCategoryType: config.message_category_type ?? null,
+ trackingEnabled: config.tracking_enabled !== false,
+ }
+}
+
+function emailSettingsConfig(settings: BroadcastEmailSettings | undefined): Record<string, any> {
+ if (!settings) {
+ return {}
+ }
+ return {
+ message_category_id: settings.messageCategoryId ?? undefined,
+ message_category_type: settings.messageCategoryType ?? undefined,
+ tracking_enabled: settings.trackingEnabled,
+ }
+}
+
export const DEFAULT_BROADCAST_CONVERSION: HogFlowConversionApi = {
events: [],
filters: [],
@@ -172,6 +209,7 @@ export interface broadcastWizardLogicValues {
effectiveTimezone: string
email: BroadcastEmailValue
emailRateLimit: HogFlowEmailSendingRateLimitApi | null
+ emailSettings: BroadcastEmailSettings
expandedRunIds: string[]
expandedRunOverride: string[] | null
firstInvalidStep: BroadcastWizardStep | null
@@ -332,6 +370,9 @@ export interface broadcastWizardLogicActions {
setEmailRateLimit: (emailRateLimit: HogFlowEmailSendingRateLimitApi | null) => {
emailRateLimit: HogFlowEmailSendingRateLimitApi | null
}
+ setEmailSettings: (settings: Partial<BroadcastEmailSettings>) => {
+ settings: Partial<BroadcastEmailSettings>
+ }
setExpandedRunOverride: (runIds: string[]) => {
runIds: string[]
}
@@ -395,7 +436,8 @@ export interface broadcastWizardLogicMeta {
goalEnabled: boolean,
conversion: HogFlowConversionApi,
email: BroadcastEmailValue,
- emailRateLimit: HogFlowEmailSendingRateLimitApi | null
+ emailRateLimit: HogFlowEmailSendingRateLimitApi | null,
+ emailSettings: BroadcastEmailSettings
) => HogFlowApi | null
broadcastId: (broadcast: HogFlowApi | null, id: string) => string | null
expandedRunIds: (expandedRunOverride: string[] | null, batchJobs: HogFlowBatchJobApi[]) => string[]
@@ -480,6 +522,7 @@ export const broadcastWizardLogic = kea<broadcastWizardLogicType>([
setGoalEnabled: (enabled: boolean) => ({ enabled }),
setConversion: (conversion: HogFlowConversionApi) => ({ conversion }),
setEmailRateLimit: (emailRateLimit: HogFlowEmailSendingRateLimitApi | null) => ({ emailRateLimit }),
+ setEmailSettings: (settings: Partial<BroadcastEmailSettings>) => ({ settings }),
setEmail: (email: BroadcastEmailValue) => ({ email }),
setScheduleMode: (mode: BroadcastScheduleMode) => ({ mode }),
setSendAt: (sendAt: string | null) => ({ sendAt }),
@@ -650,6 +693,17 @@ export const broadcastWizardLogic = kea<broadcastWizardLogicType>([
: state,
},
],
+ emailSettings: [
+ DEFAULT_BROADCAST_EMAIL_SETTINGS,
+ {
+ setEmailSettings: (state, { settings }) => ({ ...state, ...settings }),
+ hydrateFromBroadcast: (state, { broadcast }) => readEmailSettings(broadcast) ?? state,
+ applyExternalEdit: (state, { broadcast, base }) =>
+ changedElsewhere(broadcast, base, readEmailSettings)
+ ? (readEmailSettings(broadcast) ?? state)
+ : state,
+ },
+ ],
email: [
DEFAULT_BROADCAST_EMAIL,
{
@@ -769,7 +823,16 @@ export const broadcastWizardLogic = kea<broadcastWizardLogicType>([
selectors({
// The saved broadcast overlaid with the editor's unsaved state, in the shape the AI assistant reads.
broadcastAsWorkflow: [
- (s) => [s.broadcast, s.name, s.audienceProperties, s.goalEnabled, s.conversion, s.email, s.emailRateLimit],
+ (s) => [
+ s.broadcast,
+ s.name,
+ s.audienceProperties,
+ s.goalEnabled,
+ s.conversion,
+ s.email,
+ s.emailRateLimit,
+ s.emailSettings,
+ ],
(
broadcast: HogFlowApi | null,
name: string,
@@ -777,7 +840,8 @@ export const broadcastWizardLogic = kea<broadcastWizardLogicType>([
goalEnabled: boolean,
conversion: HogFlowConversionApi,
email: BroadcastEmailValue,
- emailRateLimit: HogFlowEmailSendingRateLimitApi | null
+ emailRateLimit: HogFlowEmailSendingRateLimitApi | null,
+ emailSettings: BroadcastEmailSettings
): HogFlowApi | null =>
broadcast
? ({
@@ -789,6 +853,7 @@ export const broadcastWizardLogic = kea<broadcastWizardLogicType>([
conversion,
email,
emailRateLimit,
+ emailSettings,
// A workflow shaped like a broadcast keeps its own step ids in the agent's view.
broadcast,
}),
@@ -1108,6 +1173,10 @@ export const broadcastWizardLogic = kea<broadcastWizardLogicType>([
router.actions.replace(urls.broadcast(values.broadcastId), { step: values.currentStep })
}
},
+ setEmailSettings: () => {
+ // Tracking and category live on the email step, so they share its autosave and pending flag.
+ actions.setEmail(values.email)
+ },
setEmail: async (_, breakpoint) => {
// Keeps the saved draft in step with the editor, so an AI edit starts from what the user
// sees rather than from the last Continue.
@@ -1695,6 +1764,7 @@ export function buildBroadcastPayload(values: {
conversion: HogFlowConversionApi
email: BroadcastEmailValue
emailRateLimit: HogFlowEmailSendingRateLimitApi | null
+ emailSettings?: BroadcastEmailSettings
broadcast?: HogFlowApi | null
}): Record<string, any> {
const existing = values.broadcast
@@ -1719,6 +1789,7 @@ export function buildBroadcastPayload(values: {
...action,
config: {
...action.config,
+ ...emailSettingsConfig(values.emailSettings),
inputs: {
...action.config?.inputs,
email: { ...action.config?.inputs?.email, value: values.email },
@@ -1759,6 +1830,7 @@ export function buildBroadcastPayload(values: {
updated_at: 0,
config: {
template_id: 'template-email',
+ ...emailSettingsConfig(values.emailSettings),
inputs: {
email: { value: values.email },
},
diff --git a/products/workflows/frontend/Broadcasts/broadcastWorkflowEdits.test.ts b/products/workflows/frontend/Broadcasts/broadcastWorkflowEdits.test.ts
index 239d3f7a4555..aa9f58cf8f5e 100644
--- a/products/workflows/frontend/Broadcasts/broadcastWorkflowEdits.test.ts
+++ b/products/workflows/frontend/Broadcasts/broadcastWorkflowEdits.test.ts
@@ -121,4 +121,27 @@ describe('broadcast edits to broadcast-shaped workflows', () => {
expect(payload.actions[1].config.inputs.extra).toEqual({ value: 1 })
expect(payload.actions[1].config.inputs.email.value.subject).toBe('New subject')
})
+
+ it.each([
+ ['a new broadcast', null],
+ ['a workflow shaped like a broadcast', { origin_product: null, actions: [trigger(), email(), exit], edges }],
+ ])('saves the message category and tracking onto the email step of %s', (_, existing) => {
+ const payload = buildBroadcastPayload({
+ name: 'Newsletter',
+ audienceProperties: [],
+ goalEnabled: false,
+ conversion: DEFAULT_BROADCAST_CONVERSION,
+ email: DEFAULT_BROADCAST_EMAIL,
+ emailRateLimit: null,
+ emailSettings: { messageCategoryId: 'cat-1', messageCategoryType: 'marketing', trackingEnabled: false },
+ broadcast: existing as unknown as HogFlowApi | null,
+ })
+
+ const emailStep = payload.actions.find((action: any) => action.type === 'function_email')
+ expect(emailStep.config).toMatchObject({
+ message_category_id: 'cat-1',
+ message_category_type: 'marketing',
+ tracking_enabled: false,
+ })
+ })
})
diff --git a/products/workflows/frontend/Broadcasts/steps/BroadcastContentStep.tsx b/products/workflows/frontend/Broadcasts/steps/BroadcastContentStep.tsx
index a9c457c40cac..7314539cb4d1 100644
--- a/products/workflows/frontend/Broadcasts/steps/BroadcastContentStep.tsx
+++ b/products/workflows/frontend/Broadcasts/steps/BroadcastContentStep.tsx
@@ -1,7 +1,7 @@
import { useActions, useValues } from 'kea'
import { useState } from 'react'
-import { LemonBanner, LemonButton } from '@posthog/lemon-ui'
+import { LemonBanner, LemonButton, LemonSwitch } from '@posthog/lemon-ui'
import { integrationsLogic } from 'lib/integrations/integrationsLogic'
import { EmailTemplater, TemplatePickerModal } from 'scenes/hog-functions/email-templater/EmailTemplater'
@@ -14,8 +14,8 @@ import { buildSampleGlobals } from '../../Workflows/hogflows/steps/components/Ho
import { BroadcastEmailValue, DEFAULT_BROADCAST_EMAIL, broadcastWizardLogic } from '../broadcastWizardLogic'
export function BroadcastContentStep(): JSX.Element {
- const { email, stepValidationErrors, selectedSender } = useValues(broadcastWizardLogic)
- const { setEmail } = useActions(broadcastWizardLogic)
+ const { email, stepValidationErrors, selectedSender, emailSettings } = useValues(broadcastWizardLogic)
+ const { setEmail, setEmailSettings } = useActions(broadcastWizardLogic)
const { integrations, integrationsLoading } = useValues(integrationsLogic)
const { loadIntegrations } = useActions(integrationsLogic)
const [templatePickerOpen, setTemplatePickerOpen] = useState(false)
@@ -100,6 +100,18 @@ export function BroadcastContentStep(): JSX.Element {
variables={buildSampleGlobals({ type: 'batch' }, null)}
fieldErrors={fieldErrors}
/>
+ <LemonSwitch
+ label="Track opens and link clicks"
+ checked={emailSettings.trackingEnabled}
+ onChange={(trackingEnabled) => setEmailSettings({ trackingEnabled })}
+ bordered
+ data-attr="broadcast-tracking-toggle"
+ />
+ {!emailSettings.trackingEnabled && (
+ <span className="text-xs text-secondary">
+ Links stay as written and no tracking pixel is added, so this broadcast shows no opens or clicks.
+ </span>
+ )}
</div>
)
}
diff --git a/products/workflows/frontend/Broadcasts/steps/BroadcastRecipientsStep.tsx b/products/workflows/frontend/Broadcasts/steps/BroadcastRecipientsStep.tsx
index 1893fec90ee5..4c1e48542c51 100644
--- a/products/workflows/frontend/Broadcasts/steps/BroadcastRecipientsStep.tsx
+++ b/products/workflows/frontend/Broadcasts/steps/BroadcastRecipientsStep.tsx
@@ -2,18 +2,20 @@ import { useActions, useValues } from 'kea'
import { useState } from 'react'
import { IconWarning } from '@posthog/icons'
-import { LemonButton, LemonModal, Spinner } from '@posthog/lemon-ui'
+import { LemonButton, LemonModal, LemonSelect, Link, 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 { urls } from 'scenes/urls'
import { DataTable } from '~/queries/nodes/DataTable/DataTable'
import { ActorsQuery, DataTableNode, NodeKind, ProductKey } from '~/queries/schema/schema-general'
import { AnyPersonScopeFilter, PropertyFilterType } from '~/types'
+import { optOutCategoriesLogic } from '../../OptOuts/optOutCategoriesLogic'
import { WORKFLOW_OPERATOR_ALLOWLIST } from '../../Workflows/hogflows/filters/HogFlowFilters'
import { BroadcastAudienceCohorts } from '../audience/BroadcastAudienceCohorts'
import { broadcastWizardLogic } from '../broadcastWizardLogic'
@@ -52,6 +54,50 @@ function AudienceSizePreview(): JSX.Element | null {
)
}
+function MessageCategoryPicker(): JSX.Element {
+ const { emailSettings } = useValues(broadcastWizardLogic)
+ const { setEmailSettings } = useActions(broadcastWizardLogic)
+ const { categories, categoriesLoading } = useValues(optOutCategoriesLogic())
+ const selected = categories.find((category) => category.id === emailSettings.messageCategoryId)
+
+ return (
+ <div className="flex flex-col gap-1 mt-4">
+ <span className="font-semibold">Message category</span>
+ <span className="text-secondary text-sm">
+ People who unsubscribed from this category don't get the email.{' '}
+ <Link to={urls.workflows('opt-outs')} target="_blank">
+ Manage categories
+ </Link>
+ </span>
+ <LemonSelect
+ className="max-w-100"
+ value={emailSettings.messageCategoryId}
+ loading={categoriesLoading}
+ onChange={(id) =>
+ setEmailSettings({
+ messageCategoryId: id,
+ messageCategoryType: categories.find((category) => category.id === id)?.category_type ?? null,
+ })
+ }
+ options={[
+ { value: null, label: 'No category' },
+ ...categories.map((category) => ({
+ value: category.id,
+ label: category.name,
+ labelInMenu: `${category.name} (${category.category_type})`,
+ })),
+ ]}
+ data-attr="broadcast-message-category"
+ />
+ {selected?.category_type === 'transactional' && (
+ <span className="text-xs text-warning">
+ Transactional emails go to everyone in the audience, including people who unsubscribed.
+ </span>
+ )}
+ </div>
+ )
+}
+
function AudienceListTable(): JSX.Element {
const { audienceProperties } = useValues(broadcastWizardLogic)
const [query, setQuery] = useState<DataTableNode>(() => ({
@@ -137,6 +183,7 @@ export function BroadcastRecipientsStep(): JSX.Element {
operatorAllowlist={WORKFLOW_OPERATOR_ALLOWLIST}
/>
<BroadcastAudienceCohorts />
+ <MessageCategoryPicker />
</div>
)
}
diff --git a/products/workflows/frontend/Broadcasts/steps/BroadcastReviewStep.tsx b/products/workflows/frontend/Broadcasts/steps/BroadcastReviewStep.tsx
index b76a8a7e1688..88bd90795e41 100644
--- a/products/workflows/frontend/Broadcasts/steps/BroadcastReviewStep.tsx
+++ b/products/workflows/frontend/Broadcasts/steps/BroadcastReviewStep.tsx
@@ -7,6 +7,7 @@ import PropertyFiltersDisplay from 'lib/components/PropertyFilters/components/Pr
import { integrationsLogic } from 'lib/integrations/integrationsLogic'
import { humanFriendlyNumber } from 'lib/utils/numbers'
+import { optOutCategoriesLogic } from '../../OptOuts/optOutCategoriesLogic'
import { BroadcastAudienceCohorts } from '../audience/BroadcastAudienceCohorts'
import { broadcastAudienceCohortsLogic } from '../audience/broadcastAudienceCohortsLogic'
import { BroadcastEmailPreview } from '../BroadcastEmailPreview'
@@ -68,7 +69,10 @@ export function BroadcastReviewStep(): JSX.Element {
emailRateLimit,
rateLimitedSendDuration,
stepValidationErrors,
+ emailSettings,
} = useValues(broadcastWizardLogic)
+ const { categories } = useValues(optOutCategoriesLogic())
+ const category = categories.find((item) => item.id === emailSettings.messageCategoryId)
const { props } = useMountedLogic(broadcastWizardLogic)
const { nonCohortAudience } = useValues(broadcastAudienceCohortsLogic(props))
const { integrationsLoading } = useValues(integrationsLogic)
@@ -118,6 +122,14 @@ export function BroadcastReviewStep(): JSX.Element {
) : (
<div className="text-muted text-xs">No filters. This broadcast goes to everyone.</div>
)}
+ {category && (
+ <div className="text-xs text-secondary">
+ Message category: {category.name}
+ {category.category_type === 'transactional'
+ ? '. Sent even to people who unsubscribed.'
+ : '. People who unsubscribed from it are skipped.'}
+ </div>
+ )}
</ReviewRow>
<ReviewRow label="Goal" step="goal">
@@ -133,6 +145,9 @@ export function BroadcastReviewStep(): JSX.Element {
</ReviewRow>
<ReviewRow label="Email" step="content">
+ {!emailSettings.trackingEnabled && (
+ <div className="text-xs text-secondary">Open and click tracking is off.</div>
+ )}
<BroadcastEmailPreview />
</ReviewRow>