: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 share of sent on email metric cards (#77883)
Sean Mallia927233fa833c
diff --git a/products/workflows/frontend/Workflows/EmailMetricsSummary.tsx b/products/workflows/frontend/Workflows/EmailMetricsSummary.tsxindex a8a9ed3ea6a5..e5de8943b807 100644--- a/products/workflows/frontend/Workflows/EmailMetricsSummary.tsx+++ b/products/workflows/frontend/Workflows/EmailMetricsSummary.tsx@@ -2,8 +2,9 @@ import { useValues } from 'kea'import { useMemo } from 'react'import { getColorVar } from 'lib/colors'-import { appMetricsLogic } from 'lib/components/AppMetrics/appMetricsLogic'+import { AppMetricsTimeSeriesResponse, appMetricsLogic } from 'lib/components/AppMetrics/appMetricsLogic'import { AppMetricsTrends } from 'lib/components/AppMetrics/AppMetricsTrends'+import { percentage } from 'lib/utils/numbers'import { WorkflowMetricCard } from './WorkflowMetricCard'import {@@ -15,6 +16,13 @@ import {const EMAIL_METRIC_KEYS = Object.keys(WORKFLOW_EMAIL_METRICS) as (keyof typeof WORKFLOW_EMAIL_METRICS)[]+function sumTimeSeries(timeSeries: AppMetricsTimeSeriesResponse | null): number {+ if (!timeSeries) {+ return 0+ }+ return timeSeries.series.reduce((acc, curr) => acc + curr.values.reduce((acc, curr) => acc + curr, 0), 0)+}+export function EmailMetricsSummary({logicKey,onMetricClick,@@ -42,12 +50,18 @@ export function EmailMetricsSummary({[appMetricsTrends])+ const sentTotal = sumTimeSeries(getSingleTrendSeries('email_sent'))+return (<><div className="flex flex-row gap-2 flex-wrap justify-center">{EMAIL_METRIC_KEYS.map((key) => {const metric = WORKFLOW_EMAIL_METRICS[key]const canDrillDown = !!onMetricClick && !!EMAIL_METRIC_INVOCATION_FILTERS[key]+ const shareOfSent =+ key !== 'email_sent' && sentTotal > 0+ ? percentage(sumTimeSeries(getSingleTrendSeries(key)) / sentTotal, 1)+ : nullreturn (<WorkflowMetricCardkey={key}@@ -60,6 +74,7 @@ export function EmailMetricsSummary({colorIfZero={getColorVar('muted')}onClick={canDrillDown ? () => onMetricClick(key) : undefined}onClickTooltip={`View invocations with a ${metric.name.toLowerCase()} log entry in this timeframe`}+ footer={shareOfSent ? <span>{shareOfSent} of sent</span> : null}/>)})}