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(cohorts): add realtime cohorts waitlist banner (#97057)

ruby childs83480e57bdb2
diff --git a/frontend/snapshots.yml b/frontend/snapshots.yml
index 5cc5bebed5b5..8d2d06b249c1 100644
--- a/frontend/snapshots.yml
+++ b/frontend/snapshots.yml
@@ -4040,6 +4040,10 @@ snapshots:
hash: v1.k794b7964.19da2f0798f02f14299933be9c3b20ef5884499ec72a894dd0128192ad0d8207.Q521iOqPCqWv9TaDBgIatKH6nFWs566jUYhc5M0goJA
lemon-ui-lemon-banner--success--light:
hash: v1.k794b7964.6dd73a667992a7e07145890a09b7c8bcdabf4074d7913e651e81610f622db7ea.z5RzXLIwlcBN-ce7iH6MUsEzq7oZ6ozdikDnSmZ0ecE
+ lemon-ui-lemon-banner--tall-content-top-aligned--dark:
+ hash: v1.k794b7964.9eddf2d08667c8a7cdef3387ef9f7040a8f164000cf4408503d512a552e3abe8.4qAVt7fcwCPgr9w9OuN5tzUKGB7ozyVbtA_ERiqAxnQ
+ lemon-ui-lemon-banner--tall-content-top-aligned--light:
+ hash: v1.k794b7964.a522c6504e8f5706ce5d0b90f6877da747f73e0162d5a7f44dbf0d4ae7f02b3b.Ye5GxRJnH_m_wEZDcHz6UEjrecm3jbdLS2GeofeVGx0
lemon-ui-lemon-banner--warning--dark:
hash: v1.k794b7964.ccd6919f26c9235fa5717d91865ea67120254e854af051082a47fce9bd05ed2f.y33wBGkS4iEkK_ZO_XiVBYXzh2fECsAKG4T0ZANpiyU
lemon-ui-lemon-banner--warning--light:
diff --git a/frontend/src/layout/scenes/components/FeaturePreviewSceneGate.test.tsx b/frontend/src/layout/scenes/components/FeaturePreviewSceneGate.test.tsx
index d0ca20578a1c..3d6a1a129376 100644
--- a/frontend/src/layout/scenes/components/FeaturePreviewSceneGate.test.tsx
+++ b/frontend/src/layout/scenes/components/FeaturePreviewSceneGate.test.tsx
@@ -481,10 +481,30 @@ describe('FeaturePreviewSceneGate', () => {
render(<FeaturePreviewSceneGate config={BASE_CONFIG}>{CHILDREN}</FeaturePreviewSceneGate>)
- expect(screen.getByText(/Thanks — we'll email you when it's ready/)).toBeInTheDocument()
+ expect(screen.getByText(/Thanks, we'll email you when it's ready/)).toBeInTheDocument()
expect(screen.queryByRole('switch')).not.toBeInTheDocument()
})
+ test('thanks someone who registered before waitlist surveys existed instead of asking again', () => {
+ setupMocks({ earlyAccessFeatures: [{ ...CONCEPT_FEATURE, enabled: true }], waitlistSurveysEnabled: true })
+
+ render(<FeaturePreviewSceneGate config={BASE_CONFIG}>{CHILDREN}</FeaturePreviewSceneGate>)
+
+ expect(screen.getByText(/Thanks, we'll email you when it's ready/)).toBeInTheDocument()
+ expect(screen.queryByPlaceholderText('[email protected]')).not.toBeInTheDocument()
+ })
+
+ // Matches the feature previews page: with waitlist surveys off, the one-click flow applies,
+ // so a registered user sees its disabled "Registered" state rather than the survey's thanks line.
+ test('shows a disabled Registered button to a registered user while waitlist surveys are off', () => {
+ setupMocks({ earlyAccessFeatures: [{ ...CONCEPT_FEATURE, enabled: true }], waitlistSurveysEnabled: false })
+
+ render(<FeaturePreviewSceneGate config={BASE_CONFIG}>{CHILDREN}</FeaturePreviewSceneGate>)
+
+ expect(screen.getByText('Registered').closest('button')).toHaveAttribute('aria-disabled', 'true')
+ expect(screen.queryByText(/Thanks, we'll email you when it's ready/)).not.toBeInTheDocument()
+ })
+
test('submits the waitlist survey and registers product intent', async () => {
setupMocks({ earlyAccessFeatures: [CONCEPT_FEATURE], waitlistSurveysEnabled: true })
diff --git a/frontend/src/layout/scenes/components/FeaturePreviewSceneGate.tsx b/frontend/src/layout/scenes/components/FeaturePreviewSceneGate.tsx
index 1d0aa9a96f30..ceaa7e9ed562 100644
--- a/frontend/src/layout/scenes/components/FeaturePreviewSceneGate.tsx
+++ b/frontend/src/layout/scenes/components/FeaturePreviewSceneGate.tsx
@@ -1,10 +1,10 @@
import { useActions, useValues } from 'kea'
-import { useEffect, useState } from 'react'
+import { useEffect } from 'react'
-import { IconCheck } from '@posthog/icons'
-import { LemonButton, LemonInput, LemonSwitch } from '@posthog/lemon-ui'
+import { LemonButton, LemonSwitch } from '@posthog/lemon-ui'
-import { EnrichedEarlyAccessFeature, featurePreviewsLogic } from 'lib/components/FeaturePreviews/featurePreviewsLogic'
+import { ConceptWaitlistCTA } from 'lib/components/FeaturePreviews/ConceptWaitlistCTA'
+import { featurePreviewsLogic } from 'lib/components/FeaturePreviews/featurePreviewsLogic'
import { productSetupStatusLogic } from 'lib/components/ProductEmptyState/productSetupStatusLogic'
import { ProductIntroduction } from 'lib/components/ProductIntroduction/ProductIntroduction'
import { supportLogic } from 'lib/components/Support/supportLogic'
@@ -86,7 +86,8 @@ function FeaturePreviewGateContent({
justEnrolled: boolean
}): JSX.Element {
const { earlyAccessFeatures } = useValues(featurePreviewsLogic)
- const { loadEarlyAccessFeatures, updateEarlyAccessFeatureEnrollment } = useActions(featurePreviewsLogic)
+ const { loadEarlyAccessFeatures, updateEarlyAccessFeatureEnrollment, addProductIntentForCrossSell } =
+ useActions(featurePreviewsLogic)
const { startSettling } = useActions(featurePreviewGateSettlingLogic({ flag: config.flag }))
const { activeSceneId } = useValues(sceneLogic)
const { preflight } = useValues(preflightLogic)
@@ -144,7 +145,21 @@ function FeaturePreviewGateContent({
titleOverride={config.title}
description={config.description}
isEmpty
- actionElementOverride={<ConceptWaitlistForm feature={feature} config={config} />}
+ actionElementOverride={
+ <ConceptWaitlistCTA
+ feature={feature}
+ size="medium"
+ onSignUp={() => {
+ if (config.productIntent) {
+ void addProductIntentForCrossSell({
+ from: ProductKey.EARLY_ACCESS_FEATURES,
+ to: config.productIntent,
+ intent_context: ProductIntentContext.FEATURE_PREVIEW_ENABLED,
+ })
+ }
+ }}
+ />
+ }
docsURL={config.docsURL}
/>
</SceneContent>
@@ -220,81 +235,3 @@ function FeaturePreviewGateContent({
</SceneContent>
)
}
-
-function ConceptWaitlistForm({
- feature,
- config,
-}: {
- feature: EnrichedEarlyAccessFeature
- config: FeaturePreviewGateConfig
-}): JSX.Element {
- const { waitlistSurveysEnabled, conceptSurveySubmissions } = useValues(featurePreviewsLogic)
- const { submitConceptSurvey, updateEarlyAccessFeatureEnrollment, addProductIntentForCrossSell } =
- useActions(featurePreviewsLogic)
- const [email, setEmail] = useState('')
-
- const surveySubmitted = !!conceptSurveySubmissions[feature.flagKey] || feature.enabled
-
- // Mirrors the previews page's ConceptPreview: email collection only when the waitlist
- // surveys gate is on, otherwise the plain one-click registration.
- const hasWaitlistSurvey = waitlistSurveysEnabled
-
- const recordIntent = (): void => {
- // submitConceptSurvey refuses impersonated sessions; skip the intent too so a
- // rejected signup never records a false adoption signal.
- if (config.productIntent && !window.IMPERSONATED_SESSION) {
- void addProductIntentForCrossSell({
- from: ProductKey.EARLY_ACCESS_FEATURES,
- to: config.productIntent,
- intent_context: ProductIntentContext.FEATURE_PREVIEW_ENABLED,
- })
- }
- }
-
- if (surveySubmitted) {
- return (
- <span role="status" className="flex items-center gap-1 text-success font-medium">
- <IconCheck /> Thanks — we'll email you when it's ready.
- </span>
- )
- }
-
- if (hasWaitlistSurvey) {
- return (
- <form
- className="flex items-center gap-2"
- onSubmit={(e) => {
- e.preventDefault()
- if (email) {
- submitConceptSurvey(feature.flagKey, email)
- recordIntent()
- }
- }}
- >
- <LemonInput
- type="email"
- value={email}
- onChange={setEmail}
- placeholder="[email protected]"
- aria-label="Email address"
- autoComplete="email"
- />
- <LemonButton type="primary" htmlType="submit" disabledReason={!email ? 'Enter your email' : undefined}>
- Get notified
- </LemonButton>
- </form>
- )
- }
-
- return (
- <LemonButton
- type="primary"
- onClick={() => {
- updateEarlyAccessFeatureEnrollment(feature.flagKey, true, feature.stage)
- recordIntent()
- }}
- >
- Get notified
- </LemonButton>
- )
-}
diff --git a/frontend/src/lib/components/FeaturePreviews/ConceptWaitlistCTA.tsx b/frontend/src/lib/components/FeaturePreviews/ConceptWaitlistCTA.tsx
new file mode 100644
index 000000000000..55af0946de69
--- /dev/null
+++ b/frontend/src/lib/components/FeaturePreviews/ConceptWaitlistCTA.tsx
@@ -0,0 +1,109 @@
+import { useActions, useValues } from 'kea'
+import { useState } from 'react'
+
+import { IconBell, IconCheck } from '@posthog/icons'
+import { LemonButton, LemonInput } from '@posthog/lemon-ui'
+
+import { EnrichedEarlyAccessFeature, featurePreviewsLogic } from './featurePreviewsLogic'
+
+export interface ConceptWaitlistCTAProps {
+ feature: EnrichedEarlyAccessFeature
+ size?: 'small' | 'medium'
+ /** Frozen once shipped: autocapture dashboards and Playwright select on it. */
+ dataAttr?: string
+ /** Skipped for impersonated sessions, where the sign-up itself is refused. */
+ onSignUp?: () => void
+ /** Off: one-click sign-up tied to the logged-in account, even when the feature links a waitlist survey. */
+ collectEmail?: boolean
+}
+
+export function ConceptWaitlistCTA({
+ feature,
+ size = 'small',
+ dataAttr,
+ onSignUp,
+ collectEmail = true,
+}: ConceptWaitlistCTAProps): JSX.Element {
+ const { waitlistSurveysEnabled, conceptSurveySubmissions } = useValues(featurePreviewsLogic)
+ const { submitConceptSurvey, updateEarlyAccessFeatureEnrollment } = useActions(featurePreviewsLogic)
+ const [email, setEmail] = useState('')
+
+ const { flagKey, enabled } = feature
+
+ const hasWaitlistSurvey = collectEmail && waitlistSurveysEnabled && !!feature.payload?.survey_id
+
+ const notifySignUp = (): void => {
+ // submitConceptSurvey and the enrollment listener both refuse impersonated sessions, so
+ // skip the callback too: a rejected sign-up must not record a false adoption signal.
+ if (!window.IMPERSONATED_SESSION) {
+ onSignUp?.()
+ }
+ }
+
+ if (!hasWaitlistSurvey) {
+ return (
+ <LemonButton
+ type="primary"
+ disabledReason={
+ enabled && "You have already expressed your interest. We'll contact you when it's ready"
+ }
+ onClick={() => {
+ updateEarlyAccessFeatureEnrollment(flagKey, true, feature.stage)
+ notifySignUp()
+ }}
+ size={size}
+ sideIcon={enabled ? <IconCheck /> : <IconBell />}
+ className="w-fit"
+ data-attr={dataAttr}
+ >
+ {enabled ? 'Registered' : 'Get notified'}
+ </LemonButton>
+ )
+ }
+
+ // `enabled` covers users who registered interest before the survey era. The migration
+ // command moves them into the survey, so do not ask them again.
+ if (!!conceptSurveySubmissions[flagKey] || enabled) {
+ // role="status" makes the confirmation a live region: the form (and its focused
+ // button) unmounts on submit, so without it screen readers announce nothing.
+ return (
+ <span role="status" className="flex items-center gap-1 text-success font-medium">
+ <IconCheck /> Thanks, we'll email you when it's ready.
+ </span>
+ )
+ }
+
+ return (
+ <form
+ className="flex items-center gap-2"
+ onSubmit={(e) => {
+ e.preventDefault()
+ if (email) {
+ submitConceptSurvey(flagKey, email)
+ notifySignUp()
+ }
+ }}
+ >
+ <LemonInput
+ type="email"
+ value={email}
+ onChange={setEmail}
+ placeholder="[email protected]"
+ // Several concept features can render this form on one page; name whose it is.
+ aria-label={`Email address to join the ${feature.name} waitlist`}
+ autoComplete="email"
+ size={size}
+ />
+ <LemonButton
+ type="primary"
+ size={size}
+ htmlType="submit"
+ disabledReason={!email ? 'Enter your email' : undefined}
+ aria-label={`Get notified when ${feature.name} is ready`}
+ data-attr={dataAttr}
+ >
+ Get notified
+ </LemonButton>
+ </form>
+ )
+}
diff --git a/frontend/src/lib/components/FeaturePreviews/FeaturePreviews.tsx b/frontend/src/lib/components/FeaturePreviews/FeaturePreviews.tsx
index d0e045744f53..10ff0a858e8a 100644
--- a/frontend/src/lib/components/FeaturePreviews/FeaturePreviews.tsx
+++ b/frontend/src/lib/components/FeaturePreviews/FeaturePreviews.tsx
@@ -1,7 +1,6 @@
import { useActions, useAsyncActions, useValues } from 'kea'
import { useEffect, useLayoutEffect, useState } from 'react'
-import { IconBell, IconCheck } from '@posthog/icons'
import { LemonBanner, LemonButton, LemonInput, LemonSwitch, LemonTextArea, Link } from '@posthog/lemon-ui'
import { BasicCard } from 'lib/components/Cards/BasicCard'
@@ -16,6 +15,7 @@ import { userLogic } from 'scenes/userLogic'
import { AvailableFeature } from '~/types'
+import { ConceptWaitlistCTA } from './ConceptWaitlistCTA'
import { EnrichedEarlyAccessFeature, featurePreviewsLogic } from './featurePreviewsLogic'
type AvailableFeatureChecker = (feature: AvailableFeature) => boolean
@@ -174,74 +174,9 @@ function PreviewCard({ feature, title, description, actions, children }: Preview
}
function ConceptPreview({ feature }: { feature: EnrichedEarlyAccessFeature }): JSX.Element {
- const { updateEarlyAccessFeatureEnrollment, copyExternalFeaturePreviewLink, submitConceptSurvey } =
- useActions(featurePreviewsLogic)
- const { waitlistSurveysEnabled, conceptSurveySubmissions } = useValues(featurePreviewsLogic)
+ const { copyExternalFeaturePreviewLink } = useActions(featurePreviewsLogic)
- const { flagKey, enabled, name, description } = feature
- const [email, setEmail] = useState('')
-
- // When the gate is on and the feature has a linked waitlist survey, collect an email
- // (recorded as a survey response) instead of the one-click, login-tied enrollment.
- const surveyId = feature.payload?.survey_id
- const hasWaitlistSurvey = waitlistSurveysEnabled && !!surveyId
- // `enabled` covers users who registered interest before the survey era — the
- // migration command moves them into the survey, so don't ask them again.
- const surveySubmitted = !!conceptSurveySubmissions[flagKey] || enabled
-
- let actions: JSX.Element
- if (hasWaitlistSurvey) {
- actions = surveySubmitted ? (
- // role="status" makes the confirmation a live region: the form (and its focused
- // button) unmounts on submit, so without it screen readers announce nothing.
- <span role="status" className="flex items-center gap-1 text-success font-medium">
- <IconCheck /> Thanks — we'll email you when it's ready.
- </span>
- ) : (
- <form
- className="flex items-center gap-2"
- onSubmit={(e) => {
- e.preventDefault()
- if (email) {
- submitConceptSurvey(flagKey, email)
- }
- }}
- >
- <LemonInput
- type="email"
- value={email}
- onChange={setEmail}
- placeholder="[email protected]"
- aria-label="Email address"
- autoComplete="email"
- size="small"
- />
- <LemonButton
- type="primary"
- size="small"
- htmlType="submit"
- disabledReason={!email ? 'Enter your email' : undefined}
- >
- Get notified
- </LemonButton>
- </form>
- )
- } else {
- actions = (
- <LemonButton
- type="primary"
- disabledReason={
- enabled && "You have already expressed your interest. We'll contact you when it's ready"
- }
- onClick={() => updateEarlyAccessFeatureEnrollment(flagKey, true, feature.stage)}
- size="small"
- sideIcon={enabled ? <IconCheck /> : <IconBell />}
- className="w-fit"
- >
- {enabled ? 'Registered' : 'Get notified'}
- </LemonButton>
- )
- }
+ const { flagKey, name, description } = feature
return (
<PreviewCard
@@ -261,7 +196,7 @@ function ConceptPreview({ feature }: { feature: EnrichedEarlyAccessFeature }): J
{description || <span className="text-tertiary">No description</span>}
</p>
}
- actions={actions}
+ actions={<ConceptWaitlistCTA feature={feature} />}
/>
)
}
diff --git a/frontend/src/lib/constants.tsx b/frontend/src/lib/constants.tsx
index 02b496408616..3b4c4f5ea03a 100644
--- a/frontend/src/lib/constants.tsx
+++ b/frontend/src/lib/constants.tsx
@@ -467,6 +467,7 @@ export const FEATURE_FLAGS = {
QUILL_DATE_PICKER: 'quill-date-picker', // owner: @pauldambra, flips the lib/components/DatePicker seam from LemonUI to Quill
REAL_TIME_NOTIFICATIONS: 'real-time-notifications', // owner: #team-platform-features
REALTIME_COHORT_FLAG_TARGETING: 'realtime-cohort-flag-targeting', // owner: @dmarticus #team-feature-flags
+ REALTIME_COHORTS: 'realtime-cohorts', // owner: #team-feature-flags, links the cohorts list waitlist banner to its early access feature
RECORDINGS_PLAYER_EVENT_PROPERTY_EXPANSION: 'recordings-player-event-property-expansion', // owner: @pauldambra #team-replay
REMOTE_CONFIG: 'remote-config', // owner: #team-platform-features
REPLAY_COLLAPSE_INSPECTOR_ITEMS: 'replay-collapse-inspector-items', // owner: @fasyy612 #team-replay
diff --git a/frontend/src/lib/lemon-ui/LemonBanner/LemonBanner.stories.tsx b/frontend/src/lib/lemon-ui/LemonBanner/LemonBanner.stories.tsx
index 4f7fc8128e42..958b50fa0115 100644
--- a/frontend/src/lib/lemon-ui/LemonBanner/LemonBanner.stories.tsx
+++ b/frontend/src/lib/lemon-ui/LemonBanner/LemonBanner.stories.tsx
@@ -147,3 +147,22 @@ export const NarrowWithButtons: Story = {
},
parameters: wideParameters,
}
+
+export const TallContentTopAligned: Story = {
+ render: renderWide,
+ args: {
+ type: 'info',
+ alignItems: 'start',
+ onClose: () => alert('👋'),
+ children: (
+ <div className="flex flex-col gap-2">
+ <div className="font-semibold">A heading above a paragraph of body copy</div>
+ <p className="m-0">
+ With content this tall, a centered icon and close button drift to the middle of the banner, away
+ from the heading they belong to. Setting alignItems to start pins both to the top.
+ </p>
+ </div>
+ ),
+ },
+ parameters: wideParameters,
+}
diff --git a/frontend/src/lib/lemon-ui/LemonBanner/LemonBanner.tsx b/frontend/src/lib/lemon-ui/LemonBanner/LemonBanner.tsx
index 9826a32478b9..d8b6c1075e32 100644
--- a/frontend/src/lib/lemon-ui/LemonBanner/LemonBanner.tsx
+++ b/frontend/src/lib/lemon-ui/LemonBanner/LemonBanner.tsx
@@ -28,6 +28,8 @@ export interface LemonBannerProps {
hideIcon?: boolean
square?: boolean
icon?: React.ReactNode
+ /** Keep 'center' for one-line banners: the row fills the 3rem min-height, and centering holds the text off the top edge. */
+ alignItems?: 'center' | 'start'
}
/** Generic alert message. */
@@ -41,6 +43,7 @@ export function LemonBanner({
hideIcon,
square = false,
icon,
+ alignItems = 'center',
}: LemonBannerProps): JSX.Element | null {
const logic = lemonBannerLogic({ dismissKey })
const { isDismissed } = useValues(logic)
@@ -67,7 +70,7 @@ export function LemonBanner({
square && 'LemonBanner--square'
)}
>
- <div className="flex items-center gap-2 grow @md:!px-1">
+ <div className={clsx('flex gap-2 grow @md:!px-1', alignItems === 'start' ? 'items-start' : 'items-center')}>
{!hideIcon &&
(icon ? (
icon
diff --git a/frontend/src/scenes/cohorts/Cohorts.tsx b/frontend/src/scenes/cohorts/Cohorts.tsx
index 81f3e9d27d78..9c63eba6d4a3 100644
--- a/frontend/src/scenes/cohorts/Cohorts.tsx
+++ b/frontend/src/scenes/cohorts/Cohorts.tsx
@@ -39,6 +39,7 @@ import {
import { cohortsEmptyState } from 'products/cohorts/frontend/emptyState/cohortsEmptyState'
import { CohortRealtimeTag } from 'products/cohorts/frontend/realtime/CohortRealtimeTag'
+import { RealtimeCohortsWaitlistBanner } from 'products/cohorts/frontend/realtime/RealtimeCohortsWaitlistBanner'
export const scene: SceneExport = {
component: Cohorts,
@@ -302,6 +303,8 @@ export function Cohorts(): JSX.Element {
}
/>
+ <RealtimeCohortsWaitlistBanner />
+
<div>{filtersSection}</div>
<LemonTable
columns={columns}
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 12d844606699..1e47a2e5216c 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -2778,6 +2778,12 @@ importers:
'@posthog/icons':
specifier: 'catalog:'
+ '@posthog/react':
+ specifier: 'catalog:'
+ '@testing-library/jest-dom':
+ specifier: '*'
+ version: 5.17.0
'@types/react':
specifier: 18.3.27
version: 18.3.27
@@ -2796,6 +2802,9 @@ importers:
kea-router:
specifier: 'catalog:'
version: 3.4.1([email protected](patch_hash=139b8d1f1304f9d9da452a9a1244c94ea679dbcb85687d8999563146879fb6f5)([email protected]))
+ posthog-js:
+ specifier: 'catalog:'
+ version: 1.434.4(@types/[email protected])([email protected])
react:
specifier: 18.3.1
version: 18.3.1
@@ -2803,6 +2812,9 @@ importers:
'@storybook/react':
specifier: 'catalog:'
+ '@testing-library/react':
+ specifier: ^14.3.1
kea-test-utils:
specifier: 'catalog:'
version: 0.2.4([email protected](patch_hash=139b8d1f1304f9d9da452a9a1244c94ea679dbcb85687d8999563146879fb6f5)([email protected]))
diff --git a/products/cohorts/frontend/realtime/RealtimeCohortsWaitlistBanner.test.tsx b/products/cohorts/frontend/realtime/RealtimeCohortsWaitlistBanner.test.tsx
new file mode 100644
index 000000000000..ea15f0ec9855
--- /dev/null
+++ b/products/cohorts/frontend/realtime/RealtimeCohortsWaitlistBanner.test.tsx
@@ -0,0 +1,157 @@
+import '@testing-library/jest-dom'
+
+import { cleanup, fireEvent, render, screen } from '@testing-library/react'
+import { useActions, useValues } from 'kea'
+import posthog from 'posthog-js'
+import type { ReactNode } from 'react'
+
+import { featurePreviewsLogic } from 'lib/components/FeaturePreviews/featurePreviewsLogic'
+import { FEATURE_FLAGS } from 'lib/constants'
+import { useFeatureFlag } from 'lib/hooks/useFeatureFlag'
+import { lemonToast } from 'lib/lemon-ui/LemonToast'
+
+import { cohortsSetupLogic } from '../emptyState/cohortsSetupLogic'
+import { RealtimeCohortsWaitlistBanner } from './RealtimeCohortsWaitlistBanner'
+
+jest.mock('kea', () => ({
+ ...jest.requireActual('kea'),
+ useValues: jest.fn(),
+ useActions: jest.fn(),
+}))
+jest.mock('lib/hooks/useFeatureFlag', () => ({
+ useFeatureFlag: jest.fn(() => false),
+}))
+jest.mock('posthog-js', () => ({ __esModule: true, default: { get_property: jest.fn() } }))
+jest.mock('@posthog/react', () => ({
+ PostHogCaptureOnViewed: ({ name, children }: { name: string; children: ReactNode }) => (
+ <div data-attr={`viewed-${name}`}>{children}</div>
+ ),
+}))
+jest.mock('lib/lemon-ui/LemonToast', () => ({ lemonToast: { success: jest.fn() } }))
+
+const mockedUseValues = useValues as jest.Mock
+const mockedUseActions = useActions as jest.Mock
+const mockedUseFeatureFlag = useFeatureFlag as jest.Mock
+const mockedGetProperty = posthog.get_property as jest.Mock
+
+const mockLoadEarlyAccessFeatures = jest.fn()
+const mockUpdateEarlyAccessFeatureEnrollment = jest.fn()
+const mockSubmitConceptSurvey = jest.fn()
+
+const CONCEPT_FEATURE = {
+ flagKey: FEATURE_FLAGS.REALTIME_COHORTS,
+ name: 'Realtime cohorts',
+ enabled: false,
+ stage: 'concept',
+ payload: { survey_id: 'survey-1' },
+}
+
+function setupMocks(
+ earlyAccessFeatures: Array<{
+ flagKey: string
+ enabled: boolean
+ stage?: string
+ payload?: Record<string, unknown>
+ }>,
+ {
+ isDismissed = false,
+ hasRealtimeTargeting = false,
+ setupStatus = 'has-data',
+ joinedInThisBrowser = false,
+ }: {
+ isDismissed?: boolean
+ hasRealtimeTargeting?: boolean
+ setupStatus?: string
+ joinedInThisBrowser?: boolean
+ } = {}
+): void {
+ mockedUseFeatureFlag.mockReturnValue(hasRealtimeTargeting)
+ mockedGetProperty.mockReturnValue(
+ joinedInThisBrowser ? { [`$feature_enrollment/${FEATURE_FLAGS.REALTIME_COHORTS}`]: true } : {}
+ )
+ mockedUseValues.mockImplementation((logic: unknown) => {
+ if (logic === featurePreviewsLogic) {
+ return { earlyAccessFeatures, waitlistSurveysEnabled: true, conceptSurveySubmissions: {} }
+ }
+ if (logic === cohortsSetupLogic) {
+ return { setupStatus }
+ }
+ return { isDismissed }
+ })
+ mockedUseActions.mockImplementation((logic: unknown) =>
+ logic === featurePreviewsLogic
+ ? {
+ loadEarlyAccessFeatures: mockLoadEarlyAccessFeatures,
+ submitConceptSurvey: mockSubmitConceptSurvey,
+ updateEarlyAccessFeatureEnrollment: mockUpdateEarlyAccessFeatureEnrollment,
+ }
+ : { dismiss: jest.fn() }
+ )
+}
+
+describe('RealtimeCohortsWaitlistBanner', () => {
+ afterEach(() => {
+ cleanup()
+ jest.clearAllMocks()
+ })
+
+ it('offers the waitlist while the feature is at the concept stage', () => {
+ setupMocks([CONCEPT_FEATURE])
+
+ render(<RealtimeCohortsWaitlistBanner />)
+
+ // Without the load, the banner only appears for someone who visited another page that fetched features.
+ expect(mockLoadEarlyAccessFeatures).toHaveBeenCalled()
+ expect(screen.getByText('Realtime cohorts are coming soon')).toBeInTheDocument()
+ expect(screen.getByText('Beta')).toBeInTheDocument()
+ expect(screen.getByText('Get notified')).toBeInTheDocument()
+ expect(screen.getByLabelText('close')).toBeInTheDocument()
+ expect(screen.getByTestId('viewed-realtime-cohorts-waitlist-banner-shown')).toBeInTheDocument()
+ })
+
+ // The account already identifies the user, so the banner never asks for an email, even when the
+ // feature links a waitlist survey and the surveys flag is on.
+ it('collects interest with one click and no email field', () => {
+ setupMocks([CONCEPT_FEATURE])
+
+ render(<RealtimeCohortsWaitlistBanner />)
+
+ expect(screen.queryByPlaceholderText('[email protected]')).not.toBeInTheDocument()
+ fireEvent.click(screen.getByText('Get notified'))
+
+ expect(mockUpdateEarlyAccessFeatureEnrollment).toHaveBeenCalledWith(
+ FEATURE_FLAGS.REALTIME_COHORTS,
+ true,
+ 'concept'
+ )
+ expect(mockSubmitConceptSurvey).not.toHaveBeenCalled()
+ expect(lemonToast.success).toHaveBeenCalled()
+ })
+
+ it.each([
+ ['the feature preview does not exist', []],
+ ['the feature has moved past concept', [{ ...CONCEPT_FEATURE, stage: 'beta' }]],
+ ['the user is already on the waitlist', [{ ...CONCEPT_FEATURE, enabled: true }]],
+ ])('renders nothing when %s', (_label, earlyAccessFeatures) => {
+ setupMocks(earlyAccessFeatures)
+
+ const { container } = render(<RealtimeCohortsWaitlistBanner />)
+
+ expect(container).toBeEmptyDOMElement()
+ })
+
+ it.each([
+ ['the banner was dismissed', { isDismissed: true }],
+ ['the team already has realtime cohort targeting', { hasRealtimeTargeting: true }],
+ ['the project has no cohorts yet', { setupStatus: 'needs-setup' }],
+ ['cohort detection has not answered yet', { setupStatus: 'loading' }],
+ ['this browser already joined the waitlist', { joinedInThisBrowser: true }],
+ ])('renders nothing and does not load features when %s', (_label, options) => {
+ setupMocks([CONCEPT_FEATURE], options)
+
+ const { container } = render(<RealtimeCohortsWaitlistBanner />)
+
+ expect(container).toBeEmptyDOMElement()
+ expect(mockLoadEarlyAccessFeatures).not.toHaveBeenCalled()
+ })
+})
diff --git a/products/cohorts/frontend/realtime/RealtimeCohortsWaitlistBanner.tsx b/products/cohorts/frontend/realtime/RealtimeCohortsWaitlistBanner.tsx
new file mode 100644
index 000000000000..10a97d14d418
--- /dev/null
+++ b/products/cohorts/frontend/realtime/RealtimeCohortsWaitlistBanner.tsx
@@ -0,0 +1,79 @@
+import { useActions, useValues } from 'kea'
+import posthog from 'posthog-js'
+import { useEffect } from 'react'
+
+import { LemonBanner, LemonTag } from '@posthog/lemon-ui'
+import { PostHogCaptureOnViewed } from '@posthog/react'
+
+import { ConceptWaitlistCTA } from 'lib/components/FeaturePreviews/ConceptWaitlistCTA'
+import { featurePreviewsLogic } from 'lib/components/FeaturePreviews/featurePreviewsLogic'
+import { FEATURE_FLAGS } from 'lib/constants'
+import { useFeatureFlag } from 'lib/hooks/useFeatureFlag'
+import { lemonBannerLogic } from 'lib/lemon-ui/LemonBanner/lemonBannerLogic'
+import { lemonToast } from 'lib/lemon-ui/LemonToast'
+
+import { cohortsSetupLogic } from '../emptyState/cohortsSetupLogic'
+
+// pinned: localStorage key, because renaming it shows the banner again to everyone who closed it
+const DISMISS_KEY = 'realtime-cohorts-waitlist'
+
+function joinedWaitlistInThisBrowser(): boolean {
+ const storedPersonProps = posthog.get_property('$stored_person_properties') as Record<string, unknown> | undefined
+ return !!storedPersonProps?.[`$feature_enrollment/${FEATURE_FLAGS.REALTIME_COHORTS}`]
+}
+
+export function RealtimeCohortsWaitlistBanner(): JSX.Element | null {
+ const { earlyAccessFeatures } = useValues(featurePreviewsLogic)
+ const { loadEarlyAccessFeatures } = useActions(featurePreviewsLogic)
+ const { isDismissed } = useValues(lemonBannerLogic({ dismissKey: DISMISS_KEY }))
+ // Teams with no cohorts get the setup screen today; this keeps them out if it becomes skippable.
+ const { setupStatus } = useValues(cohortsSetupLogic)
+ // A team with realtime cohort targeting sees "Realtime" tags in the table below; a waitlist
+ // above them would contradict the page.
+ const alreadyHasRealtimeCohorts = useFeatureFlag('REALTIME_COHORT_FLAG_TARGETING')
+ const hidden =
+ isDismissed || alreadyHasRealtimeCohorts || setupStatus !== 'has-data' || joinedWaitlistInThisBrowser()
+
+ // The loader forces a fresh request, so only ask when the banner could render.
+ useEffect(() => {
+ if (!hidden) {
+ loadEarlyAccessFeatures()
+ }
+ }, [hidden, loadEarlyAccessFeatures])
+
+ // Shipping realtime cohorts retires this banner on its own: the early access feature
+ // leaving the concept ("coming soon") stage hides it, with no second frontend change.
+ const feature = earlyAccessFeatures.find((f) => f.flagKey === FEATURE_FLAGS.REALTIME_COHORTS)
+ if (hidden || feature?.stage !== 'concept' || feature.enabled) {
+ return null
+ }
+
+ return (
+ <PostHogCaptureOnViewed name="realtime-cohorts-waitlist-banner-shown">
+ <LemonBanner type="info" dismissKey={DISMISS_KEY} alignItems="start">
+ <div className="flex flex-col gap-2">
+ <div className="flex flex-wrap items-center gap-1.5">
+ <span className="font-semibold">Realtime cohorts are coming soon</span>
+ <LemonTag type="completion">Beta</LemonTag>
+ </div>
+ <p className="m-0">
+ Group people by the actions they took, and keep the group up to date as they take them. Join the
+ waitlist to try it first.
+ </p>
+ <ConceptWaitlistCTA
+ feature={feature}
+ dataAttr="realtime-cohorts-waitlist-signup"
+ collectEmail={false}
+ // Signing up flips `feature.enabled` and unmounts the banner, so its inline
+ // confirmation never shows; the toast outlives it.
+ onSignUp={() =>
+ lemonToast.success(
+ "You're on the realtime cohorts waitlist. We'll email you when it's ready."
+ )
+ }
+ />
+ </div>
+ </LemonBanner>
+ </PostHogCaptureOnViewed>
+ )
+}
diff --git a/products/cohorts/package.json b/products/cohorts/package.json
index a22d175473ce..3cd687774822 100644
--- a/products/cohorts/package.json
+++ b/products/cohorts/package.json
@@ -6,15 +6,20 @@
"dependencies": {
"kea": "catalog:",
"kea-loaders": "catalog:",
- "kea-router": "catalog:"
+ "kea-router": "catalog:",
+ "posthog-js": "catalog:"
},
"devDependencies": {
"@storybook/react": "catalog:",
+ "@testing-library/react": "^14.3.1",
"kea-test-utils": "catalog:"
},
"peerDependencies": {
"@posthog/brand": "catalog:",
"@posthog/icons": "catalog:",
+ "@posthog/react": "catalog:",
+ "@testing-library/jest-dom": "*",
+ "@testing-library/react": "*",
"@types/react": "*",
"clsx": "*",
"fuse.js": "*",