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(experiments): record the wizard's vision scanner as a cross-sell (#79775)

Marcel Poelker35989c898aae
diff --git a/frontend/src/scenes/experiments/ExperimentForm/createExperimentLogic.test.ts b/frontend/src/scenes/experiments/ExperimentForm/createExperimentLogic.test.ts
index 8fd438190af5..897620e54d48 100644
--- a/frontend/src/scenes/experiments/ExperimentForm/createExperimentLogic.test.ts
+++ b/frontend/src/scenes/experiments/ExperimentForm/createExperimentLogic.test.ts
@@ -9,7 +9,12 @@ import { featureFlagLogic } from 'lib/logic/featureFlagLogic'
import { refreshTreeItem } from '~/layout/panel-layout/ProjectTree/projectTreeLogic'
import { useMocks } from '~/mocks/jest'
-import { type ExperimentExposureCriteria, NodeKind } from '~/queries/schema/schema-general'
+import {
+ type ExperimentExposureCriteria,
+ NodeKind,
+ ProductIntentContext,
+ ProductKey,
+} from '~/queries/schema/schema-general'
import { initKeaTests } from '~/test/init'
import type { Experiment } from '~/types'
@@ -34,6 +39,7 @@ describe('createExperimentLogic', () => {
let routerPushSpy: jest.SpyInstance
let scannerCreateSpy: jest.Mock
let scannerRequestBody: Record<string, unknown> | null
+ let productIntentBodies: Record<string, unknown>[]
let exposureEventSeenWithSessionId: boolean
beforeEach(() => {
@@ -41,6 +47,7 @@ describe('createExperimentLogic', () => {
localStorage.clear()
sessionStorage.clear()
scannerRequestBody = null
+ productIntentBodies = []
exposureEventSeenWithSessionId = true
scannerCreateSpy = jest.fn(async ({ request }: { request: Request }) => {
scannerRequestBody = (await request.json()) as Record<string, unknown>
@@ -82,7 +89,10 @@ describe('createExperimentLogic', () => {
'/api/projects/:team_id/vision/scanners/': scannerCreateSpy,
},
patch: {
- '/api/environments/:team_id/add_product_intent/': () => [200, {}],
+ '/api/environments/:team_id/add_product_intent/': async ({ request }) => {
+ productIntentBodies.push((await request.json()) as Record<string, unknown>)
+ return [200, {}]
+ },
},
})
initKeaTests()
@@ -209,6 +219,19 @@ describe('createExperimentLogic', () => {
],
},
})
+ // A plain product intent is indistinguishable from someone reaching Replay Vision on their
+ // own, so the cross-sell metadata is the only thing that attributes the scanner to experiments
+ expect(productIntentBodies).toContainEqual(
+ expect.objectContaining({
+ product_type: ProductKey.REPLAY_VISION,
+ intent_context: ProductIntentContext.EXPERIMENT_REPLAY_VISION_SCANNER_CREATED,
+ metadata: expect.objectContaining({
+ from: ProductKey.EXPERIMENTS,
+ to: ProductKey.REPLAY_VISION,
+ type: 'cross_sell',
+ }),
+ })
+ )
expect(lemonToast.success).toHaveBeenCalledWith(
'Experiment created. The Replay Vision scanner is off until you turn it on.',
expect.objectContaining({
diff --git a/frontend/src/scenes/experiments/ExperimentForm/createExperimentLogic.ts b/frontend/src/scenes/experiments/ExperimentForm/createExperimentLogic.ts
index 533eba68115d..197c496e28be 100644
--- a/frontend/src/scenes/experiments/ExperimentForm/createExperimentLogic.ts
+++ b/frontend/src/scenes/experiments/ExperimentForm/createExperimentLogic.ts
@@ -32,7 +32,7 @@ import type {
import { visionScannersCreate } from 'products/replay_vision/frontend/generated/api'
import type { FeatureFlagsSet } from '../../../lib/logic/featureFlagLogic'
-import type { ProductIntentProperties } from '../../../lib/utils/product-intents'
+import type { ProductCrossSellProperties, ProductIntentProperties } from '../../../lib/utils/product-intents'
import type { ExperimentMetricUnion } from '../../../queries/schema/schema-general'
import type { FeatureFlagType } from '../../../types'
import { NEW_EXPERIMENT } from '../constants'
@@ -171,6 +171,7 @@ export interface createExperimentLogicActions {
flag: FeatureFlagType
} // featureFlagsLogic
addProductIntent: (properties: ProductIntentProperties) => ProductIntentProperties // teamLogic
+ addProductIntentForCrossSell: (properties: ProductCrossSellProperties) => ProductCrossSellProperties // teamLogic
cancelForm: () => {
value: true
}
@@ -290,7 +291,7 @@ export const createExperimentLogic = kea<createExperimentLogicType>([
featureFlagsLogic,
['updateFlag'],
teamLogic,
- ['addProductIntent'],
+ ['addProductIntent', 'addProductIntentForCrossSell'],
],
})),
actions(() => ({
@@ -635,8 +636,9 @@ export const createExperimentLogic = kea<createExperimentLogicType>([
experimentScannerBody(response, filters, usedExposureFallback)
)
replayScannerId = replayScanner.id
- actions.addProductIntent({
- product_type: ProductKey.REPLAY_VISION,
+ actions.addProductIntentForCrossSell({
+ from: ProductKey.EXPERIMENTS,
+ to: ProductKey.REPLAY_VISION,
intent_context: ProductIntentContext.EXPERIMENT_REPLAY_VISION_SCANNER_CREATED,
})
} catch (scannerError) {