: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(workflows): read email engagement against tracked sends (#74191)
Harley Alexanderc4d6ed4d3813
diff --git a/frontend/snapshots.yml b/frontend/snapshots.ymlindex 91e95fddc3c8..87d65d150766 100644--- a/frontend/snapshots.yml+++ b/frontend/snapshots.yml@@ -5383,9 +5383,9 @@ snapshots:scenes-app-customer-analytics-accounts--row-expanded-with-note--light:hash: v1.k794b7964.d8bf466f479ff1d959eb4bcc623791a9bb5d0679bb4603551330a41b195d21ca.OrdGvoj-FidEK77CCv6wrGfEKYjLduhFHA9Zft14W3Iscenes-app-customer-analytics-dashboard--b-2-b-mode-with-groups-enabled--dark:- hash: v1.k794b7964.828fae9c91deb58c84ba0d76bf0824931870cb75f43a3d9b723d7cd9fbf7be83.0kVC0j8iyaF1TD_NlHvk9_g_9GZy-jQzLWt4wQOkf48+ hash: v1.k794b7964.cf03f6a65f846aec287042028193b834c567f01226d2e91f6389df5af935530d.bXzRv9MkU0nXN-4tvGbenagVaJuhFr86goke8HVYFJYscenes-app-customer-analytics-dashboard--b-2-b-mode-with-groups-enabled--light:- hash: v1.k794b7964.ff25e11868464e00df352180254dbe0a1017cd1d8c7c4f4c7d6995068e80e2dc.Qos7ay_QrM7AHm70rH92TSqCZK0E7xHFg-ojDFhyktg+ hash: v1.k794b7964.4ee0185302dbca8e82bf55b9ce41d3fbbd357be595f39e1601be9714a46df5b6.4tdIruQOTdOTFWzHYxNCfm24rxaY9YscJG-pT2fk12wscenes-app-customer-analytics-dashboard--b-2-b-mode-without-groups--dark:hash: v1.k794b7964.fba00c329afe3f32d762b5ca68fd34ec029f644f5b0e9e1122589fa00bf39147.ZgZqcfIjl8qUUZ2865YzQ12RBt0Om97q2dsg9dxUYDYscenes-app-customer-analytics-dashboard--b-2-b-mode-without-groups--light:diff --git a/nodejs/src/cdp/services/messaging/email.service.test.ts b/nodejs/src/cdp/services/messaging/email.service.test.tsindex c00e32cd1787..9c98f39cbca6 100644--- a/nodejs/src/cdp/services/messaging/email.service.test.ts+++ b/nodejs/src/cdp/services/messaging/email.service.test.ts@@ -725,6 +725,17 @@ describe('EmailService', () => {const testSend = await service.executeSendEmail(invocation, true)expect(testSend.metrics).toEqual([])})++ it('marks the captured send event as untracked so customer-built engagement rates can exclude it', async () => {+ jest.spyOn(+ (service as any).teamWorkflowsConfigService,+ 'shouldCaptureEngagementEvents'+ ).mockResolvedValue(true)+ const result = await service.executeSendEmail(invocation)+ expect(result.capturedPostHogEvents[0].properties).toMatchObject({+ $email_tracking_enabled: false,+ })+ })})describe('recipient tracking consent', () => {@@ -879,6 +890,7 @@ describe('EmailService', () => {$workflow_action_id: invocation.state.actionId,$email_to: '[email protected]',$email_subject: 'Test Subject',+ $email_tracking_enabled: true,},})})diff --git a/nodejs/src/cdp/services/messaging/email.service.ts b/nodejs/src/cdp/services/messaging/email.service.tsindex 0dc2a64a43d6..3fbc1ec5d44d 100644--- a/nodejs/src/cdp/services/messaging/email.service.ts+++ b/nodejs/src/cdp/services/messaging/email.service.ts@@ -317,6 +317,11 @@ export class EmailService {$workflow_action_id: invocation.state.actionId,$email_to: params.to.email,$email_subject: params.subject,+ // Always set, never conditional: an untracked send can never produce a+ // `$workflows_email_opened` or `$workflows_email_link_clicked`, so without this+ // dimension on the send there is no way to build an open rate in an insight that+ // isn't deflated by however much of the audience declined tracking.+ $email_tracking_enabled: trackingEnabled,},})}diff --git a/products/workflows/frontend/Workflows/WorkflowMetricsSummary.tsx b/products/workflows/frontend/Workflows/WorkflowMetricsSummary.tsxindex 3529691ea625..ec14695ffeb7 100644--- a/products/workflows/frontend/Workflows/WorkflowMetricsSummary.tsx+++ b/products/workflows/frontend/Workflows/WorkflowMetricsSummary.tsx@@ -21,6 +21,23 @@ import {type WorkflowMetricsSummaryLogicProps,} from './workflowMetricsSummaryLogic'+const TRACKED_SENDS_TOOLTIP =+ 'Untracked sends can never record opens or clicks, so engagement is shown against tracked sends (sent minus untracked).'++// Opens and clicks are only possible on tracked sends, so pair the raw count with the denominator it+// should be read against. A step that tracked every send shows the count alone, because its Sent+// column is already the right denominator.+function trackedEngagementColumn(value: number, row: EmailMetricRow): JSX.Element {+ return (+ <span>+ {value.toLocaleString()}+ {row.untracked > 0 && (+ <span className="text-muted"> of {row.trackedSends.toLocaleString()} tracked sends</span>+ )}+ </span>+ )+}+interface WorkflowMetricsSummaryProps extends WorkflowMetricsSummaryLogicProps {onSelectAction?: (actionId: string) => void/** Drill a per-email metric into its filtered logs (only bounced/blocked have a log filter). */@@ -84,35 +101,15 @@ export function WorkflowMetricsSummary({title: 'Opened',key: 'opened',align: 'right',- tooltip:- 'Untracked sends can never record opens or clicks, so opens are shown against tracked deliveries (delivered minus untracked).',- render: (_, row) => (- <span>- {row.opened.toLocaleString()}- {row.untracked > 0 && row.delivered - row.untracked > 0 && (- <span className="text-muted">- {' '}- of {(row.delivered - row.untracked).toLocaleString()} tracked- </span>- )}- </span>- ),+ tooltip: TRACKED_SENDS_TOOLTIP,+ render: (_, row) => trackedEngagementColumn(row.opened, row),},{title: 'Clicked',key: 'clicked',align: 'right',- render: (_, row) => (- <span>- {row.linkClicked.toLocaleString()}- {row.untracked > 0 && row.delivered - row.untracked > 0 && (- <span className="text-muted">- {' '}- of {(row.delivered - row.untracked).toLocaleString()} tracked- </span>- )}- </span>- ),+ tooltip: TRACKED_SENDS_TOOLTIP,+ render: (_, row) => trackedEngagementColumn(row.linkClicked, row),},{title: 'Issues',diff --git a/products/workflows/frontend/Workflows/workflowMetricsSummaryLogic.test.ts b/products/workflows/frontend/Workflows/workflowMetricsSummaryLogic.test.tsindex ae2686082a0a..b5142873de4e 100644--- a/products/workflows/frontend/Workflows/workflowMetricsSummaryLogic.test.ts+++ b/products/workflows/frontend/Workflows/workflowMetricsSummaryLogic.test.ts@@ -177,10 +177,18 @@ describe('buildEmailMetricRows', () => {bouncePrevented: 2,blocked: 4,untracked: 7,+ trackedSends: 93,},])})+ it('keeps tracked sends positive when untracked sends outnumber deliveries', () => {+ const [row] = buildEmailMetricRows([{ id: 'a1', name: 'E' }], {+ a1: { email_sent: 100, email_delivered: 60, email_untracked: 90, email_bounced: 40 },+ })+ expect(row.trackedSends).toBe(10)+ })+// delivered falls back to sent - bounced - blocked (clamped at 0) when it wasn't collected.it.each<{ totals: Partial<Record<EmailMetric, number>>; delivered: number }>([{ totals: { email_sent: 10, email_bounced: 3, email_blocked: 2 }, delivered: 5 },diff --git a/products/workflows/frontend/Workflows/workflowMetricsSummaryLogic.ts b/products/workflows/frontend/Workflows/workflowMetricsSummaryLogic.tsindex 3cefeb4464f5..1d84e824e877 100644--- a/products/workflows/frontend/Workflows/workflowMetricsSummaryLogic.ts+++ b/products/workflows/frontend/Workflows/workflowMetricsSummaryLogic.ts@@ -69,8 +69,14 @@ export type EmailMetricRow = {bouncePrevented: numberblocked: number// Sends without open/click tracking (step toggle off or no recipient consent). These can never- // record opens/clicks, so engagement reads against (delivered - untracked).+ // record opens/clicks, so engagement reads against trackedSends rather than sent.untracked: number+ // Tracked sends, not tracked deliveries. `email_untracked` and `email_sent` are pushed together on+ // the same keys at send time, so the subtraction is exact and can never go negative, whereas+ // `delivered - untracked` mixes send-time and webhook-time counts and goes non-positive once an+ // untracked audience starts bouncing. A true tracked-deliveries denominator would need an untracked+ // counter emitted at delivery time in the SES webhook, keyed off `mail.tags['ses:configuration-set']`.+ trackedSends: number}// Single source of truth for metric colors across the workflow metric views. Keyed by the metric's@@ -182,13 +188,14 @@ export const WORKFLOW_EMAIL_METRICS: Record<email_opened: {name: 'Opened',description:- 'Total number of emails opened. Untracked sends can never record an open, so compare opens against delivered minus untracked.',+ 'Total number of emails opened. Untracked sends can never record an open, so compare opens against sent minus untracked.',color: METRIC_COLORS['Opened'],metricNames: ['email_opened'],},email_link_clicked: {name: 'Link clicked',- description: 'Total number of times links in emails were clicked',+ description:+ 'Total number of times links in emails were clicked. Untracked sends can never record a click, so compare clicks against sent minus untracked.',color: METRIC_COLORS['Link clicked'],metricNames: ['email_link_clicked'],},@@ -220,7 +227,7 @@ export const WORKFLOW_EMAIL_METRICS: Record<email_untracked: {name: 'Untracked',description:- 'Total number of emails sent without open/click tracking, because tracking was turned off on the step or the recipient has not consented. These sends can never record opens or clicks, so exclude them when judging engagement.',+ 'Total number of emails sent without open/click tracking, because tracking was turned off on the step or the recipient has not consented. These sends can never record opens or clicks, so subtract them from sent when judging engagement.',color: METRIC_COLORS['Untracked'],metricNames: ['email_untracked'],},@@ -1326,6 +1333,7 @@ export function buildEmailMetricRows(const sent = totals.email_sent ?? 0const bounced = totals.email_bounced ?? 0const blocked = totals.email_blocked ?? 0+ const untracked = totals.email_untracked ?? 0return {id: action.id,email: action.name,@@ -1337,7 +1345,8 @@ export function buildEmailMetricRows(bounced,bouncePrevented: totals.email_bounce_prevented ?? 0,blocked,- untracked: totals.email_untracked ?? 0,+ untracked,+ trackedSends: Math.max(0, sent - untracked),}})}diff --git a/products/workflows/mcp/tools.yaml b/products/workflows/mcp/tools.yamlindex 1aa2dec295a0..8a853500b068 100644--- a/products/workflows/mcp/tools.yaml+++ b/products/workflows/mcp/tools.yaml@@ -379,7 +379,9 @@ tools:Execution stats for a single workflow by ID: time-series success/failure counts over a configurable interval(hour, day, or week). Use to inspect one workflow's health — failure spikes and reliability trends. For anat-a-glance view across ALL workflows, call workflows-global-stats first, then drill in here. Supports- breakdown by metric kind (success/failure) or name, and time range filtering.+ breakdown by metric kind (success/failure) or name, and time range filtering. For email engagement, read+ email_opened and email_link_clicked against (email_sent - email_untracked): email_untracked counts sends+ with open/click tracking off, which can never register an open or a click.workflows-test-run:operation: hog_flows_invocations_createenabled: truediff --git a/services/mcp/schema/generated-tool-definitions.json b/services/mcp/schema/generated-tool-definitions.jsonindex 0b04bd5b9d8d..fa1d329bf933 100644--- a/services/mcp/schema/generated-tool-definitions.json+++ b/services/mcp/schema/generated-tool-definitions.json@@ -10329,7 +10329,7 @@}},"workflows-stats": {- "description": "Execution stats for a single workflow by ID: time-series success/failure counts over a configurable interval (hour, day, or week). Use to inspect one workflow's health — failure spikes and reliability trends. For an at-a-glance view across ALL workflows, call workflows-global-stats first, then drill in here. Supports breakdown by metric kind (success/failure) or name, and time range filtering.",+ "description": "Execution stats for a single workflow by ID: time-series success/failure counts over a configurable interval (hour, day, or week). Use to inspect one workflow's health — failure spikes and reliability trends. For an at-a-glance view across ALL workflows, call workflows-global-stats first, then drill in here. Supports breakdown by metric kind (success/failure) or name, and time range filtering. For email engagement, read email_opened and email_link_clicked against (email_sent - email_untracked): email_untracked counts sends with open/click tracking off, which can never register an open or a click.","category": "Workflows","feature": "workflows","summary": "Get workflow stats",diff --git a/services/mcp/schema/tool-definitions-all.json b/services/mcp/schema/tool-definitions-all.jsonindex 1a8fce2e6a6a..f1606dda8e5a 100644--- a/services/mcp/schema/tool-definitions-all.json+++ b/services/mcp/schema/tool-definitions-all.json@@ -10978,7 +10978,7 @@}},"workflows-stats": {- "description": "Execution stats for a single workflow by ID: time-series success/failure counts over a configurable interval (hour, day, or week). Use to inspect one workflow's health — failure spikes and reliability trends. For an at-a-glance view across ALL workflows, call workflows-global-stats first, then drill in here. Supports breakdown by metric kind (success/failure) or name, and time range filtering.",+ "description": "Execution stats for a single workflow by ID: time-series success/failure counts over a configurable interval (hour, day, or week). Use to inspect one workflow's health — failure spikes and reliability trends. For an at-a-glance view across ALL workflows, call workflows-global-stats first, then drill in here. Supports breakdown by metric kind (success/failure) or name, and time range filtering. For email engagement, read email_opened and email_link_clicked against (email_sent - email_untracked): email_untracked counts sends with open/click tracking off, which can never register an open or a click.","category": "Workflows","feature": "workflows","summary": "Get workflow stats",