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(customer-analytics): improve gated state for usage metrics settings (#73315)

posthog[bot]d4d15007e282
diff --git a/frontend/src/layout/scenes/components/FeaturePreviewSceneGate.test.tsx b/frontend/src/layout/scenes/components/FeaturePreviewSceneGate.test.tsx
index 2565498755a6..c81814d0bf0c 100644
--- a/frontend/src/layout/scenes/components/FeaturePreviewSceneGate.test.tsx
+++ b/frontend/src/layout/scenes/components/FeaturePreviewSceneGate.test.tsx
@@ -4,7 +4,9 @@ import { cleanup, render, screen } from '@testing-library/react'
import userEvent from '@testing-library/user-event'
import { useActions, useMountedLogic, useValues } from 'kea'
+import { supportLogic } from 'lib/components/Support/supportLogic'
import { featureFlagLogic } from 'lib/logic/featureFlagLogic'
+import { preflightLogic } from 'lib/logic/preflightLogic'
import { FeaturePreviewGateConfig } from '~/types'
@@ -62,6 +64,7 @@ const mockedUseMountedLogic = useMountedLogic as jest.Mock
const mockLoadEarlyAccessFeatures = jest.fn()
const mockUpdateEarlyAccessFeatureEnrollment = jest.fn()
+const mockOpenSupportForm = jest.fn()
const BASE_CONFIG: FeaturePreviewGateConfig = {
flag: 'customer-analytics-roadmap',
@@ -84,14 +87,24 @@ function isFeatureFlagLogicRef(logic: unknown): boolean {
return logic === featureFlagLogic
}
+function isPreflightLogicRef(logic: unknown): boolean {
+ return logic === preflightLogic
+}
+
+function isSupportLogicRef(logic: unknown): boolean {
+ return logic === supportLogic
+}
+
function setupMocks({
earlyAccessFeatures = [],
activeSceneId = null,
featureFlags = {},
+ cloud = true,
}: {
earlyAccessFeatures?: Array<{ flagKey: string; enabled: boolean; stage?: string }>
activeSceneId?: string | null
featureFlags?: Record<string, boolean | string>
+ cloud?: boolean
} = {}): void {
mockedUseMountedLogic.mockReturnValue({})
@@ -105,6 +118,9 @@ function setupMocks({
if (isFeatureFlagLogicRef(logic)) {
return { featureFlags }
}
+ if (isPreflightLogicRef(logic)) {
+ return { preflight: { cloud } }
+ }
return {}
})
@@ -115,6 +131,9 @@ function setupMocks({
updateEarlyAccessFeatureEnrollment: mockUpdateEarlyAccessFeatureEnrollment,
}
}
+ if (isSupportLogicRef(logic)) {
+ return { openSupportForm: mockOpenSupportForm }
+ }
return {}
})
}
@@ -243,6 +262,40 @@ describe('FeaturePreviewSceneGate', () => {
})
})
+ describe('request access', () => {
+ const CONFIG_WITH_SUPPORT: FeaturePreviewGateConfig = {
+ ...BASE_CONFIG,
+ supportTargetArea: 'customer_analytics',
+ }
+
+ test('does not show "Request access" when config has no supportTargetArea', () => {
+ setupMocks({ earlyAccessFeatures: [] })
+
+ render(<FeaturePreviewSceneGate config={BASE_CONFIG}>{CHILDREN}</FeaturePreviewSceneGate>)
+
+ expect(screen.queryByText('Request access')).not.toBeInTheDocument()
+ })
+
+ test('does not show "Request access" on a self-hosted instance', () => {
+ setupMocks({ earlyAccessFeatures: [], cloud: false })
+
+ render(<FeaturePreviewSceneGate config={CONFIG_WITH_SUPPORT}>{CHILDREN}</FeaturePreviewSceneGate>)
+
+ expect(screen.queryByText('Request access')).not.toBeInTheDocument()
+ })
+
+ test('opens the support form targeting the configured area when "Request access" is clicked', async () => {
+ setupMocks({ earlyAccessFeatures: [], cloud: true })
+
+ render(<FeaturePreviewSceneGate config={CONFIG_WITH_SUPPORT}>{CHILDREN}</FeaturePreviewSceneGate>)
+ await userEvent.click(screen.getByText('Request access'))
+
+ expect(mockOpenSupportForm).toHaveBeenCalledWith(
+ expect.objectContaining({ kind: 'support', target_area: 'customer_analytics' })
+ )
+ })
+ })
+
describe('behavior on mount', () => {
test('calls loadEarlyAccessFeatures on mount when gated', () => {
render(<FeaturePreviewSceneGate config={BASE_CONFIG}>{CHILDREN}</FeaturePreviewSceneGate>)
diff --git a/frontend/src/layout/scenes/components/FeaturePreviewSceneGate.tsx b/frontend/src/layout/scenes/components/FeaturePreviewSceneGate.tsx
index 6375e0ec4c63..f47f024c6c4e 100644
--- a/frontend/src/layout/scenes/components/FeaturePreviewSceneGate.tsx
+++ b/frontend/src/layout/scenes/components/FeaturePreviewSceneGate.tsx
@@ -4,7 +4,9 @@ import { useEffect } from 'react'
import { LemonButton, LemonSwitch } from '@posthog/lemon-ui'
import { ProductIntroduction } from 'lib/components/ProductIntroduction/ProductIntroduction'
+import { SupportTicketTargetArea, supportLogic } from 'lib/components/Support/supportLogic'
import { featureFlagLogic } from 'lib/logic/featureFlagLogic'
+import { preflightLogic } from 'lib/logic/preflightLogic'
import { sceneLogic } from 'scenes/sceneLogic'
import { sceneConfigurations } from 'scenes/scenes'
import { urls } from 'scenes/urls'
@@ -34,6 +36,8 @@ function FeaturePreviewGateContent({ config }: { config: FeaturePreviewGateConfi
const { earlyAccessFeatures } = useValues(featurePreviewsLogic)
const { loadEarlyAccessFeatures, updateEarlyAccessFeatureEnrollment } = useActions(featurePreviewsLogic)
const { activeSceneId } = useValues(sceneLogic)
+ const { preflight } = useValues(preflightLogic)
+ const { openSupportForm } = useActions(supportLogic)
useEffect(() => {
loadEarlyAccessFeatures()
@@ -70,9 +74,25 @@ function FeaturePreviewGateContent({ config }: { config: FeaturePreviewGateConfi
<span className="font-semibold">Enable feature preview</span>
</label>
) : (
- <LemonButton type="primary" to={urls.featurePreview(config.flag)}>
- Open feature previews
- </LemonButton>
+ <div className="flex items-center gap-2">
+ <LemonButton type="primary" to={urls.featurePreview(config.flag)}>
+ Open feature previews
+ </LemonButton>
+ {config.supportTargetArea && preflight?.cloud && (
+ <LemonButton
+ type="secondary"
+ onClick={() =>
+ openSupportForm({
+ kind: 'support',
+ target_area: config.supportTargetArea as SupportTicketTargetArea,
+ message: `I'd like to request access to ${config.title}.`,
+ })
+ }
+ >
+ Request access
+ </LemonButton>
+ )}
+ </div>
)
}
docsURL={config.docsURL}
diff --git a/frontend/src/types.ts b/frontend/src/types.ts
index fbe1cdab98b5..6467793204bf 100644
--- a/frontend/src/types.ts
+++ b/frontend/src/types.ts
@@ -7574,6 +7574,12 @@ export interface FeaturePreviewGateConfig {
title: string
description: string
docsURL?: string
+ /**
+ * Support ticket target area for the "Request access" action. Set this for betas that aren't
+ * self-serve early-access features, so the gated state offers a way to request access instead
+ * of dead-ending on the feature previews page.
+ */
+ supportTargetArea?: string
}
export interface ProductManifest {
diff --git a/products/customer_analytics/frontend/featurePreviewGate.ts b/products/customer_analytics/frontend/featurePreviewGate.ts
index 40e969a8ab2b..14effd4a1ab8 100644
--- a/products/customer_analytics/frontend/featurePreviewGate.ts
+++ b/products/customer_analytics/frontend/featurePreviewGate.ts
@@ -6,6 +6,7 @@ export const customerAnalyticsFeaturePreviewGate: FeaturePreviewGateConfig = {
flag: FEATURE_FLAGS.CUSTOMER_ANALYTICS,
title: 'Try Customer analytics',
description:
- 'Get context about your customers. Is the number of signups going up? Are we converting free users to paid users? Need to know what the power users of a feature are? We got you covered.',
+ 'Get context about your customers. Is the number of signups going up? Are we converting free users to paid users? Need to know what the power users of a feature are? We got you covered. Customer analytics is currently in beta — request access below and our team will get you set up.',
docsURL: 'https://posthog.com/docs/customer-analytics',
+ supportTargetArea: 'customer_analytics',
}