: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(support): open in-app support from the error toast's get help (#92979)
posthog[bot]b469ee472cca
diff --git a/frontend/src/lib/components/Support/openInAppSupport.ts b/frontend/src/lib/components/Support/openInAppSupport.tsnew file mode 100644index 000000000000..1c85ffe09a05--- /dev/null+++ b/frontend/src/lib/components/Support/openInAppSupport.ts@@ -0,0 +1,28 @@+import { openSupportOptions } from 'lib/lemon-ui/LemonToast/getHelp'+import { preflightLogic } from 'lib/logic/preflightLogic'++import { sidePanelStateLogic } from '~/layout/navigation-3000/sidepanel/sidePanelStateLogic'+import { SidePanelTab } from '~/types'++/**+ * Opens support where the person already is, for any "contact support" trigger.+ *+ * In-app support means the side panel, which is the surface that reads the billing plan: it offers a+ * ticket only to plans entitled to one. Self-hosted has no Support tab, and a scene without a panel+ * (onboarding, login) would fall through to the support modal, which asks for a message from every+ * plan. Those cases link out to the support options docs instead.+ */+export function openInAppSupport(): void {+ const isCloudOrDev = preflightLogic.findMounted()?.values.isCloudOrDev+ const sidePanelAvailable = sidePanelStateLogic.findMounted()?.values.sidePanelAvailable+ if (!isCloudOrDev || !sidePanelAvailable) {+ openSupportOptions()+ return+ }++ // openSidePanel is the same action every other in-app support entry point calls. It writes the+ // `#panel=support` hash with `replace`, so Back leaves in one press instead of stranding an open+ // panel. The panel handles the plan itself, so free plans land on PostHog AI and the community+ // forum rather than a ticket form.+ sidePanelStateLogic.actions.openSidePanel(SidePanelTab.Support)+}diff --git a/frontend/src/lib/components/Support/registerToastGetHelp.test.ts b/frontend/src/lib/components/Support/registerToastGetHelp.test.tsnew file mode 100644index 000000000000..2f437dea68ef--- /dev/null+++ b/frontend/src/lib/components/Support/registerToastGetHelp.test.ts@@ -0,0 +1,67 @@+import { router } from 'kea-router'+import { expectLogic } from 'kea-test-utils'++import { getHelp, resetGetHelpAction } from 'lib/lemon-ui/LemonToast/getHelp'+import { preflightLogic } from 'lib/logic/preflightLogic'++import { sidePanelStateLogic } from '~/layout/navigation-3000/sidepanel/sidePanelStateLogic'+import { initKeaTests } from '~/test/init'+import { PreflightStatus, SidePanelTab } from '~/types'++import { registerToastGetHelp } from './registerToastGetHelp'++describe('registerToastGetHelp', () => {+ const windowOpen = jest.fn()++ const setUp = ({ cloud, sidePanelAvailable }: { cloud: boolean; sidePanelAvailable: boolean }): void => {+ // sidePanelStateLogic reflects open state in the URL hash, which initKeaTests doesn't reset.+ window.history.replaceState(null, '', '/')+ initKeaTests()+ sidePanelStateLogic.mount()+ sidePanelStateLogic.actions.setSidePanelAvailable(sidePanelAvailable)+ preflightLogic.mount()+ preflightLogic.actions.loadPreflightSuccess({ cloud } as PreflightStatus)+ registerToastGetHelp()+ }++ beforeEach(() => {+ jest.clearAllMocks()+ window.open = windowOpen+ })++ afterEach(() => {+ resetGetHelpAction()+ })++ it('opens the support side panel on cloud instead of leaving the app', async () => {+ setUp({ cloud: true, sidePanelAvailable: true })++ await expectLogic(sidePanelStateLogic, () => getHelp()).toFinishAllListeners()++ expect(router.values.hashParams['panel']).toBe(SidePanelTab.Support)+ expect(sidePanelStateLogic.values.selectedTab).toBe(SidePanelTab.Support)+ expect(sidePanelStateLogic.values.sidePanelOpen).toBe(true)+ expect(windowOpen).not.toHaveBeenCalled()+ // The panel replaces the URL rather than pushing it. A pushed entry would leave Back stripping+ // the hash while the panel stayed open, so Back would do nothing a person can see.+ await expectLogic(router).toNotHaveDispatchedActions(['push'])+ })++ // Self-hosted has no Support tab, and a scene without a panel falls through to the support modal,+ // which asks every plan for a message. Both link out to the channels their plan actually has.+ it.each([+ ['a self-hosted instance', { cloud: false, sidePanelAvailable: true }],+ ['a scene without a side panel', { cloud: true, sidePanelAvailable: false }],+ ])('sends %s to the support options docs', async (_, options) => {+ setUp(options)++ await expectLogic(sidePanelStateLogic, () => getHelp()).toFinishAllListeners()++ expect(sidePanelStateLogic.values.sidePanelOpen).toBe(false)+ expect(windowOpen).toHaveBeenCalledWith(+ expect.stringContaining('posthog.com/docs/support-options'),+ '_blank',+ 'noopener'+ )+ })+})diff --git a/frontend/src/lib/components/Support/registerToastGetHelp.ts b/frontend/src/lib/components/Support/registerToastGetHelp.tsnew file mode 100644index 000000000000..040e0f0c068b--- /dev/null+++ b/frontend/src/lib/components/Support/registerToastGetHelp.ts@@ -0,0 +1,8 @@+import { setGetHelpAction } from 'lib/lemon-ui/LemonToast/getHelp'++import { openInAppSupport } from './openInAppSupport'++/** Points the error toast's "Get help" button at in-app support instead of the docs fallback. */+export function registerToastGetHelp(): void {+ setGetHelpAction(openInAppSupport)+}diff --git a/frontend/src/lib/lemon-ui/LemonToast/LemonToast.test.tsx b/frontend/src/lib/lemon-ui/LemonToast/LemonToast.test.tsxindex 3cd9bf87400e..4b2f77b6a6bd 100644--- a/frontend/src/lib/lemon-ui/LemonToast/LemonToast.test.tsx+++ b/frontend/src/lib/lemon-ui/LemonToast/LemonToast.test.tsx@@ -1,7 +1,8 @@import '@testing-library/jest-dom'-import { act, fireEvent, render } from '@testing-library/react'+import { act, fireEvent, render, within } from '@testing-library/react'+import { resetGetHelpAction, setGetHelpAction } from './getHelp'import { GET_HELP_BUTTON, ToastContent, withClickableUrls } from './LemonToast'describe('LemonToast', () => {@@ -12,6 +13,44 @@ describe('LemonToast', () => {Object.assign(navigator, { clipboard: { writeText } })})+ afterEach(() => {+ resetGetHelpAction()+ jest.restoreAllMocks()+ })++ // "Get help" has to reach support where the person already is. Sending them to posthog.com+ // instead drops the error, the scene, and everything else that made the toast worth acting on.+ it('runs the registered get-help action rather than opening posthog.com', () => {+ const openSupport = jest.fn()+ setGetHelpAction(openSupport)+ const windowOpen = jest.spyOn(window, 'open').mockImplementation(() => null)++ const { container } = render(+ <ToastContent type="error" message="Load experiment failed" button={GET_HELP_BUTTON} />+ )+ fireEvent.click(within(container).getByText('Get help'))++ expect(openSupport).toHaveBeenCalledTimes(1)+ expect(windowOpen).not.toHaveBeenCalled()+ })++ // The toolbar and the exporter render toasts but have no support form to open, so they fall+ // back to the support options docs.+ it('falls back to the support options docs when nothing is registered', () => {+ const windowOpen = jest.spyOn(window, 'open').mockImplementation(() => null)++ const { container } = render(+ <ToastContent type="error" message="Load experiment failed" button={GET_HELP_BUTTON} />+ )+ fireEvent.click(within(container).getByText('Get help'))++ expect(windowOpen).toHaveBeenCalledWith(+ expect.stringContaining('posthog.com/docs/support-options'),+ '_blank',+ 'noopener'+ )+ })+// The copy button reads the rendered message out of the DOM, so it copies whatever sits inside the// message element. Widening that element to cover the action button would silently append "Get help"// to every error someone pastes elsewhere.diff --git a/frontend/src/lib/lemon-ui/LemonToast/LemonToast.tsx b/frontend/src/lib/lemon-ui/LemonToast/LemonToast.tsxindex aa3594f3d516..9e8c11d9f3bb 100644--- a/frontend/src/lib/lemon-ui/LemonToast/LemonToast.tsx+++ b/frontend/src/lib/lemon-ui/LemonToast/LemonToast.tsx@@ -14,6 +14,7 @@ import { IconErrorOutline, IconGift } from '../icons'import { LemonButton } from '../LemonButton'import { Link } from '../Link'import { Spinner } from '../Spinner'+import { getHelp } from './getHelp'export function ToastCloseButton({ closeToast }: { closeToast?: () => void }): JSX.Element {return (@@ -41,9 +42,7 @@ interface ToastOptionsWithButton<T = string> extends ToastOptions<T> {export const GET_HELP_BUTTON: ToastButton = {label: 'Get help',- action: () => {- window.open('https://posthog.com/support?utm_medium=in-product&utm_campaign=error-toast', '_blank')- },+ action: getHelp,}// Fallback for when submitting a support ticket in-app fails: let the user reach usdiff --git a/frontend/src/lib/lemon-ui/LemonToast/getHelp.ts b/frontend/src/lib/lemon-ui/LemonToast/getHelp.tsnew file mode 100644index 000000000000..a9e384401eb6--- /dev/null+++ b/frontend/src/lib/lemon-ui/LemonToast/getHelp.ts@@ -0,0 +1,36 @@+export type GetHelpAction = () => void++/**+ * Where people without in-app support end up: self-hosted instances, the toolbar, the exporter.+ * The docs page lists the channels open to each plan; posthog.com/support sells the support product.+ */+export const openSupportOptions: GetHelpAction = () => {+ // `noopener` because window.open, unlike an <a target="_blank">, leaves window.opener reachable+ // by the opened page.+ window.open(+ 'https://posthog.com/docs/support-options?utm_medium=in-product&utm_campaign=error-toast',+ '_blank',+ 'noopener'+ )+}++let getHelpAction: GetHelpAction = openSupportOptions++/**+ * Replaces what the error toast's "Get help" button does. The app registers the in-product support+ * form in `bootApp()`; bundles without one (toolbar, exporter) keep the docs fallback.+ * A seam rather than a direct call because `supportLogic` already imports the toast module, so+ * reaching back into it from here would close a cycle.+ */+export function setGetHelpAction(action: GetHelpAction): void {+ getHelpAction = action+}++/** Restores the docs fallback. Test-only: keeps a registered action from leaking across tests. */+export function resetGetHelpAction(): void {+ getHelpAction = openSupportOptions+}++export function getHelp(): void {+ getHelpAction()+}diff --git a/frontend/src/scenes/bootApp.ts b/frontend/src/scenes/bootApp.tsindex cc70be36ca4c..f05b70d7b365 100644--- a/frontend/src/scenes/bootApp.ts+++ b/frontend/src/scenes/bootApp.ts@@ -1,3 +1,4 @@+import { registerToastGetHelp } from 'lib/components/Support/registerToastGetHelp'import { registerNotebookLinkDrag } from 'scenes/notebooks/AddToNotebook/registerNotebookLinkDrag'import { initKea } from '../initKea'@@ -29,6 +30,9 @@ export function bootApp(): void {// Link resolves its drag-to-notebook behavior through a seam so bundles without// notebooks (toolbar, exporter) don't ship them; the app opts in hereregisterNotebookLinkDrag()+ // Same seam for the error toast's "Get help" button: the app opens support in place, the+ // toolbar and exporter keep linking out to the support options docs+ registerToastGetHelp()const idle =typeof window.requestIdleCallback === 'function'