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): show every required SDK setup step inline (#102142)

posthog[bot]f7e5e6d348a2
diff --git a/frontend/snapshots.yml b/frontend/snapshots.yml
index de446b3455c4..4ac3380bb200 100644
--- a/frontend/snapshots.yml
+++ b/frontend/snapshots.yml
@@ -10385,9 +10385,9 @@ snapshots:
scenes-app-settings-organization--settings-organization-members--light:
hash: v1.k794b7964.a908db1c5361acbe7d9ec6429b8a921fad94ab4cf4adeb3daae3816e15d83503.fqkQyN5ukTYAdvIKOeko4R1mBb4MtgpnNX8BqfjqTps
scenes-app-settings-organization--settings-organization-proxy--dark:
- hash: v1.k794b7964.02acdbc3b671b4a724d93deb92f4079445216b1c395b3d7b2d45ee0a11046ff3.vWYPxGBbJQtC2KNDVX0drRhNZ6fit0PKF9aGnZL4UxM
+ hash: v1.k794b7964.8d224fe300274548438d00f38a72825c5e8425c42da637eb010efbc6791e6294.ZwYt5atQBiMtka55zyETWNWXpZhyoO2-FGb_nxzZcwE
scenes-app-settings-organization--settings-organization-proxy--light:
- hash: v1.k794b7964.7b5c6cd9ce6dd8338300ecd56a9a76198b020cfc4dad9551d329ec395920146d.BPKFFN1wzKTTXthSin7B8Z8VZhQSDII1h0bPCBbfLho
+ hash: v1.k794b7964.3020ed863f50139077a3e56bfcfed14114732825ddcd29d3dac356fa44babb25.RLy_8L5cCU59QtBsKXZ1DiFYxZGtuYEwpuHNT_wAMpk
scenes-app-settings-organization--settings-organization-roles--dark:
hash: v1.k794b7964.a17e5ccd912192ea9e39e5fe05a68bd3fc0ffb85ae9eedded99723eeca0b3c80.2GShVOupZgGLnVuQpijdn5_U73FjYX24aVAIbt5NxF8
scenes-app-settings-organization--settings-organization-roles--light:
@@ -10413,9 +10413,9 @@ snapshots:
scenes-app-settings-project--settings-project-danger-zone--light:
hash: v1.k794b7964.d1c7e77b9262b8e43553afc214de0511b6369c69f161e9f0c6ebb4455851e8ed.WuznBVFyHT9OPoCcrWbZ4fl2-m7tu-ge5rLETaH8Byc
scenes-app-settings-project--settings-project-details--dark:
- hash: v1.k794b7964.f11b9323d9a435fe7b3d81fc6b59defbe3e6fc2bb251017ede668d709bda2f1c.ix5GviZ3bqQoNGWsYhxce_RKXMQsmdl5MjrJv3nbsUI
+ hash: v1.k794b7964.5149d75603105af7d69f042e637792ab82c2252d94f4be589f9e719d89ee7130.G3yLXg6gi2BRkhn6qArJxyxkXg59EQHXbmNzpIUX3v8
scenes-app-settings-project--settings-project-details--light:
- hash: v1.k794b7964.93e0f8bd95f061dc866827c4e9a5db96564358f84661c18b469b2eb211282fe0.unp1YWigvuhVTj8-Qo4N0c9kB-kq9BniqL5kbXdYQlk
+ hash: v1.k794b7964.a2695b636aeb73d3eb543ead7ffd3b86e16b47dd49f37ae15565cb6286796dc5.f6rKh3QIZOs_ryn3iWbfQfCMr_ruAoiC_Ac0Ru_fNJQ
scenes-app-settings-project--settings-project-integrations--dark:
hash: v1.k794b7964.bf31464f10d36bfd3279dabc491f218cb2963722f82bcbb493e5dc33d29c86b5.yDZsN-V7mNvv7zdaVUNPpq_7M-7fQr7o42LRqg610pQ
scenes-app-settings-project--settings-project-integrations--light:
diff --git a/frontend/src/lib/utils/eventUsageLogic.ts b/frontend/src/lib/utils/eventUsageLogic.ts
index 293bf5f716c0..8e26b7813d2a 100644
--- a/frontend/src/lib/utils/eventUsageLogic.ts
+++ b/frontend/src/lib/utils/eventUsageLogic.ts
@@ -382,6 +382,12 @@ export interface ExperimentRecordingsBucketFailedContext {
error: string
}
+/** Where a reader picked an SDK in the setup snippets, so selection can be compared across surfaces. */
+export type SDKSetupInstructionsSurface =
+ | 'settings_sdk_setup'
+ | 'settings_reverse_proxy_setup'
+ | 'onboarding_ai_observability'
+
// GROW-89: both onboarding flows fire the same funnel event names during the transition, told apart
// by `version` (1 = legacy, 2 = context-first redesign) and `flow_variant`. Stamping properties
// instead of renaming keeps every existing dashboard and alert on the v1 events working. The
@@ -2223,6 +2229,13 @@ export interface eventUsageLogicActions {
reportSDKSelected: (sdk: SDK) => {
sdk: SDK
}
+ reportSDKSetupInstructionsSDKSelected: (
+ sdkKey: string,
+ surface: SDKSetupInstructionsSurface
+ ) => {
+ sdkKey: string
+ surface: SDKSetupInstructionsSurface
+ }
reportSavedInsightFilterUsed: (filterKeys: string[]) => {
filterKeys: string[]
}
@@ -3305,6 +3318,10 @@ export const eventUsageLogic = kea<eventUsageLogicType>([
reportBillingUsageInteraction: (properties: BillingUsageInteractionProps) => ({ properties }),
reportBillingSpendInteraction: (properties: BillingUsageInteractionProps) => ({ properties }),
reportSDKSelected: (sdk: SDK) => ({ sdk }),
+ reportSDKSetupInstructionsSDKSelected: (sdkKey: string, surface: SDKSetupInstructionsSurface) => ({
+ sdkKey,
+ surface,
+ }),
// Setup wizard sync (CLI ↔ app) funnel. Fired from the Installation layer
// (installationProgressLogic); guards for "once per session" live in that logic.
reportWizardSyncSessionDetected: (props: {
@@ -4785,6 +4802,12 @@ export const eventUsageLogic = kea<eventUsageLogicType>([
sdk: sdk.key,
})
},
+ reportSDKSetupInstructionsSDKSelected: ({ sdkKey, surface }) => {
+ posthog.capture('sdk setup instructions sdk selected', {
+ sdk: sdkKey,
+ surface,
+ })
+ },
reportWizardSyncSessionDetected: ({ workflowId, skillId, runPhase, taskCount }) => {
posthog.capture('setup wizard sync session detected', {
workflow_id: workflowId,
diff --git a/frontend/src/scenes/onboarding/self-driving/steps/AIObservabilityStep.test.tsx b/frontend/src/scenes/onboarding/self-driving/steps/AIObservabilityStep.test.tsx
new file mode 100644
index 000000000000..f3c0868fc186
--- /dev/null
+++ b/frontend/src/scenes/onboarding/self-driving/steps/AIObservabilityStep.test.tsx
@@ -0,0 +1,37 @@
+import { MOCK_DEFAULT_TEAM } from 'lib/api.mock'
+
+import '@testing-library/jest-dom'
+
+import { cleanup, fireEvent, render, screen } from '@testing-library/react'
+
+import { teamLogic } from 'scenes/teamLogic'
+
+import { initKeaTests } from '~/test/init'
+
+import { AIObservabilityStep } from './AIObservabilityStep'
+
+describe('AIObservabilityStep', () => {
+ beforeEach(() => {
+ initKeaTests()
+ teamLogic.mount()
+ teamLogic.actions.loadCurrentTeamSuccess(MOCK_DEFAULT_TEAM)
+ })
+
+ afterEach(() => {
+ cleanup()
+ })
+
+ it('keeps the chosen language when the provider changes', () => {
+ render(<AIObservabilityStep onContinue={jest.fn()} onSkip={jest.fn()} />)
+
+ expect(screen.getByText(/pip install posthog openai/)).toBeInTheDocument()
+
+ fireEvent.click(screen.getAllByText('Node')[0])
+ expect(screen.getByText(/npm install @posthog\/ai posthog-node openai/)).toBeInTheDocument()
+
+ fireEvent.click(screen.getAllByText('OpenAI')[0])
+ fireEvent.click(screen.getByText('Anthropic'))
+
+ expect(screen.getByText(/npm install @posthog\/ai posthog-node @anthropic-ai\/sdk/)).toBeInTheDocument()
+ })
+})
diff --git a/frontend/src/scenes/onboarding/self-driving/steps/AIObservabilityStep.tsx b/frontend/src/scenes/onboarding/self-driving/steps/AIObservabilityStep.tsx
index 65a887ba166f..0baf57cea586 100644
--- a/frontend/src/scenes/onboarding/self-driving/steps/AIObservabilityStep.tsx
+++ b/frontend/src/scenes/onboarding/self-driving/steps/AIObservabilityStep.tsx
@@ -1,9 +1,12 @@
+import { useActions } from 'kea'
import { useState } from 'react'
import { LemonButton, LemonSelect } from '@posthog/lemon-ui'
+import { eventUsageLogic } from 'lib/utils/eventUsageLogic'
import { AIObservabilitySDKInstructions } from 'scenes/onboarding/legacy/sdks/ai-observability/AIObservabilitySDKInstructions'
import { ALL_SDKS } from 'scenes/onboarding/legacy/sdks/allSDKs'
+import { OnboardingSelectedFileProvider } from 'scenes/onboarding/shared/OnboardingDocsContentWrapper'
import { SDKKey } from '~/types'
@@ -25,32 +28,41 @@ export function AIObservabilityStep({
onSkip: () => void
}): JSX.Element {
const [provider, setProvider] = useState<SDKKey>(SDKKey.OPENAI)
+ const { reportSDKSetupInstructionsSDKSelected } = useActions(eventUsageLogic)
const Instructions = AIObservabilitySDKInstructions[provider]
return (
- <div className="flex flex-col gap-5">
- <div className="flex items-center justify-center gap-2">
- <span className="text-secondary text-sm">My AI app uses</span>
- <LemonSelect
- size="small"
- value={provider}
- onChange={(value) => value && setProvider(value)}
- options={PROVIDER_OPTIONS}
- />
- </div>
- {Instructions && (
- <div className="border rounded p-4 text-left">
- <Instructions />
+ <OnboardingSelectedFileProvider>
+ <div className="flex flex-col gap-5">
+ <div className="flex items-center justify-center gap-2">
+ <span className="text-secondary text-sm">My AI app uses</span>
+ <LemonSelect
+ size="small"
+ value={provider}
+ onChange={(value) => {
+ if (!value) {
+ return
+ }
+ setProvider(value)
+ reportSDKSetupInstructionsSDKSelected(value, 'onboarding_ai_observability')
+ }}
+ options={PROVIDER_OPTIONS}
+ />
+ </div>
+ {Instructions && (
+ <div className="border rounded p-4 text-left">
+ <Instructions />
+ </div>
+ )}
+ <div className="flex flex-col items-center gap-1 pt-2">
+ <LemonButton type="primary" status="alt" onClick={onContinue}>
+ Continue
+ </LemonButton>
+ <LemonButton type="tertiary" size="small" onClick={onSkip}>
+ Skip for now
+ </LemonButton>
</div>
- )}
- <div className="flex flex-col items-center gap-1 pt-2">
- <LemonButton type="primary" status="alt" onClick={onContinue}>
- Continue
- </LemonButton>
- <LemonButton type="tertiary" size="small" onClick={onSkip}>
- Skip for now
- </LemonButton>
</div>
- </div>
+ </OnboardingSelectedFileProvider>
)
}
diff --git a/frontend/src/scenes/onboarding/shared/OnboardingDocsContentWrapper.tsx b/frontend/src/scenes/onboarding/shared/OnboardingDocsContentWrapper.tsx
index 5fd6953d0bee..bfaafab7dbe8 100644
--- a/frontend/src/scenes/onboarding/shared/OnboardingDocsContentWrapper.tsx
+++ b/frontend/src/scenes/onboarding/shared/OnboardingDocsContentWrapper.tsx
@@ -57,6 +57,22 @@ export interface OnboardingComponentsContext {
const OnboardingContext = createContext<OnboardingComponentsContext | null>(null)
+const SelectedFileContext = createContext<{
+ selectedFile: string | null
+ setSelectedFile: (file: string) => void
+} | null>(null)
+
+/**
+ * Keeps the code block file choice (for example Python or Node) outside the content wrapper, so a
+ * surface that swaps the whole instruction tree keeps the reader's choice instead of resetting it.
+ */
+export function OnboardingSelectedFileProvider({ children }: { children: ReactNode }): JSX.Element {
+ const [selectedFile, setSelectedFile] = React.useState<string | null>(null)
+ const value = useMemo(() => ({ selectedFile, setSelectedFile }), [selectedFile])
+
+ return <SelectedFileContext.Provider value={value}>{children}</SelectedFileContext.Provider>
+}
+
function Steps({ children }: StepsProps): JSX.Element {
let stepNumber = 0
@@ -346,8 +362,17 @@ function MinimalSteps({ children }: StepsProps): JSX.Element {
return <div className="space-y-4">{children}</div>
}
-function MinimalStep({ children }: StepProps & { stepNumber?: number }): JSX.Element | null {
- return <div className="space-y-4">{children}</div>
+function MinimalStep({ title, docsOnly, children }: StepProps): JSX.Element | null {
+ if (docsOnly) {
+ return null
+ }
+
+ return (
+ <div className="space-y-2">
+ {title && <h4 className="m-0">{title}</h4>}
+ <div className="space-y-4">{children}</div>
+ </div>
+ )
}
// This is a wrapper to share certain onboarding instructions with the main website repo.
@@ -365,7 +390,11 @@ export function OnboardingDocsContentWrapper({
/** When true, code snippets show the reverse proxy domain (if one exists) instead of the default API host. */
useReverseProxy?: boolean
}): JSX.Element {
- const [selectedFile, setSelectedFile] = React.useState<string | null>(null)
+ const [localSelectedFile, setLocalSelectedFile] = React.useState<string | null>(null)
+ const { selectedFile, setSelectedFile } = useContext(SelectedFileContext) ?? {
+ selectedFile: localSelectedFile,
+ setSelectedFile: setLocalSelectedFile,
+ }
const { proxyRecords } = useValues(proxyLogic)
const apiHost = useMemo(() => {
diff --git a/frontend/src/scenes/settings/environment/ProxySDKSetup.tsx b/frontend/src/scenes/settings/environment/ProxySDKSetup.tsx
index f37d8568d663..d530cfbf1521 100644
--- a/frontend/src/scenes/settings/environment/ProxySDKSetup.tsx
+++ b/frontend/src/scenes/settings/environment/ProxySDKSetup.tsx
@@ -1,21 +1,17 @@
-import { useValues } from 'kea'
+import { useActions, useValues } from 'kea'
import { useMemo, useState } from 'react'
import { LemonButton, LemonModal, LemonSelect, LemonSkeleton } from '@posthog/lemon-ui'
import { Link } from 'lib/lemon-ui/Link'
+import { eventUsageLogic } from 'lib/utils/eventUsageLogic'
import { OnboardingDocsContentWrapper } from 'scenes/onboarding/shared/OnboardingDocsContentWrapper'
import SetupWizardBanner from 'scenes/onboarding/shared/SetupWizardBanner'
import { teamLogic } from 'scenes/teamLogic'
import { SDKKey } from '~/types'
-import {
- buildSDKSelectOptions,
- filterRequiredSteps,
- filterToFirstRequiredStep,
- SDK_CONFIGS,
-} from './SDKSetupInstructions'
+import { buildSDKSelectOptions, filterRequiredSteps, SDK_CONFIGS } from './SDKSetupInstructions'
const PROXY_SDK_OPTIONS = buildSDKSelectOptions(['web', 'mobile'])
@@ -23,6 +19,7 @@ export function ProxySDKSetup(): JSX.Element {
const { currentTeam, currentTeamLoading } = useValues(teamLogic)
const [selectedSDK, setSelectedSDK] = useState<SDKKey>(SDKKey.JS_WEB)
const [showFullSetup, setShowFullSetup] = useState(false)
+ const { reportSDKSetupInstructionsSDKSelected } = useActions(eventUsageLogic)
const config = useMemo(() => SDK_CONFIGS[selectedSDK], [selectedSDK])
@@ -48,12 +45,13 @@ export function ProxySDKSetup(): JSX.Element {
onChange={(value) => {
setSelectedSDK(value)
setShowFullSetup(false)
+ reportSDKSetupInstructionsSDKSelected(value, 'settings_reverse_proxy_setup')
}}
options={PROXY_SDK_OPTIONS}
className="max-w-80"
/>
<OnboardingDocsContentWrapper snippets={snippets} minimal useReverseProxy>
- <Installation modifySteps={filterToFirstRequiredStep} />
+ <Installation modifySteps={filterRequiredSteps} />
</OnboardingDocsContentWrapper>
<div className="flex items-center gap-2">
<LemonButton type="secondary" size="small" onClick={() => setShowFullSetup(true)}>
@@ -71,7 +69,7 @@ export function ProxySDKSetup(): JSX.Element {
>
{wizardIntegrationName && <SetupWizardBanner integrationName={wizardIntegrationName} />}
<OnboardingDocsContentWrapper snippets={snippets} useReverseProxy>
- <Installation modifySteps={filterRequiredSteps} />
+ <Installation />
</OnboardingDocsContentWrapper>
<div className="mt-4">
<Link to={docsLink} target="_blank">
diff --git a/frontend/src/scenes/settings/environment/SDKSetupInstructions.test.tsx b/frontend/src/scenes/settings/environment/SDKSetupInstructions.test.tsx
new file mode 100644
index 000000000000..07d2d07122dc
--- /dev/null
+++ b/frontend/src/scenes/settings/environment/SDKSetupInstructions.test.tsx
@@ -0,0 +1,34 @@
+import { MOCK_DEFAULT_TEAM } from 'lib/api.mock'
+
+import '@testing-library/jest-dom'
+
+import { cleanup, fireEvent, render, screen } from '@testing-library/react'
+
+import { teamLogic } from 'scenes/teamLogic'
+
+import { initKeaTests } from '~/test/init'
+
+import { SDKSetupInstructions } from './SDKSetupInstructions'
+
+describe('<SDKSetupInstructions />', () => {
+ beforeEach(() => {
+ initKeaTests()
+ teamLogic.mount()
+ teamLogic.actions.loadCurrentTeamSuccess(MOCK_DEFAULT_TEAM)
+ })
+
+ afterEach(() => {
+ cleanup()
+ })
+
+ it('shows the initialize snippet with the project token for a server SDK', () => {
+ render(<SDKSetupInstructions />)
+
+ fireEvent.click(screen.getByText('Web'))
+ fireEvent.click(screen.getByText('Python'))
+
+ expect(screen.getByText('Install the package')).toBeInTheDocument()
+ expect(screen.getByText('Initialize PostHog')).toBeInTheDocument()
+ expect(screen.getByText(new RegExp(MOCK_DEFAULT_TEAM.api_token))).toBeInTheDocument()
+ })
+})
diff --git a/frontend/src/scenes/settings/environment/SDKSetupInstructions.tsx b/frontend/src/scenes/settings/environment/SDKSetupInstructions.tsx
index 6e506a079035..16249c11eb3c 100644
--- a/frontend/src/scenes/settings/environment/SDKSetupInstructions.tsx
+++ b/frontend/src/scenes/settings/environment/SDKSetupInstructions.tsx
@@ -1,4 +1,4 @@
-import { useValues } from 'kea'
+import { useActions, useValues } from 'kea'
import { useMemo, useState } from 'react'
import { LemonButton, LemonModal, LemonSelect, LemonSelectSection, LemonSkeleton } from '@posthog/lemon-ui'
@@ -40,6 +40,7 @@ import {
import type { StepDefinition } from '@posthog/shared-onboarding/steps'
import { Link } from 'lib/lemon-ui/Link'
+import { eventUsageLogic } from 'lib/utils/eventUsageLogic'
import { JS_WEB_SNIPPETS } from 'scenes/onboarding/shared/jsWebSnippets'
import { OnboardingDocsContentWrapper } from 'scenes/onboarding/shared/OnboardingDocsContentWrapper'
import SetupWizardBanner from 'scenes/onboarding/shared/SetupWizardBanner'
@@ -49,11 +50,6 @@ import { SDKKey } from '~/types'
const NODE_SNIPPETS = { NodeEventCapture }
const PYTHON_SNIPPETS = { PythonEventCapture }
-export const filterToFirstRequiredStep = (steps: StepDefinition[]): StepDefinition[] => {
- const first = steps.find((s) => s.badge === 'required')
- return first ? [first] : steps.slice(0, 1)
-}
-
export const filterRequiredSteps = (steps: StepDefinition[]): StepDefinition[] =>
steps.filter((s) => s.badge === 'required')
@@ -337,6 +333,7 @@ export function SDKSetupInstructions(): JSX.Element {
const { currentTeam, currentTeamLoading } = useValues(teamLogic)
const [selectedSDK, setSelectedSDK] = useState<SDKKey>(SDKKey.JS_WEB)
const [showFullSetup, setShowFullSetup] = useState(false)
+ const { reportSDKSetupInstructionsSDKSelected } = useActions(eventUsageLogic)
const config = useMemo(() => SDK_CONFIGS[selectedSDK], [selectedSDK])
@@ -363,12 +360,13 @@ export function SDKSetupInstructions(): JSX.Element {
onChange={(value) => {
setSelectedSDK(value)
setShowFullSetup(false)
+ reportSDKSetupInstructionsSDKSelected(value, 'settings_sdk_setup')
}}
options={ALL_SDK_SELECT_OPTIONS}
className="max-w-80"
/>
<OnboardingDocsContentWrapper snippets={snippets} minimal useReverseProxy={isClientSideSDK}>
- <Installation modifySteps={filterToFirstRequiredStep} />
+ <Installation modifySteps={filterRequiredSteps} />
</OnboardingDocsContentWrapper>
<div className="flex items-center gap-2">
<LemonButton type="secondary" size="small" onClick={() => setShowFullSetup(true)}>
@@ -386,7 +384,7 @@ export function SDKSetupInstructions(): JSX.Element {
>
{wizardIntegrationName && <SetupWizardBanner integrationName={wizardIntegrationName} />}
<OnboardingDocsContentWrapper snippets={snippets} useReverseProxy={isClientSideSDK}>
- <Installation modifySteps={filterRequiredSteps} />
+ <Installation />
</OnboardingDocsContentWrapper>
<div className="mt-4">
<Link to={docsLink} target="_blank">