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(desktop): show PostHog web feedback intercept only once (#76547)

Jonathan Mieloo5bd365f4d775
diff --git a/products/desktop/packages/ui/src/features/canvas/stores/posthogWebFeedbackStore.ts b/products/desktop/packages/ui/src/features/canvas/stores/posthogWebFeedbackStore.ts
new file mode 100644
index 000000000000..ea4838b08db6
--- /dev/null
+++ b/products/desktop/packages/ui/src/features/canvas/stores/posthogWebFeedbackStore.ts
@@ -0,0 +1,50 @@
+import { electronStorage } from "@posthog/ui/shell/rendererStorage";
+import { create } from "zustand";
+import { persist } from "zustand/middleware";
+
+// Tracks whether the "Before you head to PostHog web" feedback intercept has
+// already run once. After the user submits, skips, or dismisses it, going back
+// to PostHog web navigates straight there instead of prompting again.
+interface PostHogWebFeedbackState {
+ hasSeen: boolean;
+ // Storage is read asynchronously (Electron IPC); hasSeen exposes its default
+ // until the read settles. Readers can gate on this to avoid trusting the
+ // pre-hydration default.
+ hasHydrated: boolean;
+ markSeen: () => void;
+ setHasHydrated: (hydrated: boolean) => void;
+}
+
+export const usePostHogWebFeedbackStore = create<PostHogWebFeedbackState>()(
+ persist(
+ (set) => ({
+ hasSeen: false,
+ hasHydrated: false,
+ markSeen: () => set({ hasSeen: true }),
+ setHasHydrated: (hydrated) => set({ hasHydrated: hydrated }),
+ }),
+ {
+ name: "posthog-web-feedback-seen",
+ storage: electronStorage,
+ partialize: (state) => ({ hasSeen: state.hasSeen }),
+ // A markSeen() that lands before the async read returns would otherwise be
+ // undone by zustand's default merge overwriting it with the persisted
+ // value. Keep hasSeen sticky so the one-time intercept is never re-shown.
+ merge: (persisted, current) => ({
+ ...current,
+ hasSeen:
+ current.hasSeen ||
+ (persisted as Partial<PostHogWebFeedbackState>)?.hasSeen === true,
+ }),
+ onRehydrateStorage: () => (state) => {
+ if (state) {
+ state.setHasHydrated(true);
+ return;
+ }
+ // Failed read: fail open as unseen. Re-showing the intercept once beats
+ // never navigating; the in-session markSeen still suppresses it after.
+ usePostHogWebFeedbackStore.setState({ hasHydrated: true });
+ },
+ },
+ ),
+);
diff --git a/products/desktop/packages/ui/src/router/routes/__root.tsx b/products/desktop/packages/ui/src/router/routes/__root.tsx
index 9ca6ca2279e6..6abf62970161 100644
--- a/products/desktop/packages/ui/src/router/routes/__root.tsx
+++ b/products/desktop/packages/ui/src/router/routes/__root.tsx
@@ -33,6 +33,7 @@ import {
import { useCanvasDeepLink } from "@posthog/ui/features/canvas/hooks/useCanvasDeepLink";
import { useChannelDeepLink } from "@posthog/ui/features/canvas/hooks/useChannelDeepLink";
import { useChannelsLayout } from "@posthog/ui/features/canvas/hooks/useChannelsLayout";
+import { usePostHogWebFeedbackStore } from "@posthog/ui/features/canvas/stores/posthogWebFeedbackStore";
import { CommandMenu } from "@posthog/ui/features/command/CommandMenu";
import { CommandSearchBar } from "@posthog/ui/features/command/CommandSearchBar";
import { GlobalFilePicker } from "@posthog/ui/features/command/GlobalFilePicker";
@@ -156,18 +157,33 @@ function RootLayout() {
currentProjectId ? `/project/${currentProjectId}` : "/",
);
+ const posthogWebFeedbackSeen = usePostHogWebFeedbackStore((s) => s.hasSeen);
+ const posthogWebFeedbackHydrated = usePostHogWebFeedbackStore(
+ (s) => s.hasHydrated,
+ );
+ const markPostHogWebFeedbackSeen = usePostHogWebFeedbackStore(
+ (s) => s.markSeen,
+ );
+
// "PostHog Web" opens the feedback modal first and performs its navigation
// only once the modal is submitted or skipped.
const handleFeedbackFinished = () => {
const finishedMode = feedbackMode;
setFeedbackMode(null);
if (finishedMode === "posthog-web" && posthogWebUrl) {
+ markPostHogWebFeedbackSeen();
void openUrlInBrowser(posthogWebUrl);
}
};
const handleOpenPostHogWeb = () => {
track(ANALYTICS_EVENTS.POSTHOG_WEB_OPENED);
+ // Only skip the intercept once the persisted flag has hydrated, so a stale
+ // pre-hydration default can't wrongly re-show it.
+ if (posthogWebFeedbackHydrated && posthogWebFeedbackSeen && posthogWebUrl) {
+ void openUrlInBrowser(posthogWebUrl);
+ return;
+ }
setFeedbackMode("posthog-web");
};
const {