: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
chore(surveys): localize typed event usage reporting (#107826)
Paul D'Ambra72026011b1c2
diff --git a/frontend/src/lib/utils/eventUsageLogic.ts b/frontend/src/lib/utils/eventUsageLogic.tsindex 39c363e0d31e..4b99d649e4c3 100644--- a/frontend/src/lib/utils/eventUsageLogic.ts+++ b/frontend/src/lib/utils/eventUsageLogic.ts@@ -63,18 +63,17 @@ import {ExperimentIdType,ExperimentStatsMethod,FunnelCorrelation,- MultipleSurveyQuestion,OnboardingStepKey,ProductTour,PropertyFilterType,InsightModel,type SDK,Survey,- SurveyQuestionType,} from '~/types'import { captureBIWorksheetAction } from 'products/business_intelligence/frontend/biEditorAnalytics'import { getExperimentStatus } from 'products/experiments/frontend/experimentStatus'+import { getSurveyConfigurationProperties } from 'products/surveys/frontend/surveyUsage'import type { ExperimentMetricUnion } from '../../queries/schema/schema-general'import type { FunnelCorrelationResultsType, Realm, UserType } from '../../types'@@ -1581,9 +1580,6 @@ export interface eventUsageLogicActions {reportSurveyCycleDetected: (survey: NewSurvey | Survey) => {survey: NewSurvey | Survey}- reportSurveyEdited: (survey: Survey) => {- survey: Survey- }reportSurveyTemplateClicked: (template: SurveyTemplateType,source?: string@@ -1591,9 +1587,6 @@ export interface eventUsageLogicActions {source: string | undefinedtemplate: SurveyTemplateType}- reportSurveyViewed: (survey: Survey) => {- survey: Survey- }reportTaxonomicFilterCategorySelected: (groupType: TaxonomicFilterGroupType,eventName?: string@@ -2049,9 +2042,6 @@ export const eventUsageLogic = kea<eventUsageLogicType>([reportFlagsCodeExampleLanguage: (language: string) => ({language,}),- reportSurveyViewed: (survey: Survey) => ({- survey,- }),reportSurveyCreated: (survey: Survey,isDuplicate?: boolean,@@ -2062,7 +2052,6 @@ export const eventUsageLogic = kea<eventUsageLogicType>([source,meta,}),- reportSurveyEdited: (survey: Survey) => ({ survey }),reportSurveyTemplateClicked: (template: SurveyTemplateType, source?: string) => ({ template, source }),reportSurveyCycleDetected: (survey: Survey | NewSurvey) => ({ survey }),reportSurveyConsolidatedResultsQuery: (@@ -2801,10 +2790,6 @@ export const eventUsageLogic = kea<eventUsageLogicType>([})},reportSurveyCreated: ({ survey, isDuplicate, creationSource, createdFrom }) => {- const questionsWithShuffledOptions = survey.questions.filter((question) => {- return question.hasOwnProperty('shuffleOptions') && (question as MultipleSurveyQuestion).shuffleOptions- })-posthog.capture('survey created', {// The web app is the only place this event is emitted from — there is no backend// equivalent — so stamping the surface here is what puts surveys in a `source`@@ -2819,65 +2804,7 @@ export const eventUsageLogic = kea<eventUsageLogicType>([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,- recurring_survey_iteration_interval:- survey.iteration_frequency_days == undefined ? 0 : survey.iteration_frequency_days,- shuffle_questions_enabled: !!survey.appearance?.shuffleQuestions,- shuffle_question_options_enabled_count: questionsWithShuffledOptions.length,- has_branching_logic: survey.questions.some(- (question) => question.branching && Object.keys(question.branching).length > 0- ),- has_partial_responses: survey.enable_partial_responses,- skipping_submit_button: survey.questions.some((question) => {- if (- question.type === SurveyQuestionType.SingleChoice ||- question.type === SurveyQuestionType.MultipleChoice- ) {- return question.skipSubmitButton- }- return false- }),- })- },- reportSurveyViewed: ({ survey }) => {- posthog.capture('survey viewed', {- name: survey.name,- id: survey.id,- created_at: survey.created_at,- start_date: survey.start_date,- end_date: survey.end_date,- })- },- reportSurveyEdited: ({ survey }) => {- const questionsWithShuffledOptions = survey.questions.filter((question) => {- return question.hasOwnProperty('shuffleOptions') && (question as MultipleSurveyQuestion).shuffleOptions- })-- posthog.capture('survey edited', {- name: survey.name,- id: survey.id,- created_at: survey.created_at,- start_date: survey.start_date,- events_count: survey.conditions?.events?.values.length,- recurring_survey_iteration_count: survey.iteration_count == undefined ? 0 : survey.iteration_count,- recurring_survey_iteration_interval:- survey.iteration_frequency_days == undefined ? 0 : survey.iteration_frequency_days,- shuffle_questions_enabled: !!survey.appearance?.shuffleQuestions,- shuffle_question_options_enabled_count: questionsWithShuffledOptions.length,- has_branching_logic: survey.questions.some(- (question) => question.branching && Object.keys(question.branching).length > 0- ),- has_partial_responses: survey.enable_partial_responses,- skipping_submit_button: survey.questions.some((question) => {- if (- question.type === SurveyQuestionType.SingleChoice ||- question.type === SurveyQuestionType.MultipleChoice- ) {- return question.skipSubmitButton- }- return false- }),+ ...getSurveyConfigurationProperties(survey),})},reportSurveyTemplateClicked: ({ template, source }) => {diff --git a/frontend/src/scenes/surveys/surveyLogic.tsx b/frontend/src/scenes/surveys/surveyLogic.tsxindex c5809b2f83e4..cb49f88bebb1 100644--- a/frontend/src/scenes/surveys/surveyLogic.tsx+++ b/frontend/src/scenes/surveys/surveyLogic.tsx@@ -98,6 +98,7 @@ import {} from '~/types'import { surveysGenerateTranslationsCreate } from 'products/surveys/frontend/generated/api'+import { reportSurveyEdited } from 'products/surveys/frontend/surveyUsage'import type { ProductIntentProperties } from '../../lib/utils/product-intents'import type {@@ -843,12 +844,6 @@ export interface surveyLogicActions {reportSurveyCycleDetected: (survey: NewSurvey | Survey) => {survey: NewSurvey | Survey} // eventUsageLogic- reportSurveyEdited: (survey: Survey) => {- survey: Survey- } // eventUsageLogic- reportSurveyViewed: (survey: Survey) => {- survey: Survey- } // eventUsageLogicloadSurveys: () => any // surveysLogicaddProductIntent: (properties: ProductIntentProperties) => ProductIntentProperties // teamLogicaddResponseColumn: (column: SurveyResponseColumn) => {@@ -1545,13 +1540,7 @@ export const surveyLogic = kea<surveyLogicType>([surveysLogic,['loadSurveys'],eventUsageLogic,- [- 'reportSurveyCreated',- 'reportSurveyEdited',- 'reportSurveyViewed',- 'reportSurveyCycleDetected',- 'reportSurveyConsolidatedResultsQuery',- ],+ ['reportSurveyCreated', 'reportSurveyCycleDetected', 'reportSurveyConsolidatedResultsQuery'],teamLogic,['addProductIntent'],],@@ -1679,7 +1668,13 @@ export const surveyLogic = kea<surveyLogicType>([survey.appearance = defaultSurveyAppearance}const currentFilters = values.answerFilters- actions.reportSurveyViewed(survey)+ posthog.capture('survey viewed', {+ name: survey.name,+ id: survey.id,+ created_at: survey.created_at,+ start_date: survey.start_date,+ end_date: survey.end_date,+ })// Initialize answer filters for all questions - first for index-based, then for id-basedactions.setAnswerFilters(survey.questions.map((question) => {@@ -2070,7 +2065,7 @@ export const surveyLogic = kea<surveyLogicType>([updateSurveySuccess: ({ survey }) => {lemonToast.success(<>Survey {survey.name} updated</>)actions.editingSurvey(false)- actions.reportSurveyEdited(survey)+ reportSurveyEdited(survey)actions.loadSurveys()},launchSurveySuccess: ({ survey }) => {diff --git a/frontend/src/scenes/surveys/wizard/surveyWizardLogic.ts b/frontend/src/scenes/surveys/wizard/surveyWizardLogic.tsindex ea60f5989578..2a2b0de1e89c 100644--- a/frontend/src/scenes/surveys/wizard/surveyWizardLogic.ts+++ b/frontend/src/scenes/surveys/wizard/surveyWizardLogic.ts@@ -28,6 +28,8 @@ import { urls } from 'scenes/urls'import { ProductIntentContext, ProductKey } from '~/queries/schema/schema-general'import { Breadcrumb, LinkSurveyQuestion, Survey, SurveyQuestionType, SurveySchedule, SurveyType } from '~/types'+import { reportSurveyEdited } from 'products/surveys/frontend/surveyUsage'+import type { ProductIntentProperties } from '../../../lib/utils/product-intents'import type { TeamPublicType, TeamType } from '../../../types'import {@@ -126,9 +128,6 @@ export interface surveyWizardLogicActions {isDuplicate: boolean | undefinedsurvey: Survey} // eventUsageLogic- reportSurveyEdited: (survey: Survey) => {- survey: Survey- } // eventUsageLogicreportSurveyTemplateClicked: (template: SurveyTemplateType,source?: string | undefined@@ -238,7 +237,7 @@ export const surveyWizardLogic = kea<surveyWizardLogicType>([surveysLogic,['loadSurveys'],eventUsageLogic,- ['reportSurveyCreated', 'reportSurveyEdited', 'reportSurveyTemplateClicked'],+ ['reportSurveyCreated', 'reportSurveyTemplateClicked'],teamLogic,['addProductIntent'],],@@ -575,7 +574,7 @@ export const surveyWizardLogic = kea<surveyWizardLogicType>([updateSurveySuccess: ({ survey }) => {lemonToast.success(`Survey "${survey.name}" updated`)actions.loadSurveys()- actions.reportSurveyEdited(survey)+ reportSurveyEdited(survey)router.actions.push(urls.survey(survey.id))},})),diff --git a/pnpm-lock.yaml b/pnpm-lock.yamlindex 79acac4a51d0..06f7380e8fa7 100644--- a/pnpm-lock.yaml+++ b/pnpm-lock.yaml@@ -5077,6 +5077,9 @@ importers:kea-router:specifier: 'catalog:'version: 3.4.2([email protected](patch_hash=139b8d1f1304f9d9da452a9a1244c94ea679dbcb85687d8999563146879fb6f5)([email protected]))+ posthog-js:+ specifier: 'catalog:'+ version: 1.438.12(@types/[email protected])([email protected])react:specifier: 18.3.1version: 18.3.1diff --git a/products/surveys/frontend/surveyUsage.test.ts b/products/surveys/frontend/surveyUsage.test.tsnew file mode 100644index 000000000000..e4e2857e31ed--- /dev/null+++ b/products/surveys/frontend/surveyUsage.test.ts@@ -0,0 +1,41 @@+import posthog from 'posthog-js'++import { Survey, SurveyQuestionType } from '~/types'++import { reportSurveyEdited } from './surveyUsage'++describe('reportSurveyEdited', () => {+ it('reports survey configuration without question text or responses', () => {+ const capture = jest.spyOn(posthog, 'capture').mockImplementation()+ const survey = {+ id: 'survey-example',+ name: 'Example survey',+ created_at: '2026-01-01T00:00:00Z',+ start_date: null,+ questions: [{ type: SurveyQuestionType.Open, question: 'Private question' }],+ conditions: null,+ iteration_count: null,+ iteration_frequency_days: null,+ appearance: null,+ enable_partial_responses: false,+ } as Survey++ reportSurveyEdited(survey)++ expect(capture).toHaveBeenCalledWith('survey edited', {+ name: 'Example survey',+ id: 'survey-example',+ created_at: '2026-01-01T00:00:00Z',+ start_date: null,+ events_count: undefined,+ recurring_survey_iteration_count: 0,+ recurring_survey_iteration_interval: 0,+ shuffle_questions_enabled: false,+ shuffle_question_options_enabled_count: 0,+ has_branching_logic: false,+ has_partial_responses: false,+ skipping_submit_button: false,+ })+ capture.mockRestore()+ })+})diff --git a/products/surveys/frontend/surveyUsage.ts b/products/surveys/frontend/surveyUsage.tsnew file mode 100644index 000000000000..30dc6ff1b842--- /dev/null+++ b/products/surveys/frontend/surveyUsage.ts@@ -0,0 +1,52 @@+import posthog from 'posthog-js'++import { MultipleSurveyQuestion, Survey, SurveyQuestionType } from '~/types'++type SurveyConfigurationProperties = {+ events_count: number | undefined+ recurring_survey_iteration_count: number+ recurring_survey_iteration_interval: number+ shuffle_questions_enabled: boolean+ shuffle_question_options_enabled_count: number+ has_branching_logic: boolean+ has_partial_responses: Survey['enable_partial_responses']+ skipping_submit_button: boolean+}++export function getSurveyConfigurationProperties(survey: Survey): SurveyConfigurationProperties {+ const questionsWithShuffledOptions = survey.questions.filter((question) => {+ return question.hasOwnProperty('shuffleOptions') && (question as MultipleSurveyQuestion).shuffleOptions+ })++ return {+ events_count: survey.conditions?.events?.values.length,+ recurring_survey_iteration_count: survey.iteration_count == undefined ? 0 : survey.iteration_count,+ recurring_survey_iteration_interval:+ survey.iteration_frequency_days == undefined ? 0 : survey.iteration_frequency_days,+ shuffle_questions_enabled: !!survey.appearance?.shuffleQuestions,+ shuffle_question_options_enabled_count: questionsWithShuffledOptions.length,+ has_branching_logic: survey.questions.some(+ (question) => question.branching && Object.keys(question.branching).length > 0+ ),+ has_partial_responses: survey.enable_partial_responses,+ skipping_submit_button: survey.questions.some((question) => {+ if (+ question.type === SurveyQuestionType.SingleChoice ||+ question.type === SurveyQuestionType.MultipleChoice+ ) {+ return question.skipSubmitButton+ }+ return false+ }),+ }+}++export function reportSurveyEdited(survey: Survey): void {+ posthog.capture('survey edited', {+ name: survey.name,+ id: survey.id,+ created_at: survey.created_at,+ start_date: survey.start_date,+ ...getSurveyConfigurationProperties(survey),+ })+}diff --git a/products/surveys/package.json b/products/surveys/package.jsonindex cac595a96c04..d8a52ebeb611 100644--- a/products/surveys/package.json+++ b/products/surveys/package.json@@ -6,7 +6,8 @@"dependencies": {"kea": "catalog:","kea-loaders": "catalog:",- "kea-router": "catalog:"+ "kea-router": "catalog:",+ "posthog-js": "catalog:"},"devDependencies": {"@storybook/react": "catalog:",