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 the welcome dialog reopening for invitees (#112647)

Rafael Audibert67dfdd435eb7
diff --git a/frontend/src/generated/core/api.schemas.ts b/frontend/src/generated/core/api.schemas.ts
index 50e25291ef9a..0980bda1965e 100644
--- a/frontend/src/generated/core/api.schemas.ts
+++ b/frontend/src/generated/core/api.schemas.ts
@@ -4764,6 +4764,11 @@ export interface OrganizationApi {
readonly created_at: string
readonly updated_at: string
readonly membership_level: OrganizationMembershipLevelEnumApi
+ /**
+ * When the requesting user joined this organization. Null if the user is not a member.
+ * @nullable
+ */
+ readonly membership_joined_at: string | null
readonly plugins_access_level: OrganizationPluginsAccessLevelEnumApi
readonly teams: readonly OrganizationApiTeamsItem[]
readonly projects: readonly OrganizationApiProjectsItem[]
diff --git a/frontend/src/scenes/welcome/WelcomeDialog.stories.tsx b/frontend/src/scenes/welcome/WelcomeDialog.stories.tsx
index cbe66d45331b..17f98ec4c39f 100644
--- a/frontend/src/scenes/welcome/WelcomeDialog.stories.tsx
+++ b/frontend/src/scenes/welcome/WelcomeDialog.stories.tsx
@@ -8,7 +8,7 @@ import { activeCloudRunLogic } from 'scenes/onboarding/shared/wizard-sync/active
import { userLogic } from 'scenes/userLogic'
import { mswDecorator } from '~/mocks/browser'
-import { UserType } from '~/types'
+import { OrganizationType, UserType } from '~/types'
import { WelcomeDialog } from './WelcomeDialog'
import { welcomeDialogLogic } from './welcomeDialogLogic'
@@ -120,8 +120,15 @@ const EMPTY_PAYLOAD = {
is_organization_first_user: false,
}
+// The dialog only opens in the first weeks of org membership, so join the day before `mockDate`.
+const RECENTLY_JOINED_ORGANIZATION: OrganizationType = {
+ ...MOCK_DEFAULT_USER.organization!,
+ membership_joined_at: '2026-04-16T00:00:00Z',
+}
+
const INVITED_USER: UserType = {
...MOCK_DEFAULT_USER,
+ organization: RECENTLY_JOINED_ORGANIZATION,
first_name: 'Fern',
is_organization_first_user: false,
}
@@ -129,6 +136,7 @@ const INVITED_USER: UserType = {
// A partner-provisioned account: no inviter (first org user), onboarding skipped as 'provisioned'.
const PROVISIONED_USER: UserType = {
...MOCK_DEFAULT_USER,
+ organization: RECENTLY_JOINED_ORGANIZATION,
first_name: 'Robin',
is_organization_first_user: true,
onboarding_skipped_reason: 'provisioned',
diff --git a/frontend/src/scenes/welcome/WelcomeDialog.tsx b/frontend/src/scenes/welcome/WelcomeDialog.tsx
index 20d209a35a24..747750e190bf 100644
--- a/frontend/src/scenes/welcome/WelcomeDialog.tsx
+++ b/frontend/src/scenes/welcome/WelcomeDialog.tsx
@@ -16,7 +16,7 @@ import { ProductsInUseCard } from './cards/ProductsInUseCard'
import { RecentActivityCard } from './cards/RecentActivityCard'
import { SuggestedNextStepsCard } from './cards/SuggestedNextStepsCard'
import { TeamMembersCard } from './cards/TeamMembersCard'
-import { wasWelcomeDismissed, welcomeDialogLogic } from './welcomeDialogLogic'
+import { welcomeDialogLogic } from './welcomeDialogLogic'
// The welcome dialog is allowed to auto-open only on these scenes. The welcome flow's purpose
// is to orient an invitee on the home of the product — opening it as an overlay over a deep-link
@@ -25,23 +25,18 @@ import { wasWelcomeDismissed, welcomeDialogLogic } from './welcomeDialogLogic'
// primary dashboard when one is configured, so first-visit invitees land there instead of home.
const WELCOME_DIALOG_ALLOWED_SCENES = new Set<Scene>([Scene.ProjectHomepage, Scene.Dashboard])
-/** 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.
+/** Only render the welcome dialog when it is due. 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.
*
* 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 { shouldShowDialog } = useValues(welcomeDialogLogic)
const { sceneId } = useValues(sceneLogic)
- // Invitees see it as before; partner-provisioned accounts (no inviter) get it too.
- const eligible = !!user && (user.is_organization_first_user === false || isProvisionedUser)
- if (!eligible || !user || wasWelcomeDismissed(user.uuid, user.organization?.id)) {
- return null
- }
- if (!sceneId || !WELCOME_DIALOG_ALLOWED_SCENES.has(sceneId as Scene)) {
+ if (!shouldShowDialog || !sceneId || !WELCOME_DIALOG_ALLOWED_SCENES.has(sceneId as Scene)) {
return null
}
return <WelcomeDialog />
diff --git a/frontend/src/scenes/welcome/welcomeDialogLogic.test.ts b/frontend/src/scenes/welcome/welcomeDialogLogic.test.ts
index 100cb00be6bf..4174b2c3d8ea 100644
--- a/frontend/src/scenes/welcome/welcomeDialogLogic.test.ts
+++ b/frontend/src/scenes/welcome/welcomeDialogLogic.test.ts
@@ -13,13 +13,22 @@ import { welcomeDialogLogic } from './welcomeDialogLogic'
jest.mock('posthog-js')
+const DAY_MS = 24 * 60 * 60 * 1000
+
+const RECENTLY_JOINED_ORGANIZATION = {
+ ...MOCK_DEFAULT_USER.organization!,
+ membership_joined_at: new Date().toISOString(),
+}
+
const INVITED_USER: UserType = {
...MOCK_DEFAULT_USER,
+ organization: RECENTLY_JOINED_ORGANIZATION,
is_organization_first_user: false,
}
const ORG_CREATOR_USER: UserType = {
...MOCK_DEFAULT_USER,
+ organization: RECENTLY_JOINED_ORGANIZATION,
is_organization_first_user: true,
}
@@ -27,6 +36,7 @@ const ORG_CREATOR_USER: UserType = {
// 'provisioned'. Should still get the welcome dialog even though it isn't an invitee.
const PROVISIONED_USER: UserType = {
...MOCK_DEFAULT_USER,
+ organization: RECENTLY_JOINED_ORGANIZATION,
is_organization_first_user: true,
onboarding_skipped_reason: 'provisioned',
}
@@ -64,10 +74,9 @@ describe('welcomeDialogLogic', () => {
let logic: ReturnType<typeof welcomeDialogLogic.build>
beforeEach(() => {
- // The dialog persists dismissal in localStorage and "looked around" in sessionStorage —
- // clear both so a prior test doesn't carry over and suppress the dialog.
+ // The dialog persists dismissals and closes in localStorage, so clear it to stop a prior
+ // test from suppressing the dialog.
window.localStorage.clear()
- window.sessionStorage.clear()
;(posthog.capture as jest.Mock).mockClear()
useMocks({
get: {
@@ -106,32 +115,20 @@ describe('welcomeDialogLogic', () => {
expect(logic.values.shouldShowDialog).toBe(true)
})
- it('does not reopen for a user who has already dismissed', async () => {
- window.localStorage.setItem(
- `posthog_welcome_dismissed:${INVITED_USER.uuid}:${INVITED_USER.organization?.id}`,
- '1'
- )
+ it('does not reopen in a new tab after "Don\'t show again"', async () => {
userLogic.actions.loadUserSuccess(INVITED_USER)
logic = welcomeDialogLogic()
logic.mount()
+ await expectLogic(logic).toDispatchActions(['loadWelcomeDataSuccess'])
+ logic.actions.dismissWelcome()
expect(logic.values.shouldShowDialog).toBe(false)
- await expectLogic(logic).toNotHaveDispatchedActions(['loadWelcomeData'])
- })
- it('persists dismissal to localStorage so the dialog does not reopen', async () => {
- userLogic.actions.loadUserSuccess(INVITED_USER)
+ logic.unmount()
logic = welcomeDialogLogic()
logic.mount()
-
- await expectLogic(logic).toDispatchActions(['loadWelcomeDataSuccess'])
- logic.actions.dismissWelcome()
- expect(
- window.localStorage.getItem(
- `posthog_welcome_dismissed:${INVITED_USER.uuid}:${INVITED_USER.organization?.id}`
- )
- ).toBe('1')
expect(logic.values.shouldShowDialog).toBe(false)
+ await expectLogic(logic).toNotHaveDispatchedActions(['loadWelcomeData'])
})
it.each(['start_exploring', 'modal_close', 'ask_max_card'] as const)(
@@ -151,6 +148,23 @@ describe('welcomeDialogLogic', () => {
}
)
+ it.each([
+ { control: 'closeDialog', close: (): void => logic.actions.closeDialog('start_exploring') },
+ { control: 'trackCardClick', close: (): void => logic.actions.trackCardClick('dashboards', '/dashboard/42') },
+ ])('stays closed in a new tab after $control', async ({ close }) => {
+ userLogic.actions.loadUserSuccess(INVITED_USER)
+ logic = welcomeDialogLogic()
+ logic.mount()
+
+ await expectLogic(logic).toDispatchActions(['loadWelcomeDataSuccess'])
+ close()
+
+ logic.unmount()
+ logic = welcomeDialogLogic()
+ logic.mount()
+ expect(logic.values.shouldShowDialog).toBe(false)
+ })
+
it('tracks card interactions', async () => {
userLogic.actions.loadUserSuccess(INVITED_USER)
logic = welcomeDialogLogic()
@@ -178,4 +192,28 @@ describe('welcomeDialogLogic', () => {
expect(logic.values.organizationName).toBe('Beta Corp')
await expectLogic(logic).toDispatchActions(['resetForOrgChange', 'loadWelcomeData'])
})
+
+ it.each([
+ { case: 'in the first week', joinedDaysAgo: 1, closedOnDay: null, expected: true },
+ { case: 'on the last day of the window', joinedDaysAgo: 13, closedOnDay: null, expected: true },
+ { case: 'once two weeks have passed', joinedDaysAgo: 14, closedOnDay: null, expected: false },
+ { case: 'long after joining', joinedDaysAgo: 30, closedOnDay: null, expected: false },
+ { case: 'after a close in the same week', joinedDaysAgo: 6, closedOnDay: 1, expected: false },
+ { case: 'in the week after a close', joinedDaysAgo: 7, closedOnDay: 1, expected: true },
+ { case: 'after a close in the second week', joinedDaysAgo: 13, closedOnDay: 8, expected: false },
+ ])('shouldShowDialog is $expected $case', ({ joinedDaysAgo, closedOnDay, expected }) => {
+ const joinedAt = Date.now() - joinedDaysAgo * DAY_MS
+ const user: UserType = {
+ ...INVITED_USER,
+ organization: { ...RECENTLY_JOINED_ORGANIZATION, membership_joined_at: new Date(joinedAt).toISOString() },
+ }
+ userLogic.actions.loadUserSuccess(user)
+ logic = welcomeDialogLogic()
+ logic.mount()
+ if (closedOnDay !== null) {
+ logic.actions.markClosed(logic.values.membershipKey!, joinedAt + closedOnDay * DAY_MS)
+ }
+
+ expect(logic.values.shouldShowDialog).toBe(expected)
+ })
})
diff --git a/frontend/src/scenes/welcome/welcomeDialogLogic.ts b/frontend/src/scenes/welcome/welcomeDialogLogic.ts
index d4d483f39283..8fc920ca04a1 100644
--- a/frontend/src/scenes/welcome/welcomeDialogLogic.ts
+++ b/frontend/src/scenes/welcome/welcomeDialogLogic.ts
@@ -1,4 +1,4 @@
-import { MakeLogicType, actions, connect, events, kea, listeners, path, reducers, selectors } from 'kea'
+import { MakeLogicType, actions, connect, kea, listeners, path, reducers, selectors } from 'kea'
import { loaders } from 'kea-loaders'
import { subscriptions } from 'kea-subscriptions'
import posthog from 'posthog-js'
@@ -75,83 +75,29 @@ export type WelcomeCardKind = 'members' | 'activity' | 'dashboards' | 'products'
* 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 closes it without dismissing it, which avoids re-opening on every project-home remount.
-const SESSION_LOOKED_AROUND_KEY = 'posthog_welcome_looked_around'
+const WEEK_MS = 7 * 24 * 60 * 60 * 1000
+const WELCOME_WINDOW_WEEKS = 2
-function dismissedKey(userUuid: string | undefined, orgId: string | undefined): string | null {
- return userUuid && orgId ? `${LOCAL_DISMISSED_KEY_PREFIX}${userUuid}:${orgId}` : null
-}
-
-function rememberDismissed(userUuid: string | undefined, orgId: string | undefined): void {
- const key = dismissedKey(userUuid, orgId)
- if (typeof window === 'undefined' || !key) {
- return
- }
- try {
- window.localStorage.setItem(key, '1')
- } catch {
- // localStorage can be unavailable (privacy mode, etc.) — degrade gracefully.
- }
-}
-
-export function wasWelcomeDismissed(userUuid: string | undefined, orgId: string | undefined): boolean {
- return wasDismissed(userUuid, orgId)
-}
-
-function wasDismissed(userUuid: string | undefined, orgId: string | undefined): boolean {
- const key = dismissedKey(userUuid, orgId)
- if (typeof window === 'undefined' || !key) {
- return false
- }
- try {
- return window.localStorage.getItem(key) === '1'
- } catch {
- return false
- }
-}
-
-function rememberLookedAround(orgId: string | undefined): void {
- if (typeof window === 'undefined' || !orgId) {
- return
- }
- try {
- window.sessionStorage.setItem(SESSION_LOOKED_AROUND_KEY, orgId)
- } catch {
- // sessionStorage can be unavailable (privacy mode, etc.) — degrade gracefully.
- }
-}
-
-function wasLookedAround(orgId: string | undefined): boolean {
- if (typeof window === 'undefined' || !orgId) {
- return false
- }
- try {
- return window.sessionStorage.getItem(SESSION_LOOKED_AROUND_KEY) === orgId
- } catch {
- return false
- }
+function weeksSince(start: number, at: number): number {
+ return Math.floor((at - start) / WEEK_MS)
}
// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
export interface welcomeDialogLogicValues {
isProvisionedUser: boolean // userLogic
user: UserType | null // userLogic
+ closedAt: Record<string, number>
+ dismissedMemberships: Record<string, boolean>
hasLoadedOnce: boolean
interactedCards: Record<WelcomeCardKind, boolean>
inviter: WelcomeInviter | null
- locallyClosed: boolean
+ membershipKey: string | null
organizationName: string
popularDashboards: WelcomePopularDashboard[]
productsInUse: string[]
recentActivity: WelcomeRecentActivity[]
shouldShowDialog: boolean
shownAt: number | null
- storageTick: number
suggestedNextSteps: WelcomeSuggestedStep[]
teamMembers: WelcomeTeamMember[]
welcomeData: WelcomePayload
@@ -161,9 +107,6 @@ export interface welcomeDialogLogicValues {
// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
export interface welcomeDialogLogicActions {
- acknowledgeStorageChange: () => {
- value: true
- }
closeDialog: (source: WelcomeCloseSource) => {
source: WelcomeCloseSource
}
@@ -188,6 +131,16 @@ export interface welcomeDialogLogicActions {
markCardInteracted: (card: WelcomeCardKind) => {
card: WelcomeCardKind
}
+ markClosed: (
+ membershipKey: string,
+ closedAt: number
+ ) => {
+ closedAt: number
+ membershipKey: string
+ }
+ markDismissed: (membershipKey: string) => {
+ membershipKey: string
+ }
markShown: () => {
value: true
}
@@ -216,11 +169,13 @@ export interface welcomeDialogLogicMeta {
productsInUse: (welcomeData: WelcomePayload) => string[]
suggestedNextSteps: (welcomeData: WelcomePayload) => WelcomeSuggestedStep[]
organizationName: (welcomeData: WelcomePayload, user: UserType | null) => string
+ membershipKey: (user: UserType | null) => string | null
shouldShowDialog: (
user: UserType | null,
isProvisionedUser: boolean,
- locallyClosed: boolean,
- storageTick: number
+ membershipKey: string | null,
+ dismissedMemberships: Record<string, boolean>,
+ closedAt: Record<string, number>
) => boolean
}
}
@@ -247,9 +202,8 @@ export const welcomeDialogLogic = kea<welcomeDialogLogicType>([
markCardInteracted: (card: WelcomeCardKind) => ({ card }),
markShown: true,
setWelcomeDataError: (error: boolean) => ({ error }),
- // Bumped when another tab writes to localStorage (dismisses) so the current tab's
- // shouldShowDialog selector re-evaluates without needing a full page navigation.
- acknowledgeStorageChange: true,
+ markDismissed: (membershipKey: string) => ({ membershipKey }),
+ markClosed: (membershipKey: string, closedAt: number) => ({ membershipKey, closedAt }),
}),
reducers({
@@ -267,13 +221,20 @@ export const welcomeDialogLogic = kea<welcomeDialogLogicType>([
resetForOrgChange: () => ({}) as Record<WelcomeCardKind, boolean>,
},
],
- // Hide the dialog optimistically so it doesn't flash back during the loadUser refetch.
- locallyClosed: [
- false,
+ // Both persisted maps are keyed by `membershipKey`, so a contractor/agency who works across
+ // multiple orgs gets a fresh welcome in each org. "Don't show again" hides the dialog for good.
+ dismissedMemberships: [
+ {} as Record<string, boolean>,
+ { persist: true },
{
- dismissWelcome: () => true,
- closeDialog: () => true,
- resetForOrgChange: () => false,
+ markDismissed: (state, { membershipKey }) => ({ ...state, [membershipKey]: true }),
+ },
+ ],
+ closedAt: [
+ {} as Record<string, number>,
+ { persist: true },
+ {
+ markClosed: (state, { membershipKey, closedAt }) => ({ ...state, [membershipKey]: closedAt }),
},
],
hasLoadedOnce: [
@@ -291,15 +252,6 @@ export const welcomeDialogLogic = kea<welcomeDialogLogicType>([
resetForOrgChange: () => false,
},
],
- // A monotonically-incrementing counter that shouldShowDialog depends on so cross-tab
- // localStorage changes trigger a re-computation of the selector.
- storageTick: [
- 0,
- {
- acknowledgeStorageChange: (state) => state + 1,
- resetForOrgChange: () => 0,
- },
- ],
}),
loaders(({ actions }) => ({
@@ -355,28 +307,35 @@ export const welcomeDialogLogic = kea<welcomeDialogLogicType>([
return data.organization_name || userOrgName || ''
},
],
- // Open for invitees (not the org creator) and for partner-provisioned accounts (which have no
- // inviter, so they'd otherwise never see it), when not already dismissed.
- // `storageTick` is in the dependency list so cross-tab localStorage changes re-run the selector.
+ membershipKey: [
+ (s) => [s.user],
+ (user: UserType | null): string | null =>
+ user?.uuid && user.organization?.id ? `${user.uuid}:${user.organization.id}` : null,
+ ],
shouldShowDialog: [
- (s) => [s.user, s.isProvisionedUser, s.locallyClosed, s.storageTick],
+ (s) => [s.user, s.isProvisionedUser, s.membershipKey, s.dismissedMemberships, s.closedAt],
(
- user: null | import('../../types').UserType,
+ user: UserType | null,
isProvisionedUser: boolean,
- locallyClosed: boolean
+ membershipKey: string | null,
+ dismissedMemberships: Record<string, boolean>,
+ closedAt: Record<string, number>
): boolean => {
- if (!user || (user.is_organization_first_user !== false && !isProvisionedUser)) {
+ // Open for invitees (not the org creator) and for partner-provisioned accounts (which have
+ // no inviter, so they'd otherwise never see it).
+ if (!user || !membershipKey || (user.is_organization_first_user !== false && !isProvisionedUser)) {
return false
}
- const orgId = user.organization?.id
- if (wasDismissed(user.uuid, orgId)) {
+ const joinedAt = Date.parse(user.organization?.membership_joined_at ?? '')
+ if (Number.isNaN(joinedAt) || dismissedMemberships[membershipKey]) {
return false
}
- if (locallyClosed) {
+ const currentWeek = weeksSince(joinedAt, Date.now())
+ if (currentWeek >= WELCOME_WINDOW_WEEKS) {
return false
}
- // Also suppress if the user opted to look around earlier in this tab's session.
- return !wasLookedAround(orgId)
+ const lastClosedAt = closedAt[membershipKey]
+ return lastClosedAt === undefined || weeksSince(joinedAt, lastClosedAt) < currentWeek
},
],
}),
@@ -407,8 +366,9 @@ export const welcomeDialogLogic = kea<welcomeDialogLogicType>([
})
},
closeDialog: ({ source }) => {
- // Persist the close across remounts in the same tab.
- rememberLookedAround(values.user?.organization?.id)
+ if (values.membershipKey) {
+ actions.markClosed(values.membershipKey, Date.now())
+ }
posthog.capture('welcome_screen_closed', {
source,
time_on_screen_ms: values.shownAt ? Date.now() - values.shownAt : null,
@@ -418,7 +378,9 @@ export const welcomeDialogLogic = kea<welcomeDialogLogicType>([
dismissWelcome: () => {
const interactedCount = Object.keys(values.interactedCards).length
const timeOnScreen = values.shownAt ? Date.now() - values.shownAt : null
- rememberDismissed(values.user?.uuid, values.user?.organization?.id)
+ if (values.membershipKey) {
+ actions.markDismissed(values.membershipKey)
+ }
posthog.capture('welcome_screen_dismissed', {
time_on_screen_ms: timeOnScreen,
cards_interacted_with: interactedCount,
@@ -426,9 +388,10 @@ export const welcomeDialogLogic = kea<welcomeDialogLogicType>([
},
trackCardClick: ({ card, targetHref }) => {
actions.markCardInteracted(card)
- // Clicking an in-app card link counts as engagement — persist the "looked around"
- // marker so the dialog doesn't re-appear the next time the user lands on home.
- rememberLookedAround(values.user?.organization?.id)
+ // Clicking an in-app card link counts as engagement, so it hides the dialog like a close.
+ if (values.membershipKey) {
+ actions.markClosed(values.membershipKey, Date.now())
+ }
posthog.capture('welcome_screen_card_clicked', {
card,
target_href: targetHref,
@@ -452,29 +415,4 @@ export const welcomeDialogLogic = kea<welcomeDialogLogicType>([
}
},
})),
-
- // Subscribe to the browser's storage event so that dismissal from another tab propagates
- // to this one. The event only fires in *other* tabs (not the one that performed the write),
- // so the acting tab is already in sync via its own reducers.
- events(({ actions, cache }) => ({
- afterMount: () => {
- if (typeof window === 'undefined') {
- return
- }
- const handler = (event: StorageEvent): void => {
- if (event.key && event.key.startsWith(LOCAL_DISMISSED_KEY_PREFIX)) {
- actions.acknowledgeStorageChange()
- }
- }
- window.addEventListener('storage', handler)
- cache.storageHandler = handler
- },
- beforeUnmount: () => {
- if (typeof window === 'undefined' || !cache.storageHandler) {
- return
- }
- window.removeEventListener('storage', cache.storageHandler)
- cache.storageHandler = undefined
- },
- })),
])
diff --git a/frontend/src/types.ts b/frontend/src/types.ts
index 1dd4b552fce9..e26375a03738 100644
--- a/frontend/src/types.ts
+++ b/frontend/src/types.ts
@@ -605,6 +605,7 @@ interface OrganizationMetadata {
}
export interface OrganizationType extends OrganizationBasicType {
+ membership_joined_at?: string | null
created_at: string
updated_at: string
plugins_access_level: PluginsAccessLevel
diff --git a/posthog/api/organization.py b/posthog/api/organization.py
index 8ae5ed30a916..4266c8869a1f 100644
--- a/posthog/api/organization.py
+++ b/posthog/api/organization.py
@@ -213,6 +213,9 @@ class OrganizationSerializer(
serializers.ModelSerializer, UserPermissionsSerializerMixin, UserAccessControlSerializerMixin
):
membership_level = serializers.SerializerMethodField()
+ membership_joined_at = serializers.SerializerMethodField(
+ help_text="When the requesting user joined this organization. Null if the user is not a member."
+ )
teams = serializers.SerializerMethodField()
projects = serializers.SerializerMethodField()
metadata = serializers.SerializerMethodField()
@@ -250,6 +253,7 @@ class OrganizationSerializer(
"created_at",
"updated_at",
"membership_level",
+ "membership_joined_at",
"plugins_access_level",
"teams",
"projects",
@@ -285,6 +289,7 @@ class OrganizationSerializer(
"created_at",
"updated_at",
"membership_level",
+ "membership_joined_at",
"plugins_access_level",
"teams",
"projects",
@@ -331,6 +336,11 @@ class OrganizationSerializer(
membership = self.user_permissions.organization_memberships.get(organization.pk)
return OrganizationMembership.Level(membership.level) if membership is not None else None
+ @extend_schema_field(serializers.DateTimeField(allow_null=True))
+ def get_membership_joined_at(self, organization: Organization) -> str | None:
+ membership = self.user_permissions.organization_memberships.get(organization.pk)
+ return membership.joined_at.isoformat() if membership is not None else None
+
@tracer.start_as_current_span("organization_serializer.teams")
def get_teams(self, instance: Organization) -> list[dict[str, Any]]:
user_id = _resolve_cached_user_id(self.context)
diff --git a/posthog/api/test/test_user.py b/posthog/api/test/test_user.py
index e0f4a621ac96..cf1be894d05c 100644
--- a/posthog/api/test/test_user.py
+++ b/posthog/api/test/test_user.py
@@ -116,6 +116,10 @@ class TestUserAPI(APIBaseTest):
self.assertEqual(response_data["organization"]["name"], self.organization.name)
self.assertEqual(response_data["organization"]["membership_level"], 1)
+ self.assertEqual(
+ response_data["organization"]["membership_joined_at"],
+ self.organization_membership.joined_at.isoformat(),
+ )
self.assertEqual(response_data["organization"]["teams"][0]["id"], self.team.id)
self.assertEqual(response_data["organization"]["teams"][0]["name"], self.team.name)
self.assertNotIn(
diff --git a/products/platform_features/frontend/generated/api.schemas.ts b/products/platform_features/frontend/generated/api.schemas.ts
index 883085e2b4d4..dce5b53d7f7e 100644
--- a/products/platform_features/frontend/generated/api.schemas.ts
+++ b/products/platform_features/frontend/generated/api.schemas.ts
@@ -82,6 +82,11 @@ export interface OrganizationApi {
readonly created_at: string
readonly updated_at: string
readonly membership_level: OrganizationMembershipLevelEnumApi
+ /**
+ * When the requesting user joined this organization. Null if the user is not a member.
+ * @nullable
+ */
+ readonly membership_joined_at: string | null
readonly plugins_access_level: OrganizationPluginsAccessLevelEnumApi
readonly teams: readonly OrganizationApiTeamsItem[]
readonly projects: readonly OrganizationApiProjectsItem[]
@@ -192,6 +197,11 @@ export interface PatchedOrganizationApi {
readonly created_at?: string
readonly updated_at?: string
readonly membership_level?: OrganizationMembershipLevelEnumApi
+ /**
+ * When the requesting user joined this organization. Null if the user is not a member.
+ * @nullable
+ */
+ readonly membership_joined_at?: string | null
readonly plugins_access_level?: OrganizationPluginsAccessLevelEnumApi
readonly teams?: readonly PatchedOrganizationApiTeamsItem[]
readonly projects?: readonly PatchedOrganizationApiProjectsItem[]
diff --git a/services/mcp/src/api/generated.ts b/services/mcp/src/api/generated.ts
index 95218b0d2f0b..7c59a01a1e8b 100644
--- a/services/mcp/src/api/generated.ts
+++ b/services/mcp/src/api/generated.ts
@@ -66610,6 +66610,11 @@ export namespace Schemas {
readonly created_at: string;
readonly updated_at: string;
readonly membership_level: OrganizationMembershipLevelEnum;
+ /**
+ * When the requesting user joined this organization. Null if the user is not a member.
+ * @nullable
+ */
+ readonly membership_joined_at: string | null;
readonly plugins_access_level: OrganizationPluginsAccessLevelEnum;
readonly teams: readonly OrganizationTeamsItem[];
readonly projects: readonly OrganizationProjectsItem[];
@@ -79593,6 +79598,11 @@ export namespace Schemas {
readonly created_at?: string;
readonly updated_at?: string;
readonly membership_level?: OrganizationMembershipLevelEnum;
+ /**
+ * When the requesting user joined this organization. Null if the user is not a member.
+ * @nullable
+ */
+ readonly membership_joined_at?: string | null;
readonly plugins_access_level?: OrganizationPluginsAccessLevelEnum;
readonly teams?: readonly PatchedOrganizationTeamsItem[];
readonly projects?: readonly PatchedOrganizationProjectsItem[];