Skip to content

: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.

fix(marketing-analytics): apply app chart theme to attribution chart (#78735)

Sam Pennington14fae9adacde
diff --git a/frontend/src/lib/charts/hooks.ts b/frontend/src/lib/charts/hooks.ts
index fc8960d374b1..2d31ffac42f2 100644
--- a/frontend/src/lib/charts/hooks.ts
+++ b/frontend/src/lib/charts/hooks.ts
@@ -16,6 +16,7 @@ const CHART_CONFIG_DEFAULTS = {
showCrosshair: true,
showGrid: true,
barCornerRadius: 4,
+ tooltip: { placement: 'cursor' },
} as const
function chartThemeDefaults(isDarkModeOn: boolean): Partial<ChartTheme> {
@@ -72,7 +73,8 @@ export function useDateRangeZoom(
}
/** Builds a chart's config object, memoized on `deps`, applying `CHART_CONFIG_DEFAULTS` for any
- * key the factory leaves undefined. Keys the factory sets explicitly always win over the defaults. */
+ * key the factory leaves undefined. Keys the factory sets explicitly always win over the defaults.
+ * `tooltip` merges key by key instead of being replaced wholesale. */
export function useChartConfig<T extends object>(factory: () => T, deps: DependencyList): T
export function useChartConfig<T extends object>(factory: () => T | undefined, deps: DependencyList): T | undefined
export function useChartConfig<T extends object>(factory: () => T | undefined, deps: DependencyList): T | undefined {
@@ -83,6 +85,8 @@ export function useChartConfig<T extends object>(factory: () => T | undefined, d
return config
}
const defined = Object.fromEntries(Object.entries(config).filter(([, value]) => value !== undefined))
- return { ...CHART_CONFIG_DEFAULTS, ...defined } as T
+ // Nested, so a chart that sets any tooltip field would otherwise replace the whole default.
+ const tooltip = { ...CHART_CONFIG_DEFAULTS.tooltip, ...defined.tooltip }
+ return { ...CHART_CONFIG_DEFAULTS, ...defined, tooltip } as T
}, deps)
}
diff --git a/frontend/src/scenes/web-analytics/tabs/marketing-analytics/frontend/components/AttributionTab/AttributionChart.tsx b/frontend/src/scenes/web-analytics/tabs/marketing-analytics/frontend/components/AttributionTab/AttributionChart.tsx
index d84524adcb27..ee85fe7bf8ab 100644
--- a/frontend/src/scenes/web-analytics/tabs/marketing-analytics/frontend/components/AttributionTab/AttributionChart.tsx
+++ b/frontend/src/scenes/web-analytics/tabs/marketing-analytics/frontend/components/AttributionTab/AttributionChart.tsx
@@ -2,9 +2,10 @@ import clsx from 'clsx'
import { useMemo } from 'react'
import { LemonSkeleton } from '@posthog/lemon-ui'
-import type { Series } from '@posthog/quill-charts'
-import { BarChart, useChartTheme } from '@posthog/quill-charts'
+import type { BarChartConfig, Series } from '@posthog/quill-charts'
+import { BarChart } from '@posthog/quill-charts'
+import { useChartConfig, useChartTheme } from 'lib/charts/hooks'
import { humanFriendlyNumber } from 'lib/utils/numbers'
import { AttributionMode, MarketingAnalyticsAttributionRow } from '~/queries/schema/schema-general'
@@ -59,6 +60,18 @@ export function AttributionChart({
// Rows arrive server-ordered by influenced conversions, so the slice is the top slice.
const chartRows = useMemo(() => rows.slice(0, MAX_CHART_ROWS), [rows])
+ const config: BarChartConfig = useChartConfig(
+ () => ({
+ barLayout: 'grouped',
+ legend: { show: true, position: 'top' },
+ tooltip: {
+ valueFormatter: (value: number) => humanFriendlyNumber(value, 1),
+ sortedByValue: true,
+ },
+ }),
+ []
+ )
+
const series: Series[] = useMemo(
() =>
models.map((model, index) => ({
@@ -99,14 +112,7 @@ export function AttributionChart({
series={series}
labels={chartRows.map((row) => row.breakdownValue || '(none)')}
theme={theme}
- config={{
- barLayout: 'grouped',
- legend: { show: true, position: 'top' },
- tooltip: {
- valueFormatter: (value: number) => humanFriendlyNumber(value, 1),
- sortedByValue: true,
- },
- }}
+ config={config}
/>
</div>
) : (