: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-analytics): show an untagged campaign or source as (empty) (#97560)
Javier Bahamondes2817f627a205
diff --git a/frontend/src/scenes/web-analytics/tabs/marketing-analytics/frontend/components/CampaignMapping/mappingUtils.test.ts b/frontend/src/scenes/web-analytics/tabs/marketing-analytics/frontend/components/CampaignMapping/mappingUtils.test.tsindex 82cd6f53ca24..8001035cd147 100644--- a/frontend/src/scenes/web-analytics/tabs/marketing-analytics/frontend/components/CampaignMapping/mappingUtils.test.ts+++ b/frontend/src/scenes/web-analytics/tabs/marketing-analytics/frontend/components/CampaignMapping/mappingUtils.test.ts@@ -1,4 +1,4 @@-import { MappableColumn, getMappableColumn, isMappableValue } from './mappingUtils'+import { EMPTY_UTM_LABEL, MappableColumn, getMappableColumn, isMappableValue, withEmptyUtmLabel } from './mappingUtils'describe('mappingUtils', () => {describe('getMappableColumn', () => {@@ -28,4 +28,25 @@ describe('mappingUtils', () => {expect(isMappableValue(value)).toBe(expected)})})++ describe('withEmptyUtmLabel', () => {+ it.each([+ ['Campaign', 'organic', EMPTY_UTM_LABEL],+ ['Source', 'organic', EMPTY_UTM_LABEL],+ ['Source', 'Organic', EMPTY_UTM_LABEL],+ ['Campaign', 'summer_sale', 'summer_sale'],+ ['Source', 'google', 'google'],+ ])('column %s with value %s shows %s', (key, value, expected) => {+ expect(withEmptyUtmLabel({ key, value }).value).toBe(expected)+ })++ it('leaves a column that is not campaign or source alone', () => {+ expect(withEmptyUtmLabel({ key: 'Channel', value: 'organic' }).value).toBe('organic')+ })++ it('returns the same object when nothing changes, so a cell does not re-render', () => {+ const item = { key: 'Campaign', value: 'summer_sale' }+ expect(withEmptyUtmLabel(item)).toBe(item)+ })+ })})diff --git a/frontend/src/scenes/web-analytics/tabs/marketing-analytics/frontend/components/CampaignMapping/mappingUtils.ts b/frontend/src/scenes/web-analytics/tabs/marketing-analytics/frontend/components/CampaignMapping/mappingUtils.tsindex 03e064362d4c..98747476be76 100644--- a/frontend/src/scenes/web-analytics/tabs/marketing-analytics/frontend/components/CampaignMapping/mappingUtils.ts+++ b/frontend/src/scenes/web-analytics/tabs/marketing-analytics/frontend/components/CampaignMapping/mappingUtils.ts@@ -311,3 +311,16 @@ export function isMappableValue(value: unknown): boolean {const utmValue = extractStringValue(value)return !!utmValue && utmValue.toLowerCase() !== ORGANIC_LABEL}++/** What a campaign or source cell shows when the row carried no utm tag. */+export const EMPTY_UTM_LABEL = '(empty)'++/** Reads the sentinel as the absence it stands for, so a row does not name a campaign nobody created.+ * A source genuinely tagged `organic` is indistinguishable here, and the backend already groups it+ * into the same row. */+export function withEmptyUtmLabel<T extends { key: string; value?: number | string }>(item: T): T {+ if (!getMappableColumn(item.key) || extractStringValue(item.value).toLowerCase() !== ORGANIC_LABEL) {+ return item+ }+ return { ...item, value: EMPTY_UTM_LABEL }+}diff --git a/frontend/src/scenes/web-analytics/tabs/marketing-analytics/frontend/shared.tsx b/frontend/src/scenes/web-analytics/tabs/marketing-analytics/frontend/shared.tsxindex 0f0bb039748a..73ce7871ab24 100644--- a/frontend/src/scenes/web-analytics/tabs/marketing-analytics/frontend/shared.tsx+++ b/frontend/src/scenes/web-analytics/tabs/marketing-analytics/frontend/shared.tsx@@ -15,6 +15,8 @@ import { teamLogic } from 'scenes/teamLogic'import { InfinityValue, MarketingAnalyticsItem, WebAnalyticsItemKind } from '~/queries/schema/schema-general'import { ChartDisplayType } from '~/types'+import { withEmptyUtmLabel } from './components/CampaignMapping/mappingUtils'+// Simple mapping for the display mode options and their iconsexport const DISPLAY_MODE_OPTIONS: LemonSegmentedButtonOption<ChartDisplayType>[] = [{ value: ChartDisplayType.ActionsLineGraph, icon: <IconLineGraph /> },@@ -296,5 +298,5 @@ export const MarketingAnalyticsCell = ({return <span>-</span>}- return <MarketingAnalyticsCellInternal value={value as MarketingAnalyticsItem} style={style} />+ return <MarketingAnalyticsCellInternal value={withEmptyUtmLabel(value as MarketingAnalyticsItem)} style={style} />}