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(onboarding): stop rendering the welcome dialog twice on home (#95513)

posthog[bot]d8101bb5f83a
diff --git a/frontend/src/scenes/project-homepage/ProjectHomepage.tsx b/frontend/src/scenes/project-homepage/ProjectHomepage.tsx
index c8ca51beff6b..c615f924d2e0 100644
--- a/frontend/src/scenes/project-homepage/ProjectHomepage.tsx
+++ b/frontend/src/scenes/project-homepage/ProjectHomepage.tsx
@@ -1,24 +1,10 @@
import './ProjectHomepage.scss'
-import { useValues } from 'kea'
-
import { projectHomepageLogic } from 'scenes/project-homepage/projectHomepageLogic'
import { SceneExport } from 'scenes/sceneTypes'
-import { userLogic } from 'scenes/userLogic'
-import { WelcomeDialog } from 'scenes/welcome/WelcomeDialog'
-import { wasWelcomeDismissed } from 'scenes/welcome/welcomeDialogLogic'
import { AiFirstHomepage } from './ai-first/AiFirstHomepage'
-/** Only mount the welcome dialog (and its kea logic) for users actually eligible to see it. */
-function MaybeWelcomeDialog(): JSX.Element | null {
- const { user } = useValues(userLogic)
- if (!user || user.is_organization_first_user !== false || wasWelcomeDismissed(user.uuid, user.organization?.id)) {
- return null
- }
- return <WelcomeDialog />
-}
-
export const scene: SceneExport = {
component: ProjectHomepage,
logic: projectHomepageLogic,
@@ -28,7 +14,6 @@ export function ProjectHomepage(): JSX.Element {
return (
<div className="flex-1 min-h-0">
<AiFirstHomepage />
- <MaybeWelcomeDialog />
</div>
)
}
diff --git a/frontend/src/scenes/welcome/WelcomeDialog.tsx b/frontend/src/scenes/welcome/WelcomeDialog.tsx
index 58894bfaacfe..20d209a35a24 100644
--- a/frontend/src/scenes/welcome/WelcomeDialog.tsx
+++ b/frontend/src/scenes/welcome/WelcomeDialog.tsx
@@ -28,7 +28,11 @@ const WELCOME_DIALOG_ALLOWED_SCENES = new Set<Scene>([Scene.ProjectHomepage, Sce
/** Only mount the welcome dialog (and its kea logic) for users actually eligible to see it.
* Lives in GlobalModals so it can render regardless of which scene the user lands on after
* signup (project home, primary dashboard, etc.). Scene gating ensures the dialog only auto-opens
- * on the home / primary-dashboard scenes, not over deep-linked settings/billing/replay pages. */
+ * on the home / primary-dashboard scenes, not over deep-linked settings/billing/replay pages.
+ *
+ * This must stay the only mount of the dialog. Two mounts give two react-modal instances at the
+ * same z-index, and the overlay of the one on top covers the buttons of the one below, so the
+ * user clicks a button that receives nothing. */
export function MaybeWelcomeDialog(): JSX.Element | null {
const { user, isProvisionedUser } = useValues(userLogic)
const { sceneId } = useValues(sceneLogic)
@@ -80,7 +84,7 @@ export function WelcomeDialog(): JSX.Element | null {
return (
<LemonModal
isOpen={shouldShowDialog}
- onClose={() => closeDialog()}
+ onClose={() => closeDialog('modal_close')}
width={640}
title={`Welcome to ${organizationName || 'PostHog'}`}
description={inviterLine}
@@ -90,7 +94,11 @@ export function WelcomeDialog(): JSX.Element | null {
<LemonButton type="tertiary" onClick={() => dismissWelcome()} data-attr="welcome-dismiss">
Don't show again
</LemonButton>
- <LemonButton type="primary" onClick={() => closeDialog()} data-attr="welcome-close">
+ <LemonButton
+ type="primary"
+ onClick={() => closeDialog('start_exploring')}
+ data-attr="welcome-close"
+ >
Start exploring
</LemonButton>
</div>
diff --git a/frontend/src/scenes/welcome/cards/AskMaxCard.tsx b/frontend/src/scenes/welcome/cards/AskMaxCard.tsx
index 4e7a0462fe3f..192d23bb53ba 100644
--- a/frontend/src/scenes/welcome/cards/AskMaxCard.tsx
+++ b/frontend/src/scenes/welcome/cards/AskMaxCard.tsx
@@ -15,7 +15,7 @@ export function AskMaxCard(): JSX.Element {
const handleActivate = (): void => {
trackCardClick('next_steps', 'sidepanel:max')
- closeDialog()
+ closeDialog('ask_max_card')
openSidePanel(SidePanelTab.Max)
}
diff --git a/frontend/src/scenes/welcome/welcomeDialogLogic.test.ts b/frontend/src/scenes/welcome/welcomeDialogLogic.test.ts
index 4eaeb958e20f..100cb00be6bf 100644
--- a/frontend/src/scenes/welcome/welcomeDialogLogic.test.ts
+++ b/frontend/src/scenes/welcome/welcomeDialogLogic.test.ts
@@ -1,6 +1,7 @@
import { MOCK_DEFAULT_USER } from 'lib/api.mock'
import { expectLogic } from 'kea-test-utils'
+import posthog from 'posthog-js'
import { userLogic } from 'scenes/userLogic'
@@ -10,6 +11,8 @@ import { UserType } from '~/types'
import { welcomeDialogLogic } from './welcomeDialogLogic'
+jest.mock('posthog-js')
+
const INVITED_USER: UserType = {
...MOCK_DEFAULT_USER,
is_organization_first_user: false,
@@ -65,6 +68,7 @@ describe('welcomeDialogLogic', () => {
// clear both so a prior test doesn't carry over and suppress the dialog.
window.localStorage.clear()
window.sessionStorage.clear()
+ ;(posthog.capture as jest.Mock).mockClear()
useMocks({
get: {
'/api/organizations/@current/welcome/current/': mockPayload,
@@ -130,16 +134,22 @@ describe('welcomeDialogLogic', () => {
expect(logic.values.shouldShowDialog).toBe(false)
})
- it('closes locally on closeDialog so it does not flash back', async () => {
- userLogic.actions.loadUserSuccess(INVITED_USER)
- logic = welcomeDialogLogic()
- logic.mount()
-
- await expectLogic(logic).toDispatchActions(['loadWelcomeDataSuccess'])
- expect(logic.values.shouldShowDialog).toBe(true)
- logic.actions.closeDialog()
- expect(logic.values.shouldShowDialog).toBe(false)
- })
+ it.each(['start_exploring', 'modal_close', 'ask_max_card'] as const)(
+ 'closes locally on closeDialog from %s and reports which control was used',
+ async (source) => {
+ userLogic.actions.loadUserSuccess(INVITED_USER)
+ logic = welcomeDialogLogic()
+ logic.mount()
+
+ await expectLogic(logic).toDispatchActions(['loadWelcomeDataSuccess'])
+ expect(logic.values.shouldShowDialog).toBe(true)
+ logic.actions.closeDialog(source)
+ expect(logic.values.shouldShowDialog).toBe(false)
+ expect(
+ (posthog.capture as jest.Mock).mock.calls.filter(([name]) => name === 'welcome_screen_closed')
+ ).toEqual([['welcome_screen_closed', expect.objectContaining({ source })]])
+ }
+ )
it('tracks card interactions', async () => {
userLogic.actions.loadUserSuccess(INVITED_USER)
diff --git a/frontend/src/scenes/welcome/welcomeDialogLogic.ts b/frontend/src/scenes/welcome/welcomeDialogLogic.ts
index ea1763f2a532..ec31926498f7 100644
--- a/frontend/src/scenes/welcome/welcomeDialogLogic.ts
+++ b/frontend/src/scenes/welcome/welcomeDialogLogic.ts
@@ -71,12 +71,16 @@ const EMPTY_PAYLOAD: WelcomePayload = {
export type WelcomeCardKind = 'members' | 'activity' | 'dashboards' | 'products' | 'next_steps'
+/** Which control closed the dialog. Reported as the `source` property of `welcome_screen_closed`,
+ * which is how we tell a deliberate "Start exploring" from an escape through the X. */
+export type WelcomeCloseSource = 'start_exploring' | 'modal_close' | 'ask_max_card'
+
// LocalStorage key used to suppress the dialog on subsequent visits after the user has dismissed it.
// Scoped per user AND organization so a contractor/agency who works across multiple orgs gets
// a fresh welcome in each org instead of only ever seeing it once across their lifetime.
const LOCAL_DISMISSED_KEY_PREFIX = 'posthog_welcome_dismissed:'
// SessionStorage key used to suppress the dialog for the remainder of a tab's session after
-// the user clicks "I'll look around" — avoids re-opening on every project-home remount.
+// the user closes it without dismissing it, which avoids re-opening on every project-home remount.
const SESSION_LOOKED_AROUND_KEY = 'posthog_welcome_looked_around'
function dismissedKey(userUuid: string | undefined, orgId: string | undefined): string | null {
@@ -160,8 +164,8 @@ export interface welcomeDialogLogicActions {
acknowledgeStorageChange: () => {
value: true
}
- closeDialog: () => {
- value: true
+ closeDialog: (source: WelcomeCloseSource) => {
+ source: WelcomeCloseSource
}
dismissWelcome: () => {
value: true
@@ -237,7 +241,7 @@ export const welcomeDialogLogic = kea<welcomeDialogLogicType>([
actions({
dismissWelcome: true,
- closeDialog: true,
+ closeDialog: (source: WelcomeCloseSource) => ({ source }),
resetForOrgChange: true,
trackCardClick: (card: WelcomeCardKind, targetHref: string) => ({ card, targetHref }),
markCardInteracted: (card: WelcomeCardKind) => ({ card }),
@@ -401,9 +405,14 @@ export const welcomeDialogLogic = kea<welcomeDialogLogicType>([
from_invite_type: welcomeData.inviter ? 'invite' : 'unknown',
})
},
- closeDialog: () => {
- // Persist "I'll look around" across remounts in the same tab.
+ closeDialog: ({ source }) => {
+ // Persist the close across remounts in the same tab.
rememberLookedAround(values.user?.organization?.id)
+ posthog.capture('welcome_screen_closed', {
+ source,
+ time_on_screen_ms: values.shownAt ? Date.now() - values.shownAt : null,
+ cards_interacted_with: Object.keys(values.interactedCards).length,
+ })
},
dismissWelcome: () => {
const interactedCount = Object.keys(values.interactedCards).length