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(code): add channel share link interstitial for posthog code (#68479)

Peter Kirkhamf52f1246a527
diff --git a/frontend/src/scenes/appScenes.ts b/frontend/src/scenes/appScenes.ts
index 1d5d2ab7ac46..3d1b984195f8 100644
--- a/frontend/src/scenes/appScenes.ts
+++ b/frontend/src/scenes/appScenes.ts
@@ -131,6 +131,7 @@ export const appScenes: Record<Scene | string, () => any> = {
[Scene.EventFiltering]: () => import('./data-pipelines/event-filtering/EventFilterScene'),
[Scene.Unsubscribe]: () => import('./Unsubscribe/Unsubscribe'),
[Scene.CodeCanvasLink]: () => import('./code-canvas/CodeCanvasLink'),
+ [Scene.CodeChannelLink]: () => import('./code-canvas/CodeChannelLink'),
[Scene.VercelConnect]: () => import('./authentication/vercel/VercelConnect'),
[Scene.VercelLinkError]: () => import('./authentication/vercel/VercelLinkError'),
[Scene.AgenticAccountMismatch]: () => import('./authentication/account/AgenticAccountMismatch'),
diff --git a/frontend/src/scenes/code-canvas/CodeCanvasLink.tsx b/frontend/src/scenes/code-canvas/CodeCanvasLink.tsx
index 86b651c0c4f4..e3479c08b3fa 100644
--- a/frontend/src/scenes/code-canvas/CodeCanvasLink.tsx
+++ b/frontend/src/scenes/code-canvas/CodeCanvasLink.tsx
@@ -6,6 +6,8 @@ import { BridgePage } from 'lib/components/BridgePage/BridgePage'
import { LemonButton } from 'lib/lemon-ui/LemonButton'
import { SceneExport } from 'scenes/sceneTypes'
+import { DESKTOP_SCHEME } from './desktopScheme'
+
export interface CodeCanvasLinkProps {
channelId: string
dashboardId: string
@@ -19,13 +21,6 @@ export const scene: SceneExport<CodeCanvasLinkProps> = {
}),
}
-// The desktop app registers a different custom scheme per build: production
-// installs use `posthog-code://`, local dev builds use `posthog-code-dev://`.
-// A dev frontend (./bin/start) is exactly when you're testing against a dev
-// desktop build, so target that scheme there. Build-time constant, so it never
-// flips after mount and double-fires.
-const DESKTOP_SCHEME = process.env.NODE_ENV === 'development' ? 'posthog-code-dev' : 'posthog-code'
-
function canvasDeepLink(channelId: string, dashboardId: string): string {
return `${DESKTOP_SCHEME}://canvas/${encodeURIComponent(channelId)}/${encodeURIComponent(dashboardId)}`
}
diff --git a/frontend/src/scenes/code-canvas/CodeChannelLink.tsx b/frontend/src/scenes/code-canvas/CodeChannelLink.tsx
new file mode 100644
index 000000000000..579177297374
--- /dev/null
+++ b/frontend/src/scenes/code-canvas/CodeChannelLink.tsx
@@ -0,0 +1,78 @@
+import { useEffect } from 'react'
+
+import { IconLaptop } from '@posthog/icons'
+
+import { BridgePage } from 'lib/components/BridgePage/BridgePage'
+import { LemonButton } from 'lib/lemon-ui/LemonButton'
+import { SceneExport } from 'scenes/sceneTypes'
+
+import { DESKTOP_SCHEME } from './desktopScheme'
+
+export interface CodeChannelLinkProps {
+ channelId: string
+ taskId?: string
+}
+
+export const scene: SceneExport<CodeChannelLinkProps> = {
+ component: CodeChannelLink,
+ paramsToProps: ({ params: { channelId, taskId } }) => ({
+ channelId: channelId ?? '',
+ taskId: taskId || undefined,
+ }),
+}
+
+function channelDeepLink(channelId: string, taskId?: string): string {
+ const base = `${DESKTOP_SCHEME}://channel/${encodeURIComponent(channelId)}`
+ return taskId ? `${base}/tasks/${encodeURIComponent(taskId)}` : base
+}
+
+/**
+ * Public, unauthenticated bridge for desktop-app "channel" share links
+ * (`/code/channel/<channelId>` and `/code/channel/<channelId>/tasks/<taskId>`). On mount it
+ * deep-links into the desktop app via the `posthog-code(-dev)://` custom scheme; for visitors
+ * without the app it shows an explanation, a manual "open" button (in case the browser blocks
+ * the auto-redirect), and a download link. Channels and their threads only exist in the desktop
+ * app, so nothing is rendered here beyond this interstitial.
+ */
+export function CodeChannelLink({ channelId, taskId }: CodeChannelLinkProps): JSX.Element {
+ // Null when the channel id is missing (a partial URL or params not yet resolved), since
+ // firing with an empty id would send a malformed `<scheme>://channel/`.
+ const deepLink = channelId ? channelDeepLink(channelId, taskId) : null
+ const target = taskId ? 'thread' : 'channel'
+
+ useEffect(() => {
+ if (deepLink) {
+ window.location.href = deepLink
+ }
+ }, [deepLink])
+
+ return (
+ <BridgePage view="code-channel-link">
+ <div className="flex flex-col items-center gap-4 text-center max-w-lg mx-auto">
+ <IconLaptop className="text-5xl shrink-0" />
+ <h2 className="text-xl font-semibold m-0">Opening in PostHog Code…</h2>
+ <p className="text-muted mb-0">
+ This {target} lives in the PostHog Code desktop app. If it's installed, it should open
+ automatically. If it didn't, use the button below, or download the app.
+ </p>
+ <div className="flex flex-col items-center gap-2">
+ {deepLink && (
+ <LemonButton
+ type="primary"
+ onClick={() => {
+ window.location.href = deepLink
+ }}
+ >
+ Open in PostHog Code
+ </LemonButton>
+ )}
+ <LemonButton type="secondary" to="https://posthog.com/code" targetBlank>
+ Download PostHog Code
+ </LemonButton>
+ </div>
+ </div>
+ </BridgePage>
+ )
+}
+
+export default CodeChannelLink
diff --git a/frontend/src/scenes/code-canvas/desktopScheme.ts b/frontend/src/scenes/code-canvas/desktopScheme.ts
new file mode 100644
index 000000000000..90e2322aae16
--- /dev/null
+++ b/frontend/src/scenes/code-canvas/desktopScheme.ts
@@ -0,0 +1,6 @@
+// The desktop app registers a different custom scheme per build: production
+// installs use `posthog-code://`, local dev builds use `posthog-code-dev://`.
+// A dev frontend (./bin/start) is exactly when you're testing against a dev
+// desktop build, so target that scheme there. Build-time constant, so it never
+// flips after mount and double-fires.
+export const DESKTOP_SCHEME = process.env.NODE_ENV === 'development' ? 'posthog-code-dev' : 'posthog-code'
diff --git a/frontend/src/scenes/sceneTypes.ts b/frontend/src/scenes/sceneTypes.ts
index 44b62e7057da..fec00192733e 100644
--- a/frontend/src/scenes/sceneTypes.ts
+++ b/frontend/src/scenes/sceneTypes.ts
@@ -169,6 +169,7 @@ export enum Scene {
EventFiltering = 'EventFiltering',
Unsubscribe = 'Unsubscribe',
CodeCanvasLink = 'CodeCanvasLink',
+ CodeChannelLink = 'CodeChannelLink',
UserInterview = 'UserInterview',
UserInterviewResponse = 'UserInterviewResponse',
UserInterviews = 'UserInterviews',
diff --git a/frontend/src/scenes/scenes.ts b/frontend/src/scenes/scenes.ts
index a8e5568e6cb3..2ffdde0354d5 100644
--- a/frontend/src/scenes/scenes.ts
+++ b/frontend/src/scenes/scenes.ts
@@ -582,6 +582,7 @@ export const sceneConfigurations: Record<Scene | string, SceneConfig> = {
},
[Scene.Unsubscribe]: { allowUnauthenticated: true, layout: 'app-raw' },
[Scene.CodeCanvasLink]: { allowUnauthenticated: true, layout: 'app-raw' },
+ [Scene.CodeChannelLink]: { allowUnauthenticated: true, layout: 'app-raw' },
[Scene.VerifyEmail]: { allowUnauthenticated: true, layout: 'plain' },
[Scene.WebAnalyticsPageReports]: {
projectBased: true,
@@ -915,6 +916,8 @@ export const routes: Record<string, [Scene | string, string]> = {
[urls.agenticAccountMismatch()]: [Scene.AgenticAccountMismatch, 'agenticAccountMismatch'],
[urls.unsubscribe()]: [Scene.Unsubscribe, 'unsubscribe'],
[urls.codeCanvasLink(':channelId', ':dashboardId')]: [Scene.CodeCanvasLink, 'codeCanvasLink'],
+ [urls.codeChannelLink(':channelId')]: [Scene.CodeChannelLink, 'codeChannelLink'],
+ [urls.codeChannelLink(':channelId', ':taskId')]: [Scene.CodeChannelLink, 'codeChannelThreadLink'],
[urls.integrationsRedirect(':kind')]: [Scene.IntegrationsRedirect, 'integrationsRedirect'],
[urls.integration(':slug')]: [Scene.IntegrationsLanding, 'integrationsLanding'],
[urls.stripeConfirmInstall()]: [Scene.StripeConfirmInstall, 'stripeConfirmInstall'],
diff --git a/frontend/src/scenes/urls.ts b/frontend/src/scenes/urls.ts
index 5a16280353ed..6d673d1d98f0 100644
--- a/frontend/src/scenes/urls.ts
+++ b/frontend/src/scenes/urls.ts
@@ -238,6 +238,8 @@ export const urls = {
materializedColumns: (): string => '/data-management/materialized-columns',
unsubscribe: (): string => '/unsubscribe',
codeCanvasLink: (channelId: string, dashboardId: string): string => `/code/canvas/${channelId}/${dashboardId}`,
+ codeChannelLink: (channelId: string, taskId?: string): string =>
+ `/code/channel/${channelId}${taskId ? `/tasks/${taskId}` : ''}`,
integration: (slug: string): string => `/integrations/${slug}`,
integrationsRedirect: (kind: string): string => `/integrations/${kind}/callback`,
stripeConfirmInstall: (): string => '/integrations/stripe/confirm-install',