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.

feat(dashboards): test PostHog AI button label (#71350)

Paul D'Ambra24fe0a13a73a
diff --git a/frontend/src/layout/scenes/components/SceneTitleSection.tsx b/frontend/src/layout/scenes/components/SceneTitleSection.tsx
index 0b49f8455ebe..735b29d0307c 100644
--- a/frontend/src/layout/scenes/components/SceneTitleSection.tsx
+++ b/frontend/src/layout/scenes/components/SceneTitleSection.tsx
@@ -41,9 +41,11 @@ import { SceneBreadcrumbBackButton } from './SceneBreadcrumbs'
export function SceneTitlePanelButton({
maxToolProps,
buttonClassName = 'size-[33px]',
+ maxButtonLabel,
}: {
maxToolProps?: Omit<UseMaxToolOptions, 'active'>
buttonClassName?: string
+ maxButtonLabel?: string
}): JSX.Element | null {
const { scenePanelIsPresent } = useValues(sceneLayoutLogic)
const { openSidePanel } = useActions(sidePanelStateLogic)
@@ -66,7 +68,7 @@ export function SceneTitlePanelButton({
<>
{!sceneMenuBarEnabled && (
<ButtonPrimitive
- className={buttonClassName}
+ className={cn(buttonClassName, maxButtonLabel && 'w-auto px-2')}
onClick={(e) => {
e.stopPropagation()
e.preventDefault()
@@ -92,7 +94,7 @@ export function SceneTitlePanelButton({
}
tooltipPlacement="bottom-end"
tooltipCloseDelayMs={0}
- iconOnly
+ iconOnly={!maxButtonLabel}
data-attr="open-context-panel-ai-button"
>
<div className="relative">
@@ -101,6 +103,7 @@ export function SceneTitlePanelButton({
<IconBrackets className="absolute size-2.5 top-0 -right-1 text-black dark:text-white" />
)}
</div>
+ {maxButtonLabel}
</ButtonPrimitive>
)}
{/* Size to mimic lemon button small */}
@@ -216,6 +219,8 @@ type SceneMainTitleProps = {
* the AI button in the title section registers the tool with Max
*/
maxToolProps?: Omit<UseMaxToolOptions, 'active'>
+ /** Optional label for the PostHog AI button. */
+ maxButtonLabel?: string
/** Max character length for the description field */
descriptionMaxLength?: number
}
@@ -241,6 +246,7 @@ export function SceneTitleSection({
onGenerateMetadata,
isGeneratingMetadata,
maxToolProps,
+ maxButtonLabel,
descriptionMaxLength,
}: SceneMainTitleProps): JSX.Element | null {
const { breadcrumbs } = useValues(breadcrumbsLogic)
@@ -390,7 +396,7 @@ export function SceneTitleSection({
)}
>
{effectiveActions}
- <SceneTitlePanelButton maxToolProps={maxToolProps} />
+ <SceneTitlePanelButton maxToolProps={maxToolProps} maxButtonLabel={maxButtonLabel} />
</div>
)}
</div>
diff --git a/frontend/src/lib/constants.tsx b/frontend/src/lib/constants.tsx
index ff11f79c0107..6508d16714da 100644
--- a/frontend/src/lib/constants.tsx
+++ b/frontend/src/lib/constants.tsx
@@ -276,6 +276,7 @@ export const FEATURE_FLAGS = {
DASHBOARD_AUTO_PREVIEW_LIMIT: 'dashboard-auto-preview-limit', // owner: @pauldambra #team-product-analytics
DASHBOARD_INLINE_TILE_INSERTION: 'dashboard-inline-tile-insertion', // owner: @MattPua #team-analytics-platform
DASHBOARD_LAYOUT_DISCARD_PROMPT: 'dashboard-layout-discard-prompt', // owner: @cory.s #team-analytics-platform
+ DASHBOARD_POSTHOG_AI_BUTTON_LABEL: 'dashboard-posthog-ai-button-label', // owner: @pauldambra #team-product-analytics multivariate=control,control_b,test
DASHBOARD_TEMPLATE_CHOOSER_EXPERIMENT: 'dashboard-template-chooser-experiment', // owner: @mattp #team-analytics-platform multivariate=control,simple,new
DASHBOARD_WIDGETS: 'dashboard-widgets', // owner: @mattp #team-analytics-platform
DASHBOARDS_LIST_VIEW: 'dashboards-list-view', // owner: @vdekrijger #team-product-analytics multivariate=control,tree
diff --git a/frontend/src/scenes/dashboard/DashboardHeader.test.tsx b/frontend/src/scenes/dashboard/DashboardHeader.test.tsx
index bb66f2ba3e35..b5ff2d93ba29 100644
--- a/frontend/src/scenes/dashboard/DashboardHeader.test.tsx
+++ b/frontend/src/scenes/dashboard/DashboardHeader.test.tsx
@@ -3,6 +3,8 @@ import '@testing-library/jest-dom'
import { cleanup, render } from '@testing-library/react'
import { BindLogic } from 'kea'
+import { useFeatureFlagVariantKey } from '@posthog/react'
+
import { featureFlagLogic } from 'lib/logic/featureFlagLogic'
import { DashboardEventSource } from 'lib/utils/eventUsageLogic'
@@ -19,6 +21,12 @@ jest.mock('lib/components/FullScreen', () => ({
jest.mock('scenes/max/MaxTool', () => ({
MaxTool: ({ children }: any) => <>{children}</>,
}))
+jest.mock('@posthog/react', () => ({
+ ...jest.requireActual('@posthog/react'),
+ useFeatureFlagVariantKey: jest.fn(),
+}))
+
+const mockUseFeatureFlagVariantKey = jest.mocked(useFeatureFlagVariantKey)
const MOCK_DASHBOARD: DashboardType<QueryBasedInsightModel> = {
id: 5,
@@ -161,4 +169,24 @@ describe('DashboardHeader', () => {
logic.unmount()
}
)
+
+ it.each([
+ { variant: 'control', showsLabel: false },
+ { variant: 'control_b', showsLabel: false },
+ { variant: 'test', showsLabel: true },
+ ])('$variant variant sets the PostHog AI button label', ({ variant, showsLabel }) => {
+ mockUseFeatureFlagVariantKey.mockReturnValue(variant)
+
+ const { logic } = renderHeader({ dashboard: MOCK_DASHBOARD })
+ const aiButton = document.querySelector('[data-attr="open-context-panel-ai-button"]')
+
+ expect(aiButton).toBeInTheDocument()
+ if (showsLabel) {
+ expect(aiButton).toHaveTextContent('PostHog AI')
+ } else {
+ expect(aiButton).not.toHaveTextContent('PostHog AI')
+ }
+
+ logic.unmount()
+ })
})
diff --git a/frontend/src/scenes/dashboard/DashboardHeader.tsx b/frontend/src/scenes/dashboard/DashboardHeader.tsx
index 265d28d6f54b..793c49861522 100644
--- a/frontend/src/scenes/dashboard/DashboardHeader.tsx
+++ b/frontend/src/scenes/dashboard/DashboardHeader.tsx
@@ -1,6 +1,9 @@
import { useActions, useValues } from 'kea'
+import { useFeatureFlagVariantKey } from '@posthog/react'
+
import { FullScreen } from 'lib/components/FullScreen'
+import { FEATURE_FLAGS } from 'lib/constants'
import { DashboardEventSource } from 'lib/utils/eventUsageLogic'
import { sceneConfigurations } from 'scenes/scenes'
import { Scene } from 'scenes/sceneTypes'
@@ -23,6 +26,7 @@ export function DashboardHeader(): JSX.Element | null {
const { dashboard, dashboardLoading, dashboardMode, canEditDashboard } = useValues(dashboardLogic)
const { setDashboardMode, loadDashboard } = useActions(dashboardLogic)
const { updateDashboard } = useActions(dashboardsModel)
+ const postHogAIButtonLabelVariant = useFeatureFlagVariantKey(FEATURE_FLAGS.DASHBOARD_POSTHOG_AI_BUTTON_LABEL)
if (!dashboard && !dashboardLoading) {
return null
@@ -56,6 +60,7 @@ export function DashboardHeader(): JSX.Element | null {
isLoading={dashboardLoading}
saveOnBlur
renameDebounceMs={0}
+ maxButtonLabel={postHogAIButtonLabelVariant === 'test' ? 'PostHog AI' : undefined}
maxToolProps={
dashboard && canEditDashboard
? {