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.

chore(onboarding): share typed funnel event reporters (#107904)

Paul D'Ambraa057ee99c5aa
diff --git a/frontend/src/lib/utils/eventUsageLogic.test.ts b/frontend/src/lib/utils/eventUsageLogic.test.ts
index 4b8d91a0f84c..b050e7c25ac3 100644
--- a/frontend/src/lib/utils/eventUsageLogic.test.ts
+++ b/frontend/src/lib/utils/eventUsageLogic.test.ts
@@ -18,7 +18,6 @@ import {
type DashboardType,
FilterLogicalOperator,
FunnelVizType,
- OnboardingStepKey,
PropertyFilterType,
StepOrderValue,
} from '~/types'
@@ -31,37 +30,6 @@ import {
} from './eventUsageLogic'
describe('eventUsageLogic', () => {
- describe('onboarding funnel events', () => {
- let capture: jest.SpyInstance
-
- beforeEach(() => {
- initKeaTests()
- eventUsageLogic.mount()
- capture = jest.spyOn(posthog, 'capture').mockImplementation()
- })
-
- afterEach(() => {
- capture.mockRestore()
- })
-
- it('stamps the entry point on every funnel event', () => {
- eventUsageLogic.actions.reportOnboardingStarted()
- eventUsageLogic.actions.reportOnboardingStepCompleted(OnboardingStepKey.INSTALL)
- eventUsageLogic.actions.reportOnboardingStepSkipped(OnboardingStepKey.INSTALL)
- eventUsageLogic.actions.reportOnboardingCompleted('product_analytics')
-
- for (const event of [
- 'onboarding started',
- 'onboarding step completed',
- 'onboarding step skipped',
- 'onboarding completed',
- ]) {
- const call = capture.mock.calls.find(([name]) => name === event)
- expect(call?.[1]).toMatchObject({ entry_point: 'product_selection' })
- }
- })
- })
-
describe('experiments list viewed', () => {
it('sends the state of the list under its pinned property names', () => {
initKeaTests()
diff --git a/frontend/src/lib/utils/eventUsageLogic.ts b/frontend/src/lib/utils/eventUsageLogic.ts
index 2b8b92efadfd..2affe0d0fd49 100644
--- a/frontend/src/lib/utils/eventUsageLogic.ts
+++ b/frontend/src/lib/utils/eventUsageLogic.ts
@@ -63,7 +63,6 @@ import {
ExperimentIdType,
ExperimentStatsMethod,
FunnelCorrelation,
- OnboardingStepKey,
ProductTour,
PropertyFilterType,
InsightModel,
@@ -438,15 +437,6 @@ export type SDKSetupInstructionsSurface =
| 'settings_reverse_proxy_setup'
| 'onboarding_ai_observability'
-// pinned: event property values. Onboarding funnel insights filter and break down on these, so
-// they keep the values the flow sent while it was one of two experiment arms. `entry_point` rides
-// along with every funnel event, not only `started`, so a breakdown by it stays populated.
-const ONBOARDING_EVENT_PROPS = {
- version: 1,
- flow_variant: 'legacy',
- entry_point: 'product_selection',
-} as const
-
function retentionWindowDays(metric: ExperimentRetentionMetric): number | undefined {
const unitToDays: Record<string, number> = { day: 1, week: 7, month: 30 }
const multiplier = unitToDays[metric.retention_window_unit]
@@ -1400,42 +1390,6 @@ export interface eventUsageLogicActions {
itemType: string | null | undefined
section: string
}
- reportOnboardingCompleted: (productKey: string) => {
- productKey: string
- }
- reportOnboardingProductToggled: (
- productKey: string,
- selected: boolean,
- recommendationSource: string
- ) => {
- productKey: string
- recommendationSource: string
- selected: boolean
- }
- reportOnboardingStarted: () => {
- value: true
- }
- reportOnboardingStepCompleted: (
- stepKey: OnboardingStepKey,
- productKey?: string
- ) => {
- productKey: string | undefined
- stepKey: OnboardingStepKey
- }
- reportOnboardingStepSkipped: (
- stepKey: OnboardingStepKey,
- productKey?: string
- ) => {
- productKey: string | undefined
- stepKey: OnboardingStepKey
- }
- reportOnboardingUseCaseSelected: (
- useCase: string,
- recommendedProducts: readonly string[]
- ) => {
- recommendedProducts: readonly string[]
- useCase: string
- }
reportPersonOpenedFromNewlySeenPersonsList: () => {
value: true
}
@@ -2005,25 +1959,6 @@ export const eventUsageLogic = kea<eventUsageLogicType>([
}),
reportProductTourListViewed: true,
reportProductUnsubscribed: (product: string) => ({ product }),
- reportOnboardingStarted: true,
- reportOnboardingStepCompleted: (stepKey: OnboardingStepKey, productKey?: string) => ({
- stepKey,
- productKey,
- }),
- reportOnboardingStepSkipped: (stepKey: OnboardingStepKey, productKey?: string) => ({
- stepKey,
- productKey,
- }),
- reportOnboardingCompleted: (productKey: string) => ({ productKey }),
- reportOnboardingUseCaseSelected: (useCase: string, recommendedProducts: readonly string[]) => ({
- useCase,
- recommendedProducts,
- }),
- reportOnboardingProductToggled: (productKey: string, selected: boolean, recommendationSource: string) => ({
- productKey,
- selected,
- recommendationSource,
- }),
reportBillingCTAShown: true,
reportBillingUsageInteraction: (properties: BillingUsageInteractionProps) => ({ properties }),
reportBillingSpendInteraction: (properties: BillingUsageInteractionProps) => ({ properties }),
@@ -2764,47 +2699,6 @@ export const eventUsageLogic = kea<eventUsageLogicType>([
$set: { [property_key]: true },
})
},
- // onboarding
- reportOnboardingStarted: () => {
- posthog.capture('onboarding started', ONBOARDING_EVENT_PROPS)
- },
- reportOnboardingStepCompleted: ({ stepKey, productKey }) => {
- posthog.capture('onboarding step completed', {
- step_key: stepKey,
- // Optional — only set when the caller knows which product owns the step.
- // Lets dashboards split step funnels by product without joining elsewhere.
- ...(productKey ? { product_key: productKey } : {}),
- ...ONBOARDING_EVENT_PROPS,
- })
- },
- reportOnboardingStepSkipped: ({ stepKey, productKey }) => {
- posthog.capture('onboarding step skipped', {
- step_key: stepKey,
- ...(productKey ? { product_key: productKey } : {}),
- ...ONBOARDING_EVENT_PROPS,
- })
- },
- reportOnboardingCompleted: ({ productKey }) => {
- posthog.capture('onboarding completed', {
- product_key: productKey,
- ...ONBOARDING_EVENT_PROPS,
- })
- },
- reportOnboardingUseCaseSelected: ({ useCase, recommendedProducts }) => {
- posthog.capture('onboarding use case selected', {
- use_case: useCase,
- recommended_products: recommendedProducts,
- ...ONBOARDING_EVENT_PROPS,
- })
- },
- reportOnboardingProductToggled: ({ productKey, selected, recommendationSource }) => {
- posthog.capture('onboarding product toggled', {
- product_key: productKey,
- selected,
- recommendation_source: recommendationSource,
- ...ONBOARDING_EVENT_PROPS,
- })
- },
reportSDKSelected: ({ sdk }) => {
posthog.capture('sdk selected', {
sdk: sdk.key,
diff --git a/frontend/src/scenes/onboarding/OnboardingStep.tsx b/frontend/src/scenes/onboarding/OnboardingStep.tsx
index 220da5a509fc..abf8b5652a8a 100644
--- a/frontend/src/scenes/onboarding/OnboardingStep.tsx
+++ b/frontend/src/scenes/onboarding/OnboardingStep.tsx
@@ -6,7 +6,7 @@ import { IconArrowRight } from '@posthog/icons'
import { LemonButton } from '@posthog/lemon-ui'
import { supportLogic } from 'lib/components/Support/supportLogic'
-import { eventUsageLogic } from 'lib/utils/eventUsageLogic'
+import { reportOnboardingStepCompleted, reportOnboardingStepSkipped } from 'scenes/onboarding/onboardingUsage'
import { OnboardingStepKey } from '~/types'
@@ -50,7 +50,6 @@ export const OnboardingStep = ({
const { hasNextStep, currentStepProductKey } = useValues(onboardingLogic)
const { completeOnboarding, goToNextStep } = useActions(onboardingLogic)
- const { reportOnboardingStepCompleted, reportOnboardingStepSkipped } = useActions(eventUsageLogic)
const { openSupportForm } = useActions(supportLogic)
const advance: () => void = !hasNextStep ? completeOnboarding : goToNextStep
diff --git a/frontend/src/scenes/onboarding/billing/OnboardingUpgradeStep.tsx b/frontend/src/scenes/onboarding/billing/OnboardingUpgradeStep.tsx
index b3553b86bd7a..ab284e349408 100644
--- a/frontend/src/scenes/onboarding/billing/OnboardingUpgradeStep.tsx
+++ b/frontend/src/scenes/onboarding/billing/OnboardingUpgradeStep.tsx
@@ -7,9 +7,9 @@ import { LemonButton, Spinner } from '@posthog/lemon-ui'
import { pngHoggie } from 'lib/brand/hoggies'
import { useHogfetti } from 'lib/components/Hogfetti/Hogfetti'
-import { eventUsageLogic } from 'lib/utils/eventUsageLogic'
import { billingLogic } from 'scenes/billing/billingLogic'
import { PlatformAddonComparison } from 'scenes/billing/PlatformAddonComparison'
+import { reportOnboardingStepCompleted, reportOnboardingStepSkipped } from 'scenes/onboarding/onboardingUsage'
import { ProductKey } from '~/queries/schema/schema-general'
import { type BillingProductV2Type, OnboardingStepKey } from '~/types'
@@ -27,7 +27,6 @@ type OnboardingUpgradeStepProps = {
export const OnboardingUpgradeStep: OnboardingStepComponentType<OnboardingUpgradeStepProps> = ({ product }) => {
const { billing, billingLoading } = useValues(billingLogic)
const { goToNextStep } = useActions(onboardingLogic)
- const { reportOnboardingStepSkipped, reportOnboardingStepCompleted } = useActions(eventUsageLogic)
if (billingLoading) {
return (
diff --git a/frontend/src/scenes/onboarding/billing/PlanCards.tsx b/frontend/src/scenes/onboarding/billing/PlanCards.tsx
index 3af9c9fd06ed..1de4e8700cff 100644
--- a/frontend/src/scenes/onboarding/billing/PlanCards.tsx
+++ b/frontend/src/scenes/onboarding/billing/PlanCards.tsx
@@ -10,11 +10,11 @@ import { LemonButton } from '@posthog/lemon-ui'
import { pngHoggie } from 'lib/brand/hoggies'
import { BillingUpgradeCTA } from 'lib/components/BillingUpgradeCTA'
-import { eventUsageLogic } from 'lib/utils/eventUsageLogic'
import { pluralize } from 'lib/utils/strings'
import { billingLogic } from 'scenes/billing/billingLogic'
import { billingProductLogic } from 'scenes/billing/billingProductLogic'
import { paymentEntryLogic } from 'scenes/billing/paymentEntryLogic'
+import { reportOnboardingStepCompleted } from 'scenes/onboarding/onboardingUsage'
import { type BillingFeatureType, type BillingProductV2Type, OnboardingStepKey } from '~/types'
@@ -67,7 +67,6 @@ export function formatDataRetentionFeature(feature?: BillingFeatureType): string
export const PlanCard: React.FC<PlanCardProps> = ({ planData, product, highlight, hogPosition = 'top-right' }) => {
const { billing } = useValues(billingLogic)
const { billingProductLoading } = useValues(billingProductLogic({ product }))
- const { reportOnboardingStepCompleted } = useActions(eventUsageLogic)
const [isHovering, setIsHovering] = useState<boolean | undefined>(undefined)
const { goToNextStep } = useActions(onboardingLogic)
diff --git a/frontend/src/scenes/onboarding/data-warehouse/OnboardingDataWarehouseSourcesStep.tsx b/frontend/src/scenes/onboarding/data-warehouse/OnboardingDataWarehouseSourcesStep.tsx
index 7c346c63f40b..b4d9ac97d60a 100644
--- a/frontend/src/scenes/onboarding/data-warehouse/OnboardingDataWarehouseSourcesStep.tsx
+++ b/frontend/src/scenes/onboarding/data-warehouse/OnboardingDataWarehouseSourcesStep.tsx
@@ -1,6 +1,6 @@
import { useActions, useValues } from 'kea'
-import { eventUsageLogic } from 'lib/utils/eventUsageLogic'
+import { reportOnboardingStepCompleted } from 'scenes/onboarding/onboardingUsage'
import { OnboardingStepKey } from '~/types'
@@ -12,7 +12,6 @@ import { OnboardingStep } from '../OnboardingStep'
export const OnboardingDataWarehouseSourcesStep: OnboardingStepComponentType = () => {
const { goToNextStep } = useActions(onboardingLogic)
- const { reportOnboardingStepCompleted } = useActions(eventUsageLogic)
const { availableSourcesLoading } = useValues(availableSourcesLogic)
return (
<OnboardingStep
diff --git a/frontend/src/scenes/onboarding/onboardingLogic.tsx b/frontend/src/scenes/onboarding/onboardingLogic.tsx
index 76fa9e6fb303..6b5c88186776 100644
--- a/frontend/src/scenes/onboarding/onboardingLogic.tsx
+++ b/frontend/src/scenes/onboarding/onboardingLogic.tsx
@@ -8,10 +8,10 @@ import { type SetupTaskId } from 'lib/components/ProductSetup'
import { globalSetupLogic } from 'lib/components/ProductSetup/globalSetupLogic'
import { OrganizationMembershipLevel } from 'lib/constants'
import { featureFlagLogic } from 'lib/logic/featureFlagLogic'
-import { eventUsageLogic } from 'lib/utils/eventUsageLogic'
import { isKeyOf } from 'lib/utils/guards'
import { removeProjectIdIfPresent } from 'lib/utils/kea-router'
import { billingLogic } from 'scenes/billing/billingLogic'
+import { reportOnboardingCompleted } from 'scenes/onboarding/onboardingUsage'
import { availableOnboardingProducts } from 'scenes/onboarding/shared/utils'
import { organizationLogic } from 'scenes/organizationLogic'
import { preflightLogic } from 'scenes/PreflightCheck/preflightLogic'
@@ -705,7 +705,7 @@ export const onboardingLogic = kea<onboardingLogicType>([
// changing dashboards. Secondary products are still recorded via
// `recordProductIntentOnboardingComplete` and `has_completed_onboarding_for`,
// but don't fire an additional `onboarding completed` analytics event.
- eventUsageLogic.actions.reportOnboardingCompleted(primary)
+ reportOnboardingCompleted(primary)
props.onCompleteOnboarding?.(primary)
// Error Tracking has a side-effect tied to onboarding completion (set up in the
// legacy view): turn on autocapture_exceptions_opt_in. Preserved here.
diff --git a/frontend/src/scenes/onboarding/onboardingUsage.test.ts b/frontend/src/scenes/onboarding/onboardingUsage.test.ts
new file mode 100644
index 000000000000..a4e74523bbc9
--- /dev/null
+++ b/frontend/src/scenes/onboarding/onboardingUsage.test.ts
@@ -0,0 +1,40 @@
+import posthog from 'posthog-js'
+
+import { OnboardingStepKey } from '~/types'
+
+import {
+ reportOnboardingCompleted,
+ reportOnboardingStarted,
+ reportOnboardingStepCompleted,
+ reportOnboardingStepSkipped,
+} from './onboardingUsage'
+
+describe('onboardingUsage', () => {
+ afterEach(() => {
+ jest.restoreAllMocks()
+ })
+
+ it('keeps the funnel event properties', () => {
+ const capture = jest.spyOn(posthog, 'capture').mockImplementation()
+
+ reportOnboardingStarted()
+ reportOnboardingStepCompleted(OnboardingStepKey.INSTALL)
+ reportOnboardingStepSkipped(OnboardingStepKey.INSTALL)
+ reportOnboardingCompleted('product_analytics')
+
+ const sharedProperties = { entry_point: 'product_selection', flow_variant: 'legacy', version: 1 }
+ expect(capture).toHaveBeenNthCalledWith(1, 'onboarding started', sharedProperties)
+ expect(capture).toHaveBeenNthCalledWith(2, 'onboarding step completed', {
+ step_key: 'install',
+ ...sharedProperties,
+ })
+ expect(capture).toHaveBeenNthCalledWith(3, 'onboarding step skipped', {
+ step_key: 'install',
+ ...sharedProperties,
+ })
+ expect(capture).toHaveBeenNthCalledWith(4, 'onboarding completed', {
+ product_key: 'product_analytics',
+ ...sharedProperties,
+ })
+ })
+})
diff --git a/frontend/src/scenes/onboarding/onboardingUsage.ts b/frontend/src/scenes/onboarding/onboardingUsage.ts
new file mode 100644
index 000000000000..302c5c16b10c
--- /dev/null
+++ b/frontend/src/scenes/onboarding/onboardingUsage.ts
@@ -0,0 +1,41 @@
+import posthog from 'posthog-js'
+
+import type { OnboardingStepKey } from '~/types'
+
+// pinned: event property values. Onboarding funnel insights filter and break down on these, so
+// they keep the values the flow sent while it was one of two experiment arms. `entry_point` rides
+// along with every funnel event, not only `started`, so a breakdown by it stays populated.
+export const ONBOARDING_EVENT_PROPS = {
+ version: 1,
+ flow_variant: 'legacy',
+ entry_point: 'product_selection',
+} as const
+
+export function reportOnboardingStarted(): void {
+ posthog.capture('onboarding started', ONBOARDING_EVENT_PROPS)
+}
+
+export function reportOnboardingCompleted(productKey: string): void {
+ posthog.capture('onboarding completed', {
+ product_key: productKey,
+ ...ONBOARDING_EVENT_PROPS,
+ })
+}
+
+export function reportOnboardingStepCompleted(stepKey: OnboardingStepKey, productKey?: string): void {
+ posthog.capture('onboarding step completed', {
+ step_key: stepKey,
+ // Optional — only set when the caller knows which product owns the step.
+ // Lets dashboards split step funnels by product without joining elsewhere.
+ ...(productKey ? { product_key: productKey } : {}),
+ ...ONBOARDING_EVENT_PROPS,
+ })
+}
+
+export function reportOnboardingStepSkipped(stepKey: OnboardingStepKey, productKey?: string): void {
+ posthog.capture('onboarding step skipped', {
+ step_key: stepKey,
+ ...(productKey ? { product_key: productKey } : {}),
+ ...ONBOARDING_EVENT_PROPS,
+ })
+}
diff --git a/frontend/src/scenes/onboarding/productSelection/productSelectionLogic.ts b/frontend/src/scenes/onboarding/productSelection/productSelectionLogic.ts
index 7b681c4e2880..9a439cf22afe 100644
--- a/frontend/src/scenes/onboarding/productSelection/productSelectionLogic.ts
+++ b/frontend/src/scenes/onboarding/productSelection/productSelectionLogic.ts
@@ -2,9 +2,9 @@ import { MakeLogicType, actions, afterMount, connect, kea, listeners, path, redu
import { router } from 'kea-router'
import posthog from 'posthog-js'
-import { eventUsageLogic } from 'lib/utils/eventUsageLogic'
import { getRelativeNextPath } from 'lib/utils/url'
import { onboardingLogic } from 'scenes/onboarding/onboardingLogic'
+import { ONBOARDING_EVENT_PROPS, reportOnboardingStarted } from 'scenes/onboarding/onboardingUsage'
import { USE_CASE_OPTIONS, UseCaseOption, getRecommendedProducts } from 'scenes/onboarding/productRecommendations'
import { availableOnboardingProducts } from 'scenes/onboarding/shared/utils'
import { teamLogic } from 'scenes/teamLogic'
@@ -64,18 +64,6 @@ export interface productSelectionLogicValues {
// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
export interface productSelectionLogicActions {
- reportOnboardingProductToggled: (
- productKey: string,
- selected: boolean,
- recommendationSource: string
- ) => {
- productKey: string
- recommendationSource: string
- selected: boolean
- } // eventUsageLogic
- reportOnboardingStarted: () => {
- value: true
- } // eventUsageLogic
setOnCompleteOnboardingRedirectUrl: (url: string | null) => {
url: string | null
} // onboardingLogic
@@ -147,14 +135,7 @@ export const productSelectionLogic = kea<productSelectionLogicType>([
path(['scenes', 'onboarding', 'productSelection', 'productSelectionLogic']),
connect(() => ({
- actions: [
- teamLogic,
- ['addProductIntent'],
- onboardingLogic,
- ['setOnCompleteOnboardingRedirectUrl'],
- eventUsageLogic,
- ['reportOnboardingStarted', 'reportOnboardingProductToggled'],
- ],
+ actions: [teamLogic, ['addProductIntent'], onboardingLogic, ['setOnCompleteOnboardingRedirectUrl']],
values: [teamLogic, ['currentTeam']],
})),
@@ -366,7 +347,12 @@ export const productSelectionLogic = kea<productSelectionLogicType>([
actions.setFirstProductOnboarding(remaining[0] || null)
}
- actions.reportOnboardingProductToggled(productKey, isNowSelected, values.recommendationSource)
+ posthog.capture('onboarding product toggled', {
+ product_key: productKey,
+ selected: isNowSelected,
+ recommendation_source: values.recommendationSource,
+ ...ONBOARDING_EVENT_PROPS,
+ })
},
selectSingleProduct: ({ productKey }) => {
@@ -445,6 +431,6 @@ export const productSelectionLogic = kea<productSelectionLogicType>([
}
}
- actions.reportOnboardingStarted()
+ reportOnboardingStarted()
}),
])
diff --git a/frontend/src/scenes/onboarding/sdks/OnboardingInstallStep/NextButton.tsx b/frontend/src/scenes/onboarding/sdks/OnboardingInstallStep/NextButton.tsx
index a6c3ea9bba26..61f108bcd62c 100644
--- a/frontend/src/scenes/onboarding/sdks/OnboardingInstallStep/NextButton.tsx
+++ b/frontend/src/scenes/onboarding/sdks/OnboardingInstallStep/NextButton.tsx
@@ -3,7 +3,7 @@ import { useActions, useValues } from 'kea'
import { IconArrowRight } from '@posthog/icons'
import { LemonButton } from '@posthog/lemon-ui'
-import { eventUsageLogic } from 'lib/utils/eventUsageLogic'
+import { reportOnboardingStepCompleted, reportOnboardingStepSkipped } from 'scenes/onboarding/onboardingUsage'
import { OnboardingStepKey } from '~/types'
@@ -17,7 +17,6 @@ interface NextButtonProps {
export const NextButton = ({ installationComplete, size = 'medium' }: NextButtonProps): JSX.Element => {
const { hasNextStep, currentStepProductKey } = useValues(onboardingLogic)
const { completeOnboarding, goToNextStep } = useActions(onboardingLogic)
- const { reportOnboardingStepCompleted, reportOnboardingStepSkipped } = useActions(eventUsageLogic)
const advance = !hasNextStep ? completeOnboarding : goToNextStep
const skipInstallation = (): void => {