: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): show push metrics in the workflow Metrics tab (#71078)
Daniel Marchuk4c82e593686c
diff --git a/products/workflows/frontend/Workflows/PushMetricsSummary.tsx b/products/workflows/frontend/Workflows/PushMetricsSummary.tsxnew file mode 100644index 000000000000..d8ac082c221a--- /dev/null+++ b/products/workflows/frontend/Workflows/PushMetricsSummary.tsx@@ -0,0 +1,57 @@+import { useValues } from 'kea'+import { useMemo } from 'react'++import { getColorVar } from 'lib/colors'+import { appMetricsLogic } from 'lib/components/AppMetrics/appMetricsLogic'+import { AppMetricsTrends } from 'lib/components/AppMetrics/AppMetricsTrends'+import { AppMetricSummary } from 'lib/components/AppMetrics/AppMetricSummary'++import { WORKFLOW_PUSH_METRICS } from './workflowMetricsSummaryLogic'++const PUSH_METRIC_KEYS = Object.keys(WORKFLOW_PUSH_METRICS) as (keyof typeof WORKFLOW_PUSH_METRICS)[]++export function PushMetricsSummary({ logicKey }: { logicKey: string }): JSX.Element {+ const { appMetricsTrendsLoading, appMetricsTrends, getSingleTrendSeries } = useValues(appMetricsLogic({ logicKey }))++ const pushTrends = useMemo(+ () =>+ appMetricsTrends+ ? {+ ...appMetricsTrends,+ series: appMetricsTrends.series+ .filter((series) => series.name in WORKFLOW_PUSH_METRICS)+ .map((series) => ({+ ...series,+ name:+ WORKFLOW_PUSH_METRICS[series.name as keyof typeof WORKFLOW_PUSH_METRICS]?.name ??+ series.name,+ color: WORKFLOW_PUSH_METRICS[series.name as keyof typeof WORKFLOW_PUSH_METRICS]?.color,+ })),+ }+ : null,+ [appMetricsTrends]+ )++ return (+ <>+ <div className="flex flex-row gap-2 flex-wrap justify-center">+ {PUSH_METRIC_KEYS.map((key) => {+ const metric = WORKFLOW_PUSH_METRICS[key]+ return (+ <AppMetricSummary+ key={key}+ name={metric.name}+ description={metric.description}+ loading={appMetricsTrendsLoading}+ timeSeries={getSingleTrendSeries(key)}+ previousPeriodTimeSeries={getSingleTrendSeries(key, true)}+ color={metric.color}+ colorIfZero={getColorVar('muted')}+ />+ )+ })}+ </div>+ <AppMetricsTrends appMetricsTrends={pushTrends} loading={appMetricsTrendsLoading} />+ </>+ )+}diff --git a/products/workflows/frontend/Workflows/WorkflowMetrics.tsx b/products/workflows/frontend/Workflows/WorkflowMetrics.tsxindex bb2047f123b4..33c312036c32 100644--- a/products/workflows/frontend/Workflows/WorkflowMetrics.tsx+++ b/products/workflows/frontend/Workflows/WorkflowMetrics.tsx@@ -20,6 +20,7 @@ import { batchWorkflowJobsLogic } from './batchWorkflowJobsLogic'import { EmailMetricsSummary } from './EmailMetricsSummary'import { getHogFlowStep } from './hogflows/steps/HogFlowSteps'import { HogFlowBatchJob } from './hogflows/types'+import { PushMetricsSummary } from './PushMetricsSummary'import { WorkflowLogicProps, workflowLogic } from './workflowLogic'import { WorkflowMetricsSummary } from './WorkflowMetricsSummary'import { type EmailMetric, buildEmailMetricLogSearchParams } from './workflowMetricsSummaryLogic'@@ -152,6 +153,8 @@ function WorkflowRunMetrics(props: WorkflowLogicProps): JSX.Element {/>) : selectedAction?.type === 'function_email' ? (<EmailMetricsSummary logicKey={logicKey} onMetricClick={onEmailMetricClick} />+ ) : selectedAction?.type === 'function_push' ? (+ <PushMetricsSummary logicKey={logicKey} />) : (<><div className="flex flex-row gap-2 flex-wrap justify-center">@@ -290,6 +293,8 @@ function BatchJobMetrics({ job }: { job: HogFlowBatchJob }): JSX.Element {/>) : selectedAction?.type === 'function_email' ? (<EmailMetricsSummary logicKey={logicKey} />+ ) : selectedAction?.type === 'function_push' ? (+ <PushMetricsSummary logicKey={logicKey} />) : (<><div className="flex flex-row gap-2 flex-wrap justify-center">diff --git a/products/workflows/frontend/Workflows/WorkflowMetricsSummary.tsx b/products/workflows/frontend/Workflows/WorkflowMetricsSummary.tsxindex 02a9a73bd8a9..472ed844d001 100644--- a/products/workflows/frontend/Workflows/WorkflowMetricsSummary.tsx+++ b/products/workflows/frontend/Workflows/WorkflowMetricsSummary.tsx@@ -12,6 +12,7 @@ import {type EmailMetric,WORKFLOW_SUMMARY_METRICS,type EmailMetricRow,+ type PushMetricRow,withDisplayName,workflowMetricsSummaryLogic,type WorkflowMetricsSummaryLogicProps,@@ -39,6 +40,8 @@ export function WorkflowMetricsSummary({workflowSummaryTrends,emailMetricsRows,emailTotalsByActionIdLoading,+ pushMetricsRows,+ pushTotalsByActionIdLoading,conversionRate,conversionStats,conversionStatsLoading,@@ -138,6 +141,46 @@ export function WorkflowMetricsSummary({[onSelectAction, onMetricClick])+ const pushMetricsColumns: LemonTableColumns<PushMetricRow> = useMemo(+ () => [+ {+ title: 'Push',+ dataIndex: 'push',+ key: 'push',+ render: (_, row) =>+ onSelectAction ? (+ <span className="cursor-pointer text-link" onClick={() => onSelectAction(row.id)}>+ {row.push}+ </span>+ ) : (+ row.push+ ),+ },+ {+ title: 'Sent',+ dataIndex: 'sent',+ key: 'sent',+ align: 'right',+ render: (_, row) => row.sent.toLocaleString(),+ },+ {+ title: 'Skipped',+ dataIndex: 'skipped',+ key: 'skipped',+ align: 'right',+ render: (_, row) => row.skipped.toLocaleString(),+ },+ {+ title: 'Failed',+ dataIndex: 'failed',+ key: 'failed',+ align: 'right',+ render: (_, row) => row.failed.toLocaleString(),+ },+ ],+ [onSelectAction]+ )+return (<><div className="flex flex-row gap-2 flex-wrap justify-center">@@ -231,6 +274,18 @@ export function WorkflowMetricsSummary({emptyState="No email actions in this workflow"/>+ {/* Push has no delivery/open/click receipts like email — only the three send-time outcomes. */}+ {pushMetricsRows.length > 0 && (+ <LemonTable+ columns={pushMetricsColumns}+ dataSource={pushMetricsRows}+ loading={pushTotalsByActionIdLoading}+ rowKey="id"+ size="small"+ emptyState="No push actions in this workflow"+ />+ )}+<AppMetricsTrends appMetricsTrends={workflowSummaryTrends} loading={loading} /></>)diff --git a/products/workflows/frontend/Workflows/hogflows/panel/HogFlowEditorPanelMetrics.tsx b/products/workflows/frontend/Workflows/hogflows/panel/HogFlowEditorPanelMetrics.tsxindex e555b440e1b3..08cbf10f2e9a 100644--- a/products/workflows/frontend/Workflows/hogflows/panel/HogFlowEditorPanelMetrics.tsx+++ b/products/workflows/frontend/Workflows/hogflows/panel/HogFlowEditorPanelMetrics.tsx@@ -14,7 +14,7 @@ import { urls } from 'scenes/urls'import { EXIT_NODE_ID, TRIGGER_NODE_ID } from '../../workflowLogic'import { WORKFLOW_METRICS_INFO } from '../../WorkflowMetrics'-import { WORKFLOW_EMAIL_METRICS } from '../../workflowMetricsSummaryLogic'+import { WORKFLOW_EMAIL_METRICS, WORKFLOW_PUSH_METRICS } from '../../workflowMetricsSummaryLogic'import { hogFlowEditorLogic } from '../hogFlowEditorLogic'export function HogFlowEditorPanelMetrics(): JSX.Element | null {@@ -31,6 +31,7 @@ export function HogFlowEditorPanelMetrics(): JSX.Element | null {const selectedAction = workflow.actions.find((action) => action.id === actionId)const isEmailAction = selectedAction?.type === 'function_email'+ const isPushAction = selectedAction?.type === 'function_push'const metricName = useMemo(() => {return actionId === TRIGGER_NODE_ID@@ -39,8 +40,10 @@ export function HogFlowEditorPanelMetrics(): JSX.Element | null {? ['succeeded', 'failed']: isEmailAction? (Object.keys(WORKFLOW_EMAIL_METRICS) as string[])- : undefined- }, [actionId, isEmailAction])+ : isPushAction+ ? (Object.keys(WORKFLOW_PUSH_METRICS) as string[])+ : undefined+ }, [actionId, isEmailAction, isPushAction])const logic = appMetricsLogic({logicKey,@@ -61,17 +64,16 @@ export function HogFlowEditorPanelMetrics(): JSX.Element | null {if (!appMetricsTrends) {return undefined}- const colorSource = (isEmailAction ? WORKFLOW_EMAIL_METRICS : WORKFLOW_METRICS_INFO) as Record<- string,- { name: string; color: string }- >+ const colorSource = (+ isEmailAction ? WORKFLOW_EMAIL_METRICS : isPushAction ? WORKFLOW_PUSH_METRICS : WORKFLOW_METRICS_INFO+ ) as Record<string, { name: string; color: string }>return Object.fromEntries(appMetricsTrends.series.map((x): [string, AppMetricsSeriesOverride] => [x.name,{ label: colorSource[x.name]?.name, color: colorSource[x.name]?.color },]))- }, [appMetricsTrends, isEmailAction])+ }, [appMetricsTrends, isEmailAction, isPushAction])useEffect(() => {if (!shouldShowActionLevelMetrics) {diff --git a/products/workflows/frontend/Workflows/hogflows/steps/types.ts b/products/workflows/frontend/Workflows/hogflows/steps/types.tsindex ec04a043db47..6dc270a0fa39 100644--- a/products/workflows/frontend/Workflows/hogflows/steps/types.ts+++ b/products/workflows/frontend/Workflows/hogflows/steps/types.ts@@ -328,6 +328,10 @@ export const isEmailAction = (action: HogFlowAction): action is Extract<HogFlowAreturn ['function_email'].includes(action.type)}+export const isPushAction = (action: HogFlowAction): action is Extract<HogFlowAction, { type: 'function_push' }> => {+ return ['function_push'].includes(action.type)+}+export const isFunctionAction = (action: HogFlowAction): action is Extract<HogFlowAction, { type: 'function' | 'function_sms' | 'function_email' | 'function_push' }> => {diff --git a/products/workflows/frontend/Workflows/workflowMetricsSummaryLogic.ts b/products/workflows/frontend/Workflows/workflowMetricsSummaryLogic.tsindex 82139e3eee96..334300d62fc7 100644--- a/products/workflows/frontend/Workflows/workflowMetricsSummaryLogic.ts+++ b/products/workflows/frontend/Workflows/workflowMetricsSummaryLogic.ts@@ -17,7 +17,7 @@ import { defaultDataTableColumns } from '~/queries/nodes/DataTable/utils'import { DataTableNode, EventsQuery, NodeKind } from '~/queries/schema/schema-general'import { ActivityTab, LogEntryLevel, PropertyFilterType, PropertyOperator } from '~/types'-import { isEmailAction } from './hogflows/steps/types'+import { isEmailAction, isPushAction } from './hogflows/steps/types'import { workflowLogic } from './workflowLogic'import type { workflowMetricsSummaryLogicType } from './workflowMetricsSummaryLogicType'@@ -43,6 +43,16 @@ export type EmailMetric =| 'email_blocked'| 'email_spam'+export type PushMetric = 'push_sent' | 'push_skipped' | 'push_failed'++export type PushMetricRow = {+ id: string+ push: string+ sent: number+ skipped: number+ failed: number+}+export type EmailMetricRow = {id: stringemail: string@@ -161,6 +171,36 @@ export const WORKFLOW_EMAIL_METRICS: Record<},}+// Push has no delivery-receipt channel like email's SES webhook (FCM/APNs respond synchronously), so+// these three send-time outcomes are all we can observe. "Sent" means the provider accepted the+// notification for delivery, not that the device displayed it.+export const WORKFLOW_PUSH_METRICS: Record<+ PushMetric,+ { name: string; description: string; color: string; metricNames: string[] }+> = {+ push_sent: {+ name: 'Sent',+ description:+ 'Total number of push notifications accepted by the provider (FCM or APNs) for delivery. The provider accepting a notification does not guarantee the device displayed it.',+ color: getColorVar('primary'),+ metricNames: ['push_sent'],+ },+ push_skipped: {+ name: 'Skipped',+ description:+ 'Total number of recipients skipped because they had no registered device token, or their token was reported dead by the provider (for example, the app was uninstalled) and removed.',+ color: getColorVar('warning'),+ metricNames: ['push_skipped'],+ },+ push_failed: {+ name: 'Failed',+ description:+ 'Total number of push notifications that could not be sent — for example invalid credentials, a rejected payload, or a provider outage after retries.',+ color: getColorVar('danger'),+ metricNames: ['push_failed'],+ },+}+// Email metrics whose SES events also write per-invocation log entries (see the SES webhook// handler). Clicking the tile drills into the Invocations tab filtered to those log entries.// The `search` term matches the start of the log message the handler emits (e.g. "Permanent@@ -211,6 +251,8 @@ const EMAIL_METRICS: EmailMetric[] = ['email_spam',]+const PUSH_METRICS: PushMetric[] = ['push_sent', 'push_skipped', 'push_failed']+export interface WorkflowMetricsSummaryLogicProps {logicKey: stringid: string@@ -277,6 +319,28 @@ export const workflowMetricsSummaryLogic = kea<workflowMetricsSummaryLogicType>(},},],+ pushTotalsByActionId: [+ {} as Record<string, Partial<Record<PushMetric, number>>>,+ {+ loadPushTotals: async (_, breakpoint) => {+ await breakpoint(10)+ const dateRange = values.getDateRangeAbsolute()+ const request: AppMetricsTotalsRequest = {+ appSource: values.params.appSource,+ appSourceId: values.params.appSourceId,+ breakdownBy: ['instance_id', 'metric_name'],+ metricName: [...PUSH_METRICS],+ dateFrom: dateRange.dateFrom.toISOString(),+ dateTo: dateRange.dateTo.toISOString(),+ }++ const totalsResponse = await loadAppMetricsTotals(request, values.currentTeam?.timezone ?? 'UTC')+ await breakpoint(10)++ return mapPushMetricsToActions(totalsResponse)+ },+ },+ ],conversionStats: [{ conversions: 0, started: 0 } as {conversions: number@@ -350,6 +414,8 @@ export const workflowMetricsSummaryLogic = kea<workflowMetricsSummaryLogicType>(emailActions: [(s) => [s.workflow], (workflow) => workflow.actions.filter(isEmailAction)],+ pushActions: [(s) => [s.workflow], (workflow) => workflow.actions.filter(isPushAction)],+metricNameBySummaryMetric: [(s) => [s.appMetricsTrends],(appMetricsTrends): Record<WorkflowSummaryMetric, string> =>@@ -488,10 +554,26 @@ export const workflowMetricsSummaryLogic = kea<workflowMetricsSummaryLogicType>(}}),],++ pushMetricsRows: [+ (s) => [s.pushActions, s.pushTotalsByActionId],+ (pushActions, pushTotalsByActionId): PushMetricRow[] =>+ pushActions.map((action: { id: string; name: string }) => {+ const totals = pushTotalsByActionId[action.id] || {}+ return {+ id: action.id,+ push: action.name,+ sent: totals.push_sent ?? 0,+ skipped: totals.push_skipped ?? 0,+ failed: totals.push_failed ?? 0,+ }+ }),+ ],}),afterMount(({ actions }) => {actions.loadEmailTotals({})+ actions.loadPushTotals({})actions.loadInProgressTotal({})actions.loadConversionStats({})}),@@ -508,6 +590,7 @@ export const workflowMetricsSummaryLogic = kea<workflowMetricsSummaryLogicType>(dateTo: values.params.dateTo,})actions.loadEmailTotals({})+ actions.loadPushTotals({})actions.loadConversionStats({})},})),@@ -581,3 +664,25 @@ function mapEmailMetricsToActions(function isEmailMetric(metricName: string): metricName is EmailMetric {return EMAIL_METRICS.includes(metricName as EmailMetric)}++function mapPushMetricsToActions(+ totalsResponse: AppMetricsTotalsResponse+): Record<string, Partial<Record<PushMetric, number>>> {+ const result: Record<string, Partial<Record<PushMetric, number>>> = {}++ Object.values(totalsResponse).forEach(({ total, breakdowns }) => {+ const [instanceId, metricName] = breakdowns+ if (!instanceId || !isPushMetric(metricName)) {+ return+ }++ result[instanceId] = result[instanceId] || {}+ result[instanceId][metricName] = total+ })++ return result+}++function isPushMetric(metricName: string): metricName is PushMetric {+ return PUSH_METRICS.includes(metricName as PushMetric)+}