: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.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
fix(surveys): attribute quick-created surveys to their surface (#118532)
Juraj Majerikd9b999e9343a
diff --git a/frontend/src/lib/utils/eventUsageLogic.ts b/frontend/src/lib/utils/eventUsageLogic.tsindex 2eb8f47adb06..39c363e0d31e 100644--- a/frontend/src/lib/utils/eventUsageLogic.ts+++ b/frontend/src/lib/utils/eventUsageLogic.ts@@ -1563,8 +1563,10 @@ export interface eventUsageLogicActions {reportSurveyCreated: (survey: Survey,isDuplicate?: boolean,- creationSource?: 'form_builder' | 'full_editor' | 'llm_analytics' | 'quick_create' | 'template' | 'wizard'+ creationSource?: 'form_builder' | 'full_editor' | 'llm_analytics' | 'quick_create' | 'template' | 'wizard',+ createdFrom?: SURVEY_CREATED_SOURCE) => {+ createdFrom: SURVEY_CREATED_SOURCE | undefinedcreationSource:| 'form_builder'| 'full_editor'@@ -2053,8 +2055,9 @@ export const eventUsageLogic = kea<eventUsageLogicType>([reportSurveyCreated: (survey: Survey,isDuplicate?: boolean,- creationSource?: 'wizard' | 'full_editor' | 'quick_create' | 'template' | 'llm_analytics' | 'form_builder'- ) => ({ survey, isDuplicate, creationSource }),+ creationSource?: 'wizard' | 'full_editor' | 'quick_create' | 'template' | 'llm_analytics' | 'form_builder',+ createdFrom?: SURVEY_CREATED_SOURCE+ ) => ({ survey, isDuplicate, creationSource, createdFrom }),reportUserFeedbackButtonClicked: (source: SURVEY_CREATED_SOURCE, meta: Record<string, any>) => ({source,meta,@@ -2797,7 +2800,7 @@ export const eventUsageLogic = kea<eventUsageLogicType>([language,})},- reportSurveyCreated: ({ survey, isDuplicate, creationSource }) => {+ reportSurveyCreated: ({ survey, isDuplicate, creationSource, createdFrom }) => {const questionsWithShuffledOptions = survey.questions.filter((question) => {return question.hasOwnProperty('shuffleOptions') && (question as MultipleSurveyQuestion).shuffleOptions})@@ -2814,6 +2817,7 @@ export const eventUsageLogic = kea<eventUsageLogicType>([question_types: survey.questions.map((question) => question.type),is_duplicate: isDuplicate ?? false,creation_source: creationSource ?? 'full_editor',+ created_from: createdFrom,linked_insight_id: survey.linked_insight_id,events_count: survey.conditions?.events?.values.length,recurring_survey_iteration_count: survey.iteration_count == undefined ? 0 : survey.iteration_count,diff --git a/frontend/src/scenes/surveys/quick-create/quickSurveyFormLogic.test.ts b/frontend/src/scenes/surveys/quick-create/quickSurveyFormLogic.test.tsindex 724d2e723093..c5d5b2d41414 100644--- a/frontend/src/scenes/surveys/quick-create/quickSurveyFormLogic.test.ts+++ b/frontend/src/scenes/surveys/quick-create/quickSurveyFormLogic.test.ts@@ -1,9 +1,14 @@import { expectLogic } from 'kea-test-utils'+import posthog from 'posthog-js'+import { eventUsageLogic } from 'lib/utils/eventUsageLogic'++import { useMocks } from '~/mocks/jest'import { initKeaTests } from '~/test/init'import { FeatureFlagType } from '~/types'import { SURVEY_CREATED_SOURCE } from '../constants'+import { surveysLogic } from '../surveysLogic'import { FunnelContext, toSurveyEvent } from '../utils/opportunityDetection'import { quickSurveyFormLogic } from './quickSurveyFormLogic'import { QuickSurveyType } from './types'@@ -141,4 +146,37 @@ describe('quickSurveyFormLogic validation', () => {}),})})++ it('reports the quick-create surface on the survey created event', async () => {+ useMocks({+ get: {+ '/api/projects/:team/surveys/': { count: 0, results: [], next: null, previous: null },+ },+ post: {+ '/api/projects/:team/surveys/': () => [+ 201,+ { id: 'survey-1', name: 'Checkout test - Quick feedback', type: 'popover', questions: [] },+ ],+ },+ })+ eventUsageLogic.mount()+ surveysLogic.mount()+ const captureSpy = jest.spyOn(posthog, 'capture').mockReturnValue(undefined as any)+ const logic = quickSurveyFormLogic({+ key: 'test-submit',+ source: SURVEY_CREATED_SOURCE.EXPERIMENTS,+ contextType: QuickSurveyType.EXPERIMENT,+ defaults: { name: 'Checkout test - Quick feedback', question: 'This update?' },+ })+ logic.mount()++ await expectLogic(logic, () => logic.actions.setCreateMode('launch')).toDispatchActions([+ 'submitSurveyFormSuccess',+ ])++ expect(captureSpy).toHaveBeenCalledWith(+ 'survey created',+ expect.objectContaining({ creation_source: 'quick_create', created_from: 'experiments' })+ )+ })})diff --git a/frontend/src/scenes/surveys/quick-create/quickSurveyFormLogic.ts b/frontend/src/scenes/surveys/quick-create/quickSurveyFormLogic.tsindex bbb7d59e01d6..b842246a3e6a 100644--- a/frontend/src/scenes/surveys/quick-create/quickSurveyFormLogic.ts+++ b/frontend/src/scenes/surveys/quick-create/quickSurveyFormLogic.ts@@ -262,7 +262,7 @@ export const quickSurveyFormLogic = kea<quickSurveyFormLogicType>([const response = await api.surveys.create(surveyData)- eventUsageLogic.actions.reportSurveyCreated(response)+ eventUsageLogic.actions.reportSurveyCreated(response, false, 'quick_create', props.source)addProductIntent({product_type: ProductKey.SURVEYS,intent_context: ProductIntentContext.SURVEY_CREATED,diff --git a/frontend/src/scenes/surveys/surveyLogic.tsx b/frontend/src/scenes/surveys/surveyLogic.tsxindex 2a3d5f5db8ca..c5809b2f83e4 100644--- a/frontend/src/scenes/surveys/surveyLogic.tsx+++ b/frontend/src/scenes/surveys/surveyLogic.tsx@@ -825,8 +825,10 @@ export interface surveyLogicActions {| 'quick_create'| 'template'| 'wizard'- | undefined+ | undefined,+ createdFrom?: SURVEY_CREATED_SOURCE | undefined) => {+ createdFrom: SURVEY_CREATED_SOURCE | undefinedcreationSource:| 'form_builder'| 'full_editor'diff --git a/frontend/src/scenes/surveys/wizard/surveyWizardLogic.ts b/frontend/src/scenes/surveys/wizard/surveyWizardLogic.tsindex 06f899351d30..ea60f5989578 100644--- a/frontend/src/scenes/surveys/wizard/surveyWizardLogic.ts+++ b/frontend/src/scenes/surveys/wizard/surveyWizardLogic.ts@@ -111,8 +111,10 @@ export interface surveyWizardLogicActions {| 'quick_create'| 'template'| 'wizard'- | undefined+ | undefined,+ createdFrom?: SURVEY_CREATED_SOURCE | undefined) => {+ createdFrom: SURVEY_CREATED_SOURCE | undefinedcreationSource:| 'form_builder'| 'full_editor'