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(surveys): start a follow-up workflow from a survey (#113008)

Daniel Marchuk8898090d6b53
diff --git a/frontend/src/scenes/surveys/SurveyViewRedesign/SurveyViewRedesign.tsx b/frontend/src/scenes/surveys/SurveyViewRedesign/SurveyViewRedesign.tsx
index a1d6f4a10101..145ae3129b0b 100644
--- a/frontend/src/scenes/surveys/SurveyViewRedesign/SurveyViewRedesign.tsx
+++ b/frontend/src/scenes/surveys/SurveyViewRedesign/SurveyViewRedesign.tsx
@@ -24,6 +24,7 @@ import { interProjectCopyLogic } from 'scenes/resource-transfer/interProjectCopy
import { LaunchSurveyButton } from 'scenes/surveys/components/LaunchSurveyButton'
import { SurveyQuestionVisualization } from 'scenes/surveys/components/question-visualizations/SurveyQuestionVisualization'
import { SurveyFeedbackButton } from 'scenes/surveys/components/SurveyFeedbackButton'
+import { SurveyFollowUpWorkflowButton } from 'scenes/surveys/components/SurveyFollowUpWorkflowButton'
import { SurveyNotifications } from 'scenes/surveys/components/SurveyNotifications'
import { DuplicateToProjectModal } from 'scenes/surveys/DuplicateToProjectModal'
import { useSurveyResponseColumns } from 'scenes/surveys/hooks/useSurveyResponseColumns'
@@ -345,6 +346,7 @@ export function SurveyViewRedesign(): JSX.Element {
Copy to another project
</ButtonPrimitive>
)}
+ {surveyIdForTransfer && <SurveyFollowUpWorkflowButton surveyId={surveyIdForTransfer} />}
{!isDraft && (
<ButtonPrimitive menuItem onClick={() => setSqlHelperOpen(true)}>
<IconCode />
diff --git a/frontend/src/scenes/surveys/components/SurveyFollowUpWorkflowButton.tsx b/frontend/src/scenes/surveys/components/SurveyFollowUpWorkflowButton.tsx
new file mode 100644
index 000000000000..2a47a2bee454
--- /dev/null
+++ b/frontend/src/scenes/surveys/components/SurveyFollowUpWorkflowButton.tsx
@@ -0,0 +1,45 @@
+import { router } from 'kea-router'
+
+import { IconSend } from '@posthog/icons'
+
+import { ButtonPrimitive } from 'lib/ui/Button/ButtonPrimitives'
+
+import { SurveyEventName } from '~/types'
+
+import { captureMessageAudienceClicked } from 'products/workflows/frontend/MessageAudience/messageAudience'
+import {
+ type WorkflowTriggerConfig,
+ urlForNewWorkflowWithTrigger,
+} from 'products/workflows/frontend/Workflows/workflowTriggerPrefill'
+
+// pinned: reported as the click event's source, so renaming it splits the entry point's history
+const SOURCE = 'survey'
+
+// Keep in sync with the survey trigger in the workflow editor, which only recognizes this exact shape.
+function surveyFollowUpTrigger(surveyId: string): WorkflowTriggerConfig {
+ return {
+ type: 'event',
+ filters: {
+ events: [{ id: SurveyEventName.SENT, type: 'events', name: 'Survey sent' }],
+ properties: [{ key: '$survey_id', value: surveyId, operator: 'exact', type: 'event' }],
+ filter_test_accounts: false,
+ },
+ }
+}
+
+export function SurveyFollowUpWorkflowButton({ surveyId }: { surveyId: string }): JSX.Element {
+ return (
+ <ButtonPrimitive
+ menuItem
+ tooltip="Open a new workflow that runs each time someone submits a response to this survey"
+ onClick={() => {
+ captureMessageAudienceClicked(SOURCE, 'workflow')
+ router.actions.push(urlForNewWorkflowWithTrigger(surveyFollowUpTrigger(surveyId)))
+ }}
+ data-attr="survey-start-follow-up-workflow"
+ >
+ <IconSend />
+ Start a follow-up workflow
+ </ButtonPrimitive>
+ )
+}