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(experiments): track which create-wizard steps people view (#108105)

ruby childs58cd3137b9af
diff --git a/frontend/src/lib/utils/eventUsageLogic.ts b/frontend/src/lib/utils/eventUsageLogic.ts
index 9c40085715d7..032b7d55a719 100644
--- a/frontend/src/lib/utils/eventUsageLogic.ts
+++ b/frontend/src/lib/utils/eventUsageLogic.ts
@@ -9,6 +9,7 @@ import { TimeToSeeDataPayload } from 'lib/internalMetrics'
import { preflightLogic } from 'lib/logic/preflightLogic'
import { objectClean } from 'lib/utils/objects'
import { BillingUsageInteractionProps } from 'scenes/billing/types'
+import type { ExperimentWizardStepNavigation } from 'scenes/experiments/ExperimentWizard/experimentWizardLogic'
import { SharedMetric } from 'scenes/experiments/SharedMetrics/sharedMetricLogic'
import type { InstallationErrorKind } from 'scenes/onboarding/shared/wizard-sync/installationProgressLogic'
import { ProductTourEvent } from 'scenes/product-tours/constants'
@@ -1219,6 +1220,17 @@ export interface eventUsageLogicActions {
reportExperimentWizardStarted: () => {
value: true
}
+ reportExperimentWizardStepViewed: (
+ step: string,
+ stepNumber: number,
+ previousStep: string | null,
+ navigation: ExperimentWizardStepNavigation
+ ) => {
+ navigation: ExperimentWizardStepNavigation
+ previousStep: string | null
+ step: string
+ stepNumber: number
+ }
reportExperimentsListAiBadgeClicked: () => {
value: true
}
@@ -1806,6 +1818,12 @@ export const eventUsageLogic = kea<eventUsageLogicType>([
breakdown,
isPrimary,
}),
+ reportExperimentWizardStepViewed: (
+ step: string,
+ stepNumber: number,
+ previousStep: string | null,
+ navigation: ExperimentWizardStepNavigation
+ ) => ({ step, stepNumber, previousStep, navigation }),
reportExperimentMetricBreakdownRemoved: (
experiment: Experiment,
metricUuid: string,
@@ -2380,6 +2398,14 @@ export const eventUsageLogic = kea<eventUsageLogicType>([
is_primary_metric: isPrimary,
})
},
+ reportExperimentWizardStepViewed: ({ step, stepNumber, previousStep, navigation }) => {
+ posthog.capture('experiment wizard step viewed', {
+ step,
+ step_number: stepNumber,
+ previous_step: previousStep,
+ navigation,
+ })
+ },
reportExperimentMetricBreakdownRemoved: ({ experiment, metricUuid, breakdown, index, isPrimary }) => {
posthog.capture('experiment metric breakdown removed', {
...getEventPropertiesForExperiment(experiment),
diff --git a/frontend/src/scenes/experiments/ExperimentWizard/experimentWizardLogic.test.tsx b/frontend/src/scenes/experiments/ExperimentWizard/experimentWizardLogic.test.tsx
index 0bbd84b21102..cb77102423db 100644
--- a/frontend/src/scenes/experiments/ExperimentWizard/experimentWizardLogic.test.tsx
+++ b/frontend/src/scenes/experiments/ExperimentWizard/experimentWizardLogic.test.tsx
@@ -6,6 +6,7 @@ import { cleanup, render, screen, waitFor } from '@testing-library/react'
import userEvent from '@testing-library/user-event'
import { BindLogic } from 'kea'
import { expectLogic, partial } from 'kea-test-utils'
+import posthog from 'posthog-js'
import { FEATURE_FLAGS } from 'lib/constants'
import { featureFlagLogic } from 'lib/logic/featureFlagLogic'
@@ -423,6 +424,68 @@ describe('experimentWizardLogic', () => {
expect(logic.values.currentStep).toBe('about')
})
+ it('reports each step view with the step it came from and how it was reached', async () => {
+ await expectLogic(logic, () => {
+ logic.actions.nextStep()
+ logic.actions.setStep('about')
+ }).toDispatchActions([
+ logic.actionCreators.reportExperimentWizardStepViewed('variants', 2, 'about', 'continue'),
+ logic.actionCreators.reportExperimentWizardStepViewed('about', 1, 'variants', 'stepper'),
+ ])
+
+ // Going back from the first step doesn't change the step, so it isn't a new view
+ await expectLogic(logic, () => {
+ logic.actions.prevStep()
+ }).toNotHaveDispatchedActions(['reportExperimentWizardStepViewed'])
+
+ await expectLogic(logic, () => {
+ logic.actions.nextStep()
+ logic.actions.prevStep()
+ }).toDispatchActions([
+ logic.actionCreators.reportExperimentWizardStepViewed('variants', 2, 'about', 'continue'),
+ logic.actionCreators.reportExperimentWizardStepViewed('about', 1, 'variants', 'back'),
+ ])
+ })
+
+ it('reports the first view as a start when the wizard opens on the first step', () => {
+ logic.unmount()
+ createLogic.unmount()
+
+ const capture = jest.spyOn(posthog, 'capture')
+ createLogic = createExperimentLogic()
+ createLogic.mount()
+ logic = experimentWizardLogic()
+ logic.mount()
+
+ expect(capture).toHaveBeenCalledWith('experiment wizard step viewed', {
+ step: 'about',
+ step_number: 1,
+ previous_step: null,
+ navigation: 'start',
+ })
+ capture.mockRestore()
+ })
+
+ it('reports the first view as a resume when the wizard reopens on a later step', async () => {
+ logic.actions.setStep('analytics')
+ logic.unmount()
+ createLogic.unmount()
+
+ const capture = jest.spyOn(posthog, 'capture')
+ createLogic = createExperimentLogic()
+ createLogic.mount()
+ logic = experimentWizardLogic()
+ logic.mount()
+
+ expect(capture).toHaveBeenCalledWith('experiment wizard step viewed', {
+ step: 'analytics',
+ step_number: 3,
+ previous_step: null,
+ navigation: 'resume',
+ })
+ capture.mockRestore()
+ })
+
it('remount preserves step when sessionStorage is not cleared', async () => {
logic.actions.setStep('variants')
await expectLogic(logic).toMatchValues({ currentStep: 'variants' })
diff --git a/frontend/src/scenes/experiments/ExperimentWizard/experimentWizardLogic.ts b/frontend/src/scenes/experiments/ExperimentWizard/experimentWizardLogic.ts
index 11301f6cdaf3..34d5af759386 100644
--- a/frontend/src/scenes/experiments/ExperimentWizard/experimentWizardLogic.ts
+++ b/frontend/src/scenes/experiments/ExperimentWizard/experimentWizardLogic.ts
@@ -20,6 +20,9 @@ import { getExperimentVariants, getFlagVariants } from '../utils'
export type ExperimentWizardStep = 'about' | 'variants' | 'analytics'
+/** How someone reached a step: opening the wizard on its first step, reopening it on a later one, or moving within it */
+export type ExperimentWizardStepNavigation = 'start' | 'resume' | 'continue' | 'back' | 'stepper'
+
const WIZARD_STEPS: ExperimentWizardStep[] = ['about', 'variants', 'analytics']
export function stepStorageKey(): string {
@@ -117,6 +120,17 @@ export interface experimentWizardLogicActions {
reportExperimentWizardStarted: () => {
value: true
} // eventUsageLogic
+ reportExperimentWizardStepViewed: (
+ step: string,
+ stepNumber: number,
+ previousStep: string | null,
+ navigation: ExperimentWizardStepNavigation
+ ) => {
+ navigation: ExperimentWizardStepNavigation
+ previousStep: string | null
+ step: string
+ stepNumber: number
+ } // eventUsageLogic
loadFeatureFlagsForAutocomplete: () => {
value: true
} // selectExistingFeatureFlagModalLogic
@@ -139,7 +153,11 @@ export interface experimentWizardLogicActions {
validateFeatureFlagKey: (key: string) => {
key: string
} // variantsPanelLogic
- _applyStep: (step: ExperimentWizardStep) => {
+ _applyStep: (
+ step: ExperimentWizardStep,
+ navigation: ExperimentWizardStepNavigation
+ ) => {
+ navigation: ExperimentWizardStepNavigation
step: ExperimentWizardStep
}
markStepDeparted: (step: ExperimentWizardStep) => {
@@ -228,7 +246,7 @@ export const experimentWizardLogic = kea<experimentWizardLogicType>([
selectExistingFeatureFlagModalLogic,
['loadFeatureFlagsForAutocomplete', 'loadFeatureFlagsSuccess'],
eventUsageLogic,
- ['reportExperimentWizardStarted'],
+ ['reportExperimentWizardStarted', 'reportExperimentWizardStepViewed'],
],
})),
@@ -239,7 +257,7 @@ export const experimentWizardLogic = kea<experimentWizardLogicType>([
nextStep: true,
prevStep: true,
// Internal: applies the step change after departure logic runs.
- _applyStep: (step: ExperimentWizardStep) => ({ step }),
+ _applyStep: (step: ExperimentWizardStep, navigation: ExperimentWizardStepNavigation) => ({ step, navigation }),
markStepDeparted: (step: ExperimentWizardStep) => ({ step }),
resetWizard: true,
setLinkedFeatureFlag: (flag: FeatureFlagType | null) => ({ flag }),
@@ -363,13 +381,17 @@ export const experimentWizardLogic = kea<experimentWizardLogicType>([
],
}),
- listeners(({ actions, values }) => ({
- _applyStep: ({ step }) => {
+ listeners(({ actions, values, selectors }) => ({
+ _applyStep: ({ step, navigation }, _, __, previousState) => {
try {
sessionStorage.setItem(stepStorageKey(), step)
} catch {
// ignore
}
+ const previousStep = selectors.currentStep(previousState)
+ if (step !== previousStep) {
+ actions.reportExperimentWizardStepViewed(step, STEP_ORDER[step] + 1, previousStep, navigation)
+ }
},
resetWizard: () => {
try {
@@ -411,7 +433,7 @@ export const experimentWizardLogic = kea<experimentWizardLogicType>([
nextStep: () => {
actions.markStepDeparted(values.currentStep)
const currentIndex = WIZARD_STEPS.indexOf(values.currentStep)
- actions._applyStep(WIZARD_STEPS[Math.min(currentIndex + 1, WIZARD_STEPS.length - 1)])
+ actions._applyStep(WIZARD_STEPS[Math.min(currentIndex + 1, WIZARD_STEPS.length - 1)], 'continue')
const key = values.experiment?.feature_flag_key
if (key && !values.linkedFeatureFlag && values.featureFlagKeyValidation === null) {
@@ -421,11 +443,11 @@ export const experimentWizardLogic = kea<experimentWizardLogicType>([
prevStep: () => {
actions.markStepDeparted(values.currentStep)
const currentIndex = WIZARD_STEPS.indexOf(values.currentStep)
- actions._applyStep(WIZARD_STEPS[Math.max(currentIndex - 1, 0)])
+ actions._applyStep(WIZARD_STEPS[Math.max(currentIndex - 1, 0)], 'back')
},
setStep: ({ step }) => {
actions.markStepDeparted(values.currentStep)
- actions._applyStep(step)
+ actions._applyStep(step, 'stepper')
const key = values.experiment?.feature_flag_key
if (key && !values.linkedFeatureFlag && values.featureFlagKeyValidation === null) {
@@ -439,9 +461,16 @@ export const experimentWizardLogic = kea<experimentWizardLogicType>([
},
})),
- events(({ actions }) => ({
+ events(({ actions, values }) => ({
afterMount: () => {
actions.reportExperimentWizardStarted()
+ // The wizard reopens on the step saved earlier in the session, so the first view can be a later step
+ actions.reportExperimentWizardStepViewed(
+ values.currentStep,
+ STEP_ORDER[values.currentStep] + 1,
+ null,
+ values.isFirstStep ? 'start' : 'resume'
+ )
actions.loadFeatureFlagsForAutocomplete()
},
})),