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(surveys): capture single-use survey events locally (#107844)

Paul D'Ambra97ccfa17723d
diff --git a/frontend/src/lib/utils/eventUsageLogic.ts b/frontend/src/lib/utils/eventUsageLogic.ts
index 867e63704033..2b8b92efadfd 100644
--- a/frontend/src/lib/utils/eventUsageLogic.ts
+++ b/frontend/src/lib/utils/eventUsageLogic.ts
@@ -11,7 +11,7 @@ import { objectClean } from 'lib/utils/objects'
import { BillingUsageInteractionProps } from 'scenes/billing/types'
import { SharedMetric } from 'scenes/experiments/SharedMetrics/sharedMetricLogic'
import { ProductTourEvent } from 'scenes/product-tours/constants'
-import { NewSurvey, SURVEY_CREATED_SOURCE, SurveyTemplateType } from 'scenes/surveys/constants'
+import { SURVEY_CREATED_SOURCE } from 'scenes/surveys/constants'
import { userLogic } from 'scenes/userLogic'
import {
@@ -68,7 +68,6 @@ import {
PropertyFilterType,
InsightModel,
type SDK,
- Survey,
} from '~/types'
import { captureBIWorksheetAction } from 'products/business_intelligence/frontend/biEditorAnalytics'
@@ -1540,34 +1539,6 @@ export interface eventUsageLogicActions {
reportSessionTableVersionUpdated: (version: string) => {
version: string
}
- reportSurveyAiPromptSubmitted: (source: string) => {
- source: string
- }
- reportSurveyConsolidatedResultsQuery: (
- survey: Survey,
- totalDurationMs: number,
- queryDurations: {
- aggregate: number
- openEnded: number
- }
- ) => {
- queryDurations: {
- aggregate: number
- openEnded: number
- }
- survey: Survey
- totalDurationMs: number
- }
- reportSurveyCycleDetected: (survey: NewSurvey | Survey) => {
- survey: NewSurvey | Survey
- }
- reportSurveyTemplateClicked: (
- template: SurveyTemplateType,
- source?: string
- ) => {
- source: string | undefined
- template: SurveyTemplateType
- }
reportTaxonomicFilterCategorySelected: (
groupType: TaxonomicFilterGroupType,
eventName?: string
@@ -2027,14 +1998,6 @@ export const eventUsageLogic = kea<eventUsageLogicType>([
source,
meta,
}),
- reportSurveyTemplateClicked: (template: SurveyTemplateType, source?: string) => ({ template, source }),
- reportSurveyCycleDetected: (survey: Survey | NewSurvey) => ({ survey }),
- reportSurveyConsolidatedResultsQuery: (
- survey: Survey,
- totalDurationMs: number,
- queryDurations: { aggregate: number; openEnded: number }
- ) => ({ survey, totalDurationMs, queryDurations }),
- reportSurveyAiPromptSubmitted: (source: string) => ({ source }),
reportProductTourViewed: (tour: ProductTour) => ({ tour }),
reportProductTourCreated: (tour: ProductTour, creationSource?: 'app' | 'toolbar') => ({
tour,
@@ -2764,34 +2727,6 @@ export const eventUsageLogic = kea<eventUsageLogicType>([
language,
})
},
- reportSurveyTemplateClicked: ({ template, source }) => {
- posthog.capture('survey template clicked', {
- template,
- source,
- })
- },
- reportSurveyAiPromptSubmitted: ({ source }) => {
- posthog.capture('survey AI prompt submitted', {
- source,
- })
- },
- reportSurveyCycleDetected: ({ survey }) => {
- posthog.capture('survey cycle detected', {
- name: survey.name,
- id: survey.id,
- start_date: survey.start_date,
- end_date: survey.end_date,
- })
- },
- reportSurveyConsolidatedResultsQuery: ({ survey, totalDurationMs, queryDurations }) => {
- posthog.capture('survey consolidated results query completed', {
- name: survey.name,
- id: survey.id,
- duration: totalDurationMs,
- aggregate_duration: queryDurations.aggregate,
- open_ended_duration: queryDurations.openEnded,
- })
- },
reportProductTourViewed: ({ tour }) => {
posthog.capture(ProductTourEvent.VIEWED, {
tour_id: tour.id,
diff --git a/frontend/src/scenes/surveys/surveyLogic.tsx b/frontend/src/scenes/surveys/surveyLogic.tsx
index d1be97f6a773..a530d4fc4c4d 100644
--- a/frontend/src/scenes/surveys/surveyLogic.tsx
+++ b/frontend/src/scenes/surveys/surveyLogic.tsx
@@ -27,7 +27,6 @@ import { FEATURE_FLAGS } from 'lib/constants'
import { dayjs } from 'lib/dayjs'
import { FeatureFlagsSet, featureFlagLogic as enabledFlagLogic } from 'lib/logic/featureFlagLogic'
import { deleteWithUndo } from 'lib/utils/deleteWithUndo'
-import { eventUsageLogic } from 'lib/utils/eventUsageLogic'
import { isObject } from 'lib/utils/guards'
import { hasFormErrors, objectClean } from 'lib/utils/objects'
import { allOperatorsMapping } from 'lib/utils/operators'
@@ -801,24 +800,6 @@ export interface surveyLogicValues {
// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
export interface surveyLogicActions {
- reportSurveyConsolidatedResultsQuery: (
- survey: Survey,
- totalDurationMs: number,
- queryDurations: {
- aggregate: number
- openEnded: number
- }
- ) => {
- queryDurations: {
- aggregate: number
- openEnded: number
- }
- survey: Survey
- totalDurationMs: number
- } // eventUsageLogic
- reportSurveyCycleDetected: (survey: NewSurvey | Survey) => {
- survey: NewSurvey | Survey
- } // eventUsageLogic
loadSurveys: () => any // surveysLogic
addProductIntent: (properties: ProductIntentProperties) => ProductIntentProperties // teamLogic
addResponseColumn: (column: SurveyResponseColumn) => {
@@ -1511,14 +1492,7 @@ export const surveyLogic = kea<surveyLogicType>([
key(({ id }) => id),
path((key) => ['scenes', 'surveys', 'surveyLogic', key]),
connect(() => ({
- actions: [
- surveysLogic,
- ['loadSurveys'],
- eventUsageLogic,
- ['reportSurveyCycleDetected', 'reportSurveyConsolidatedResultsQuery'],
- teamLogic,
- ['addProductIntent'],
- ],
+ actions: [surveysLogic, ['loadSurveys'], teamLogic, ['addProductIntent']],
values: [
enabledFlagLogic,
['featureFlags as enabledFlags'],
@@ -1897,9 +1871,12 @@ export const surveyLogic = kea<surveyLogicType>([
const endMs = performance.now()
- actions.reportSurveyConsolidatedResultsQuery(survey, endMs - startMs, {
- aggregate: aggregateDuration,
- openEnded: openEndedDuration,
+ posthog.capture('survey consolidated results query completed', {
+ name: survey.name,
+ id: survey.id,
+ duration: endMs - startMs,
+ aggregate_duration: aggregateDuration,
+ open_ended_duration: openEndedDuration,
})
const aggregate = processResultsForSurveyQuestions(survey.questions, aggregateResponse.results)
@@ -4041,7 +4018,12 @@ export const surveyLogic = kea<surveyLogicType>([
},
submit: (surveyPayload) => {
if (values.hasCycle) {
- actions.reportSurveyCycleDetected(values.survey)
+ posthog.capture('survey cycle detected', {
+ name: values.survey.name,
+ id: values.survey.id,
+ start_date: values.survey.start_date,
+ end_date: values.survey.end_date,
+ })
lemonToast.error('Your survey contains an endless cycle. Please revisit your branching rules.')
return
}
diff --git a/frontend/src/scenes/surveys/wizard/steps/TemplateStep.tsx b/frontend/src/scenes/surveys/wizard/steps/TemplateStep.tsx
index c2bbcf5fcc43..5d6b77f49e69 100644
--- a/frontend/src/scenes/surveys/wizard/steps/TemplateStep.tsx
+++ b/frontend/src/scenes/surveys/wizard/steps/TemplateStep.tsx
@@ -1,5 +1,6 @@
import clsx from 'clsx'
import { useActions, useValues } from 'kea'
+import posthog from 'posthog-js'
import { useRef, useState } from 'react'
import {
@@ -25,7 +26,6 @@ import { LemonButton, LemonSegmentedButton, LemonTag, LemonTextArea } from '@pos
import { FEATURE_FLAGS } from 'lib/constants'
import { featureFlagLogic } from 'lib/logic/featureFlagLogic'
-import { eventUsageLogic } from 'lib/utils/eventUsageLogic'
import { useMaxTool } from 'scenes/max/useMaxTool'
import { SURVEY_CREATED_SOURCE, SurveyTemplate, SurveyTemplateMode, SurveyTemplateType } from '../../constants'
@@ -96,7 +96,6 @@ function TemplateCard({ template, onClick, featured }: TemplateCardProps): JSX.E
export function TemplateStep({ handleCustomizeMore }: { handleCustomizeMore: () => void }): JSX.Element {
const { coreTemplates, otherTemplates, templateMode } = useValues(surveyWizardLogic)
const { selectTemplate, setTemplateMode } = useActions(surveyWizardLogic)
- const { reportSurveyAiPromptSubmitted } = useActions(eventUsageLogic)
const { handleMaxSurveyCreated } = useActions(surveysLogic)
const { featureFlags } = useValues(featureFlagLogic)
const hostedEditorEnabled = !!featureFlags[FEATURE_FLAGS.SURVEYS_HOSTED_EDITOR]
@@ -111,7 +110,7 @@ export function TemplateStep({ handleCustomizeMore }: { handleCustomizeMore: ()
const handleAiSubmit = (): void => {
if (prompt.trim()) {
- reportSurveyAiPromptSubmitted(SURVEY_CREATED_SOURCE.SURVEY_WIZARD)
+ posthog.capture('survey AI prompt submitted', { source: SURVEY_CREATED_SOURCE.SURVEY_WIZARD })
openMax?.()
setPrompt('')
}
diff --git a/frontend/src/scenes/surveys/wizard/surveyWizardLogic.test.ts b/frontend/src/scenes/surveys/wizard/surveyWizardLogic.test.ts
index 2f3190e63cd2..79656d827bc3 100644
--- a/frontend/src/scenes/surveys/wizard/surveyWizardLogic.test.ts
+++ b/frontend/src/scenes/surveys/wizard/surveyWizardLogic.test.ts
@@ -1,5 +1,6 @@
import { router } from 'kea-router'
import { expectLogic } from 'kea-test-utils'
+import posthog from 'posthog-js'
import { lemonToast } from '@posthog/lemon-ui'
@@ -242,6 +243,7 @@ describe('surveyWizardLogic', () => {
})
it('should move to questions step after selecting template', async () => {
+ const capture = jest.spyOn(posthog, 'capture').mockImplementation()
const logic = surveyWizardLogic({ id: 'new' })
logic.mount()
@@ -253,6 +255,11 @@ describe('surveyWizardLogic', () => {
templateType: 'Net promoter score (NPS)',
}),
})
+ expect(capture).toHaveBeenCalledWith('survey template clicked', {
+ template: SurveyTemplateType.NPS,
+ source: SURVEY_CREATED_SOURCE.SURVEY_WIZARD,
+ })
+ capture.mockRestore()
})
it('should track step progression through wizard', async () => {
diff --git a/frontend/src/scenes/surveys/wizard/surveyWizardLogic.ts b/frontend/src/scenes/surveys/wizard/surveyWizardLogic.ts
index a52b0b360d7d..dff1ce067437 100644
--- a/frontend/src/scenes/surveys/wizard/surveyWizardLogic.ts
+++ b/frontend/src/scenes/surveys/wizard/surveyWizardLogic.ts
@@ -14,13 +14,13 @@ import {
} from 'kea'
import type { FieldName } from 'kea-forms/lib/index'
import { router, urlToAction } from 'kea-router'
+import posthog from 'posthog-js'
import { lemonToast } from '@posthog/lemon-ui'
import api from 'lib/api'
import { ApiError } from 'lib/api-error'
import { dayjs } from 'lib/dayjs'
-import { eventUsageLogic } from 'lib/utils/eventUsageLogic'
import { Scene } from 'scenes/sceneTypes'
import { teamLogic } from 'scenes/teamLogic'
import { urls } from 'scenes/urls'
@@ -103,13 +103,6 @@ export interface surveyWizardLogicValues {
// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
export interface surveyWizardLogicActions {
- reportSurveyTemplateClicked: (
- template: SurveyTemplateType,
- source?: string | undefined
- ) => {
- source: string | undefined
- template: SurveyTemplateType
- } // eventUsageLogic
loadSurvey: () => any // surveyLogic
resetSurvey: (values?: NewSurvey | Survey | undefined) => {
values?: NewSurvey | Survey
@@ -211,8 +204,6 @@ export const surveyWizardLogic = kea<surveyWizardLogicType>([
['setSurveyValue', 'resetSurvey', 'loadSurvey'],
surveysLogic,
['loadSurveys'],
- eventUsageLogic,
- ['reportSurveyTemplateClicked'],
teamLogic,
['addProductIntent'],
],
@@ -465,7 +456,10 @@ export const surveyWizardLogic = kea<surveyWizardLogicType>([
actions.setSurveyValue('iteration_frequency_days', isOnce ? 0 : frequencyToDays[frequencyValue])
actions.setSurveyValue('conditions', template.conditions ?? null)
- actions.reportSurveyTemplateClicked(template.templateType, SURVEY_CREATED_SOURCE.SURVEY_WIZARD)
+ posthog.capture('survey template clicked', {
+ template: template.templateType,
+ source: SURVEY_CREATED_SOURCE.SURVEY_WIZARD,
+ })
// Hosted surveys don't have a guided wizard — route to the dedicated editor.
if (isHostedMode) {