: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(marketing): align ad performance metric cards (#120332)
Javier Bahamondes681beb41236b
diff --git a/docs/internal/marketing-source-suggestions.md b/docs/internal/marketing-source-suggestions.mdindex ceca968e3c41..313002bba4d9 100644--- a/docs/internal/marketing-source-suggestions.md+++ b/docs/internal/marketing-source-suggestions.md@@ -296,3 +296,8 @@ The panel includes the source validation details shown by the status banner.When the panel displays a connection, its duplicate status banner entry is hidden.Configuration validation failures and issues for sources outside the panel remain in the banner.With source onboarding disabled, the existing banner remains available.++## Ad performance metric cards++The Ad performance summary uses the same metric cards as Web analytics.+Cards preserve period comparisons, currency formatting, and missing-value labels, and wrap to the available scene width.diff --git a/frontend/snapshots.yml b/frontend/snapshots.ymlindex 956b0104f35b..c8248ecaf68c 100644--- a/frontend/snapshots.yml+++ b/frontend/snapshots.yml@@ -13055,9 +13055,9 @@ snapshots:scenes-app-marketing-analytics-search-performance--wrapped-landing-pages-narrow--light:hash: v1.k794b7964.bc7e930ff65d3898a309bf63b7dedafb78c498d14e2ddbce421ce701b4114b19.4vEUxz-8PhpNNO7we_L1k3W-USCIj0sfcsCjdEL3Um4scenes-app-marketing-analytics-source-onboarding--ad-performance-data-available--dark:- hash: v1.k794b7964.a355e41b0b22fbe8666816826da7ad43ee8fa1fe2efd6700acef9f600ba40e3d.ZCelp-RgcMQ01Nk0pmcGmXjIADayOpLOPsT0BUSYhN0+ hash: v1.k794b7964.8e7b5a5e0a0ea5c4b51e2b2de1ebb19b6ee9762442a2f80d50c5c11af7cb41c0.dmy1asCAzzn280lIIWPJvtDeGwXCTFYU5uwBXm1Qeh8scenes-app-marketing-analytics-source-onboarding--ad-performance-data-available--light:- hash: v1.k794b7964.eb6bb588841b14b122a9c857361281e602670499f30abf5dcdd724f8c06a6f28.qL-SA4MnJl0U4nGzt_JbKjzHg0YZ3j1BEjc2cOc40w4+ hash: v1.k794b7964.6bef64a6d0e91622b0d11695fec4f71b01da8419f4a3109f71dd3a37258e3e61.ox4QhyCUW4hnC6Vc2tvLKNaV8rXni64SX-zmOdeLiwEscenes-app-marketing-analytics-source-onboarding--ad-performance-with-detected-sources--dark:hash: v1.k794b7964.86e93f2243024c677ca7b0a2ba4e18e8bb164e1f172ecbd43f92f2a5359f0b9c.j492cCtgKRxf5KtvFw8hCZ_PSqqJeS_uLhwoq91xpScscenes-app-marketing-analytics-source-onboarding--ad-performance-with-detected-sources--light:@@ -13087,13 +13087,13 @@ snapshots:scenes-app-marketing-analytics-source-onboarding--dashboard-scanning-with-search-console--light:hash: v1.k794b7964.96925f009594f797806c47cbc799946341b4e4800844baacef5f8951ad434cf9.P_bQfBSfYVpIeEPw6WGMqzloDECX40vH57tb3fvuPxMscenes-app-marketing-analytics-source-onboarding--dashboard-with-ads-and-search-console--dark:- hash: v1.k794b7964.a0642b0e26c96bd1247929c4670e913696367430827ab04f523d7da4cc60f36e.aIAKakQ_E2M2e4cViTe0ouSofNbMi9XAAbT-XKPmmDk+ hash: v1.k794b7964.47b1850977208b98c470e7f154f58de2abb7e29e7361ac377fa8a97b97aa457f.Xm_oYIE0TxXRbMVnTBal6KpOIpt3sEKKnqC3aaFrczYscenes-app-marketing-analytics-source-onboarding--dashboard-with-ads-and-search-console--light:- hash: v1.k794b7964.8850628ae6309426f8c37c8ffbf219cecefad159da78d95cf071c7c1f9b9001c.zEkynyu9GCcp_CkXzIVLr_1XyFdG6eg2rzW-PGq41p8+ hash: v1.k794b7964.e9528a39aecc7609eda45c52c082ed365bd0d01b104c53f57dbebf15eefe3a65.fKwEvw-_Vb5DT4Q2Umg6nt8C2-QcaqJFt4-UvzoIn54scenes-app-marketing-analytics-source-onboarding--dashboard-with-ads-only--dark:- hash: v1.k794b7964.01189258e622b9a7ef56b63b600af3b731b5bd85fb524583d76379560ba4c8a8.KwpTbY3Gyk08dxmZJwOd88FLONyv2EWxtN87wHh2bsI+ hash: v1.k794b7964.38254c72b3d34460b427657ab1a323d0c126f47481faafd5d3e3c2e754ec0b08.LVei2svqlTFhMY1GTRCUXAHi7VJzjATpvGMDwig7Amkscenes-app-marketing-analytics-source-onboarding--dashboard-with-ads-only--light:- hash: v1.k794b7964.a35719d163748f2340f3c78c7c51586d4ad9d06d0a647ab6e40fe140723657b3.g5VthHH34aRvYlqcBJzbTYYCovEmm7bxvV2OWnQsUO8+ hash: v1.k794b7964.14376a3211c2e9d502f090404ee8bb3d8b2f12faa11fd8a74aab63c5a85a40c7.Or5G3_1QBdlt08fORsuLGYWV0C65cBFrZXZh4pZ9b60scenes-app-marketing-analytics-source-onboarding--dashboard-with-ads-syncing-without-search-console--dark:hash: v1.k794b7964.bfa13529bdb940ef1cd344b2bf11c58522804280d0e0dd141008411660a53505.ApfEsWw3lxynpDaRYL_pRTblq_-Yucp5d6hwOFDmY9kscenes-app-marketing-analytics-source-onboarding--dashboard-with-ads-syncing-without-search-console--light:@@ -16374,6 +16374,14 @@ snapshots:hash: v1.k794b7964.83d29ddaa67d14337789881b7bf81a197f55860fb090a4a720642639bc12fa1a.a2wl_GXLua_s1sEa95lvieBxxe2CrDqxHugdIYS58QAweb-analytics-marketing-cross-sell--source--light:hash: v1.k794b7964.d0c0ba256c4baded9b011f6e4fcf2f14025c0f1c51cfa0c7f62b0591b0748c1c.b0FfB_mnvTqcB8OQLrMy2rD_viTA0RhT4uFrpRpILK4+ web-analytics-overview-metric-cards--ad-performance-metrics--dark:+ hash: v1.k794b7964.840ca84431a03193f433eafccf543fddc70a7e33a59ce60f6b89c0a7e2a0f881.XLCY7rPj48eSRAfkkbBX4PQWsD1sacn3_2ycBMCPnCg+ web-analytics-overview-metric-cards--ad-performance-metrics--light:+ hash: v1.k794b7964.3cee01659450f7502fdc053279cfafe86bf68083ecd440995e2bdd37c1cc7352.mpWixUhMB-LLYnHbnDsXjcGKy6u0nRRRtifV-P5Wr_Y+ web-analytics-overview-metric-cards--ad-performance-metrics-narrow--dark:+ hash: v1.k794b7964.7b591b20f2a7499b29d890f5ef50cbb870a1de30c8c6e30c80bc9df2c5a71870.h4nlt0EpWBa04emEg78p1-cw-Q5R-3OLMWj5yLeYgRo+ web-analytics-overview-metric-cards--ad-performance-metrics-narrow--light:+ hash: v1.k794b7964.e3294bf375e3655d47dfeeb550cb41e3b8f395d22cf00d9ff3eaeaaf4b05f806.dL4eEzNxzw_unmbv8PRGOVJTzkF1PduJsz_WKeMPEdgweb-analytics-overview-metric-cards--conversion-goal--dark:hash: v1.k794b7964.0a6a29eef1c3d6ef3a287b530d4bdd7dbcc8cfbf503d54e02bfb5ab96473b6c3.-DSdM2UYxNQisb23WDltH1M71pRcQt2-_YiAhigLzIwweb-analytics-overview-metric-cards--conversion-goal--light:diff --git a/frontend/src/queries/nodes/OverviewGrid/OverviewGrid.tsx b/frontend/src/queries/nodes/OverviewGrid/OverviewGrid.tsxindex 2458cd7b597a..2f13e84b45b3 100644--- a/frontend/src/queries/nodes/OverviewGrid/OverviewGrid.tsx+++ b/frontend/src/queries/nodes/OverviewGrid/OverviewGrid.tsx@@ -21,15 +21,10 @@ import { WebAnalyticsItemKind, WebAnalyticsPreComputeStrategy } from '~/queries/export const NO_BASELINE_CHANGE_SENTINEL = 999999-const OVERVIEW_ITEM_CELL_MIN_WIDTH_REMS_COMPACT = 6const OVERVIEW_ITEM_CELL_MIN_WIDTH_REMS_DEFAULT = 10-// Default classes for non-compact modeconst OVERVIEW_ITEM_CELL_CLASSES_DEFAULT = `flex-1 border p-2 bg-surface-primary rounded min-w-[10rem] h-30 flex flex-col items-center text-center justify-between`-// Compact classes for marketing analytics-const OVERVIEW_ITEM_CELL_CLASSES_COMPACT = `flex-1 border p-1 bg-surface-primary rounded min-w-[6rem] h-24 flex flex-col items-center text-center justify-between`-export interface OverviewItem {key: stringvalue: number | string | undefined@@ -61,7 +56,6 @@ interface OverviewGridProps {onDisablePrecompute?: () => voidlabelFromKey: (key: string) => stringfilterEmptyItems?: (item: OverviewItem) => boolean- compact?: boolean}export function OverviewGrid({@@ -73,23 +67,17 @@ export function OverviewGrid({onDisablePrecompute,labelFromKey,filterEmptyItems = () => true,- compact = false,}: OverviewGridProps): JSX.Element {const filteredItems = items.filter(filterEmptyItems)return (<><EvenlyDistributedRows- className={`flex justify-center items-center flex-wrap w-full ${compact ? 'gap-1' : 'gap-2'}`}- minWidthRems={- compact- ? OVERVIEW_ITEM_CELL_MIN_WIDTH_REMS_COMPACT + 1- : OVERVIEW_ITEM_CELL_MIN_WIDTH_REMS_DEFAULT + 2- }- maxItemsPerRow={compact ? 10 : undefined}+ className="flex justify-center items-center flex-wrap w-full gap-2"+ minWidthRems={OVERVIEW_ITEM_CELL_MIN_WIDTH_REMS_DEFAULT + 2}>{loading- ? range(numSkeletons).map((i) => <OverviewItemCellSkeleton key={i} compact={compact} />)+ ? range(numSkeletons).map((i) => <OverviewItemCellSkeleton key={i} />): filteredItems.map((item) => (<OverviewItemCellkey={item.key}@@ -97,7 +85,6 @@ export function OverviewGrid({preComputeStrategy={preComputeStrategy}onDisablePrecompute={onDisablePrecompute}labelFromKey={labelFromKey}- compact={compact}/>))}</EvenlyDistributedRows>@@ -119,16 +106,15 @@ export function SamplingNotice({ samplingRate }: { samplingRate?: SamplingRate })}-const OverviewItemCellSkeleton = ({ compact }: { compact: boolean }): JSX.Element => {- const cellClasses = compact ? OVERVIEW_ITEM_CELL_CLASSES_COMPACT : OVERVIEW_ITEM_CELL_CLASSES_DEFAULT+const OverviewItemCellSkeleton = (): JSX.Element => {return (- <div className={cellClasses}>+ <div className={OVERVIEW_ITEM_CELL_CLASSES_DEFAULT}><div className="flex flex-row w-full"><div className="flex flex-row items-start justify-start flex-1">{/* Empty space for potential beta tag */}</div>- <div className={`uppercase py-0.5 ${compact ? 'text-[10px]' : 'text-xs font-bold'}`}>- <LemonSkeleton className={`w-16 ${compact ? 'h-2.5' : 'h-3'}`} />+ <div className="uppercase py-0.5 text-xs font-bold">+ <LemonSkeleton className="w-16 h-3" /></div><div className="flex flex-1 flex-row justify-end items-start">{/* Empty space for potential action buttons */}@@ -149,7 +135,6 @@ interface OverviewItemCellProps {preComputeStrategy?: WebAnalyticsPreComputeStrategyonDisablePrecompute?: () => voidlabelFromKey: (key: string) => string- compact: boolean}const OverviewItemCell = ({@@ -157,7 +142,6 @@ const OverviewItemCell = ({preComputeStrategy,onDisablePrecompute,labelFromKey,- compact,}: OverviewItemCellProps): JSX.Element => {const { baseCurrency } = useValues(teamLogic)@@ -224,7 +208,7 @@ const OverviewItemCell = ({<divclassName={clsx('flex-1 border bg-surface-primary rounded relative transition-colors',- compact ? 'min-w-[6rem] h-24' : 'min-w-[10rem] h-30',+ 'min-w-[10rem] h-30',item.selected && 'border-accent ring-1 ring-accent',clickable && 'cursor-pointer hover:border-accent')}@@ -242,16 +226,9 @@ const OverviewItemCell = ({<PreAggregatedBadge variant="preagg" />) : null}<Tooltip title={tooltip}>- <div- className={clsx(- 'flex flex-col items-center text-center justify-between w-full h-full',- compact ? 'p-1' : 'p-2'- )}- >+ <div className="flex flex-col items-center text-center justify-between w-full h-full p-2"><div className="flex flex-row w-full justify-center items-center gap-1">- <div className={`uppercase py-0.5 ${compact ? 'text-[10px]' : 'text-xs font-bold'}`}>- {label}- </div>+ <div className="uppercase py-0.5 text-xs font-bold">{label}</div>{item.warning && (<Tooltipinteractive={!!item.warningLink}@@ -274,9 +251,7 @@ const OverviewItemCell = ({)}</div><div className="w-full flex-1 flex items-center justify-center">- <div className={compact ? 'text-lg' : 'text-2xl'}>- {formatItem(item.value, item.kind, { currency: baseCurrency })}- </div>+ <div className="text-2xl">{formatItem(item.value, item.kind, { currency: baseCurrency })}</div></div>{trend && isNotNil(item.changeFromPreviousPct) ? (// eslint-disable-next-line react/forbid-dom-props@@ -288,10 +263,7 @@ const OverviewItemCell = ({Math.abs(item.changeFromPreviousPct) >= NO_BASELINE_CHANGE_SENTINEL ? (<div className="text-muted">-</div>) : item.caption ? (- <div- className={clsx('text-secondary truncate max-w-full', compact ? 'text-[10px]' : 'text-xs')}- title={item.caption}- >+ <div className="text-secondary truncate max-w-full text-xs" title={item.caption}>{item.caption}</div>) : (diff --git a/frontend/src/queries/nodes/OverviewGrid/OverviewMetricCardGrid.stories.tsx b/frontend/src/queries/nodes/OverviewGrid/OverviewMetricCardGrid.stories.tsxindex 7b470dc08044..0792eb8ab436 100644--- a/frontend/src/queries/nodes/OverviewGrid/OverviewMetricCardGrid.stories.tsx+++ b/frontend/src/queries/nodes/OverviewGrid/OverviewMetricCardGrid.stories.tsx@@ -73,3 +73,43 @@ export const WithWarning: Story = {),},}++export const AdPerformanceMetrics: Story = {+ args: {+ labelFromKey: (key) => key,+ emptyMessage: '-',+ className: 'grid-cols-[repeat(auto-fit,minmax(12rem,1fr))]',+ items: [+ {+ key: 'Cost',+ value: 12450,+ previous: 11800,+ changeFromPreviousPct: 6,+ kind: 'currency',+ isIncreaseBad: true,+ },+ {+ key: 'Cost per reported conversions',+ value: 52,+ previous: 66.67,+ changeFromPreviousPct: -22,+ kind: 'currency',+ isIncreaseBad: true,+ },+ { key: 'Clicks', value: 8300, previous: 7500, changeFromPreviousPct: 11, kind: 'unit' },+ { key: 'Cost per conversion', value: undefined, kind: 'currency' },+ { key: 'Reported conversions', value: 'N/A', previous: 'N/A', kind: 'unit' },+ ],+ },+}++export const AdPerformanceMetricsNarrow: Story = {+ ...AdPerformanceMetrics,+ decorators: [+ (Story) => (+ <div className="w-[520px]">+ <Story />+ </div>+ ),+ ],+}diff --git a/frontend/src/queries/nodes/OverviewGrid/OverviewMetricCardGrid.tsx b/frontend/src/queries/nodes/OverviewGrid/OverviewMetricCardGrid.tsxindex 7e05e5965a5e..44babf760123 100644--- a/frontend/src/queries/nodes/OverviewGrid/OverviewMetricCardGrid.tsx+++ b/frontend/src/queries/nodes/OverviewGrid/OverviewMetricCardGrid.tsx@@ -9,22 +9,22 @@ import { AnalyticsMetricCard } from 'lib/components/AnalyticsMetricCard/Analyticimport { PreAggregatedBadge } from 'lib/components/PreAggregatedBadge'import { Tooltip } from 'lib/lemon-ui/Tooltip'import { range } from 'lib/utils/arrays'+import { cn } from 'lib/utils/css-classes'import { teamLogic } from 'scenes/teamLogic'import { WebAnalyticsPreComputeStrategy } from '~/queries/schema/schema-general'import { formatItem, NO_BASELINE_CHANGE_SENTINEL, OverviewItem, SamplingNotice, SamplingRate } from './OverviewGrid'-export interface OverviewMetricCardItem extends Omit<OverviewItem, 'value' | 'previous'> {- value: number | undefined- previous?: number-}+export type OverviewMetricCardItem = OverviewIteminterface OverviewMetricCardGridProps {items: OverviewMetricCardItem[]layout?: 'grid' | 'contents'loading: booleannumSkeletons: number+ emptyMessage?: React.ReactNode+ className?: stringsamplingRate?: SamplingRatepreComputeStrategy?: WebAnalyticsPreComputeStrategyonDisablePrecompute?: () => void@@ -36,6 +36,8 @@ export function OverviewMetricCardGrid({layout = 'grid',loading,numSkeletons,+ emptyMessage,+ className,samplingRate,preComputeStrategy,onDisablePrecompute,@@ -44,9 +46,10 @@ export function OverviewMetricCardGrid({return (<><div- className={- layout === 'contents' ? 'contents' : 'grid gap-2 grid-cols-[repeat(auto-fit,minmax(10rem,1fr))]'- }+ className={cn(+ layout === 'contents' ? 'contents' : 'grid gap-2 grid-cols-[repeat(auto-fit,minmax(10rem,1fr))]',+ className+ )}>{loading? range(numSkeletons).map((i) => <AnalyticsMetricCard key={i} title={null} loading />)@@ -54,6 +57,7 @@ export function OverviewMetricCardGrid({<MetricCardCellkey={item.key}item={item}+ emptyMessage={emptyMessage}stretch={layout === 'contents'}preComputeStrategy={preComputeStrategy}onDisablePrecompute={onDisablePrecompute}@@ -68,12 +72,14 @@ export function OverviewMetricCardGrid({function MetricCardCell({item,+ emptyMessage,stretch,preComputeStrategy,onDisablePrecompute,labelFromKey,}: {item: OverviewMetricCardItem+ emptyMessage?: React.ReactNodestretch?: booleanpreComputeStrategy?: WebAnalyticsPreComputeStrategyonDisablePrecompute?: () => void@@ -81,8 +87,10 @@ function MetricCardCell({}): JSX.Element {const { baseCurrency } = useValues(teamLogic)- const format = (n: number): string => formatItem(n, item.kind, { currency: baseCurrency })+ const format = (n: number | string): string => formatItem(n, item.kind, { currency: baseCurrency })const subtitle = item.previous != null ? `vs. ${format(item.previous)} prior` : item.caption+ // MetricCard needs a numeric value to render text metrics through its formatter.+ const numericValue = typeof item.value === 'number' ? item.value : typeof item.value === 'string' ? 0 : undefinedreturn (<AnalyticsMetricCard@@ -90,10 +98,13 @@ function MetricCardCell({title={<MetricCardTitle label={labelFromKey(item.key)} item={item} />}onClick={item.onClick}selected={item.selected}- value={item.value}+ value={numericValue}+ emptyMessage={emptyMessage}change={metricChange(item)}goodDirection={item.isIncreaseBad ? 'down' : 'up'}- formatValue={format}+ formatValue={(value) =>+ formatItem(typeof item.value === 'number' ? value : item.value, item.kind, { currency: baseCurrency })+ }subtitle={subtitle}adornment={preComputeStrategy === WebAnalyticsPreComputeStrategy.LazyPrecompute ? (diff --git a/frontend/src/scenes/web-analytics/tabs/marketing-analytics/frontend/components/MarketingAnalyticsOverview/MarketingAnalyticsOverview.tsx b/frontend/src/scenes/web-analytics/tabs/marketing-analytics/frontend/components/MarketingAnalyticsOverview/MarketingAnalyticsOverview.tsxindex 1c47f666fe9a..584cf61d7ada 100644--- a/frontend/src/scenes/web-analytics/tabs/marketing-analytics/frontend/components/MarketingAnalyticsOverview/MarketingAnalyticsOverview.tsx+++ b/frontend/src/scenes/web-analytics/tabs/marketing-analytics/frontend/components/MarketingAnalyticsOverview/MarketingAnalyticsOverview.tsx@@ -5,7 +5,7 @@ import { useAttachedLogic } from 'lib/logic/scenes/useAttachedLogic'import { InsightErrorState } from 'scenes/insights/EmptyStates'import { dataNodeLogic } from '~/queries/nodes/DataNode/dataNodeLogic'-import { OverviewGrid, OverviewItem } from '~/queries/nodes/OverviewGrid/OverviewGrid'+import { OverviewMetricCardGrid, OverviewMetricCardItem } from '~/queries/nodes/OverviewGrid/OverviewMetricCardGrid'import {AnyResponseType,MarketingAnalyticsAggregatedQuery,@@ -52,8 +52,7 @@ export function MarketingAnalyticsOverview(props: {const validationWarnings = useMemo(() => validateConversionGoals(conversion_goals), [conversion_goals])- // Convert results dict to array for rendering and map to OverviewItem- const overviewItems: OverviewItem[] = marketingOverviewQueryResponse?.results+ const overviewItems: OverviewMetricCardItem[] = marketingOverviewQueryResponse?.results? Object.entries(marketingOverviewQueryResponse.results).map(([key, item]) => ({key,value: item.value,@@ -88,14 +87,14 @@ export function MarketingAnalyticsOverview(props: {return (<>{allWarnings.length > 0 && <MarketingAnalyticsValidationWarningBanner warnings={allWarnings} />}- <OverviewGrid- compact- items={overviewItems}+ <OverviewMetricCardGrid+ className="grid-cols-[repeat(auto-fit,minmax(12rem,1fr))]"+ items={overviewItems.filter(filterEmptyMetrics)}loading={responseLoading}numSkeletons={numSkeletons}+ emptyMessage="-"samplingRate={samplingRate}- labelFromKey={labelFromKey}- filterEmptyItems={filterEmptyMetrics}+ labelFromKey={(key) => <span className="[overflow-wrap:anywhere]">{labelFromKey(key)}</span>}/></>)@@ -114,7 +113,7 @@ const labelFromKey = (key: string): string => {.join(' ')}-const filterEmptyMetrics = (item: OverviewItem): boolean => {+const filterEmptyMetrics = (item: OverviewMetricCardItem): boolean => {// Always show cost per metrics, even if they're null (they'll display as "-")if (item.key.toLowerCase().startsWith('cost per')) {return true