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.

chore(navigation): capture clicks on the scene PostHog AI button (#96217)

posthog[bot]cc43f6dcff3f
diff --git a/frontend/src/layout/scenes/components/SceneTitlePanelButton.test.tsx b/frontend/src/layout/scenes/components/SceneTitlePanelButton.test.tsx
new file mode 100644
index 000000000000..1a429f20bfe3
--- /dev/null
+++ b/frontend/src/layout/scenes/components/SceneTitlePanelButton.test.tsx
@@ -0,0 +1,29 @@
+import '@testing-library/jest-dom'
+
+import { cleanup, fireEvent, render } from '@testing-library/react'
+import posthog from 'posthog-js'
+
+import { initKeaTests } from '~/test/init'
+
+import { SceneTitlePanelButton } from './SceneTitleSection'
+
+describe('SceneTitlePanelButton', () => {
+ beforeEach(() => {
+ initKeaTests()
+ jest.spyOn(posthog, 'capture').mockImplementation(() => undefined as any)
+ })
+ afterEach(() => {
+ cleanup()
+ jest.restoreAllMocks()
+ })
+
+ // Without this event a click that never reaches `openSidePanel` leaves no trace at all,
+ // so the panel-never-opens failure has no denominator.
+ test('captures a click on the PostHog AI button', () => {
+ render(<SceneTitlePanelButton />)
+
+ fireEvent.click(document.querySelector('[data-attr="open-context-panel-ai-button"]') as HTMLElement)
+
+ expect(posthog.capture).toHaveBeenCalledWith('scene ai button clicked', expect.objectContaining({ tool: null }))
+ })
+})
diff --git a/frontend/src/layout/scenes/components/SceneTitleSection.tsx b/frontend/src/layout/scenes/components/SceneTitleSection.tsx
index 478e5150d491..a031de050188 100644
--- a/frontend/src/layout/scenes/components/SceneTitleSection.tsx
+++ b/frontend/src/layout/scenes/components/SceneTitleSection.tsx
@@ -1,6 +1,7 @@
import '../../panel-layout/ProjectTree/defaultTree'
import { useActions, useValues } from 'kea'
+import posthog from 'posthog-js'
import { useEffect, useRef, useState } from 'react'
import { useDebouncedCallback } from 'use-debounce'
@@ -27,6 +28,7 @@ import { WrappingLoadingSkeleton } from 'lib/ui/WrappingLoadingSkeleton/Wrapping
import { cn } from 'lib/utils/css-classes'
import { AnimatedSparkles } from 'scenes/max/components/AnimatedSparkles'
import { UseMaxToolOptions, useMaxTool } from 'scenes/max/useMaxTool'
+import { sceneLogic } from 'scenes/sceneLogic'
import { navigation3000Logic } from '~/layout/navigation-3000/navigationLogic'
import { sidePanelStateLogic } from '~/layout/navigation-3000/sidepanel/sidePanelStateLogic'
@@ -38,6 +40,19 @@ import { ProductIconWrapper, iconForType } from '../../panel-layout/ProjectTree/
import { sceneLayoutLogic } from '../sceneLayoutLogic'
import { SceneBreadcrumbBackButton } from './SceneBreadcrumbs'
+/**
+ * The click on the PostHog AI button is the only proof the handler ran. Every route into the
+ * panel captures `sidebar opened` afterwards, so a click without that follow-up event marks a
+ * click that never reached `openSidePanel`. Scene id is read off `sceneLogic` without
+ * subscribing so capture never triggers a re-render.
+ */
+function captureSceneAiButtonClicked(tool: string | null): void {
+ posthog.capture('scene ai button clicked', {
+ scene: sceneLogic.findMounted()?.values.activeSceneId ?? null,
+ tool,
+ })
+}
+
export function SceneTitlePanelButton({
maxToolProps,
buttonClassName = 'size-[33px]',
@@ -72,6 +87,7 @@ export function SceneTitlePanelButton({
onClick={(e) => {
e.stopPropagation()
e.preventDefault()
+ captureSceneAiButtonClicked(maxToolProps?.identifier ?? null)
if (openMax) {
openMax()
} else {
diff --git a/products/error_tracking/frontend/components/ExplainIssueTool.tsx b/products/error_tracking/frontend/components/ExplainIssueTool.tsx
deleted file mode 100644
index 034a9c6e2552..000000000000
--- a/products/error_tracking/frontend/components/ExplainIssueTool.tsx
+++ /dev/null
@@ -1,34 +0,0 @@
-import { useActions, useValues } from 'kea'
-
-import { maxContextLogic } from 'scenes/max/maxContextLogic'
-
-import { sidePanelStateLogic } from '~/layout/navigation-3000/sidepanel/sidePanelStateLogic'
-import { SidePanelTab } from '~/types'
-
-export interface UseErrorTrackingExplainIssueReturn {
- isMaxOpen: boolean
- openMax: () => void
-}
-
-/**
- * Hook to open the Max AI side panel with a prompt to explain an error tracking issue.
- * The issue is added to Max's context so the explanation is grounded in the current issue.
- *
- * @param issueId - The error tracking issue ID to explain
- */
-export function useErrorTrackingExplainIssue(issueId: string): UseErrorTrackingExplainIssueReturn {
- const { sidePanelOpen, selectedTab } = useValues(sidePanelStateLogic)
- const { openSidePanel } = useActions(sidePanelStateLogic)
- const { addOrUpdateContextErrorTrackingIssue } = useActions(maxContextLogic)
-
- const isMaxOpen = sidePanelOpen && selectedTab === SidePanelTab.Max
-
- return {
- isMaxOpen,
- openMax: () => {
- addOrUpdateContextErrorTrackingIssue({ id: issueId })
- // Leading "!" auto-runs the prompt once the side panel opens.
- openSidePanel(SidePanelTab.Max, '!Explain this issue to me')
- },
- }
-}