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(workflows): ask for broadcasts preview feedback in the list (#105190)

Daniel Marchukfcd21bd144cd
diff --git a/products/workflows/frontend/Broadcasts/BroadcastsFeaturePreview.tsx b/products/workflows/frontend/Broadcasts/BroadcastsFeaturePreview.tsx
new file mode 100644
index 000000000000..9667f4d847b8
--- /dev/null
+++ b/products/workflows/frontend/Broadcasts/BroadcastsFeaturePreview.tsx
@@ -0,0 +1,21 @@
+import { FeaturePreviewFeedbackBanner } from '../FeaturePreviewFeedbackBanner'
+
+const SURVEY_ID = '01a0ce6c-f291-0000-092b-8677d994599c'
+const RATING_QUESTION_ID = 'a5e6e02a-174b-41a7-8da6-7fa1595ac763'
+const FEEDBACK_QUESTION_ID = '1e3e0368-135f-485c-bf46-ddaac558e879'
+
+export function BroadcastsFeaturePreview(): JSX.Element {
+ return (
+ <FeaturePreviewFeedbackBanner
+ surveyId={SURVEY_ID}
+ ratingQuestionId={RATING_QUESTION_ID}
+ feedbackQuestionId={FEEDBACK_QUESTION_ID}
+ surface="broadcasts"
+ dismissKey="broadcasts-feature-preview"
+ prompt="Broadcasts is new. Is it doing what you need?"
+ modalTitle="Help shape broadcasts"
+ feedbackPlaceholder="Tell us what works, what doesn’t, or what you’d change"
+ data-attr="broadcasts-feature-preview"
+ />
+ )
+}
diff --git a/products/workflows/frontend/FeaturePreviewFeedbackBanner.test.tsx b/products/workflows/frontend/FeaturePreviewFeedbackBanner.test.tsx
new file mode 100644
index 000000000000..0210a15c2ac3
--- /dev/null
+++ b/products/workflows/frontend/FeaturePreviewFeedbackBanner.test.tsx
@@ -0,0 +1,98 @@
+import '@testing-library/jest-dom'
+
+import { cleanup, fireEvent, render, screen } from '@testing-library/react'
+import posthog from 'posthog-js'
+
+import { lemonBannerLogic } from 'lib/lemon-ui/LemonBanner/lemonBannerLogic'
+
+import { initKeaTests } from '~/test/init'
+
+import { FeaturePreviewFeedbackBanner } from './FeaturePreviewFeedbackBanner'
+
+jest.mock('posthog-js')
+
+const SURVEY_ID = 'survey-1'
+const RATING_QUESTION_ID = 'rating-q'
+const FEEDBACK_QUESTION_ID = 'feedback-q'
+
+const renderBanner = (dismissKey = 'test-banner'): void => {
+ render(
+ <FeaturePreviewFeedbackBanner
+ surveyId={SURVEY_ID}
+ ratingQuestionId={RATING_QUESTION_ID}
+ feedbackQuestionId={FEEDBACK_QUESTION_ID}
+ surface="broadcasts"
+ dismissKey={dismissKey}
+ prompt="Is this doing what you need?"
+ modalTitle="Help shape it"
+ feedbackPlaceholder="What would you change?"
+ data-attr="test-banner"
+ />
+ )
+}
+
+const captures = (): [string, Record<string, any>][] => (posthog.capture as jest.Mock).mock.calls as any
+
+describe('FeaturePreviewFeedbackBanner', () => {
+ beforeEach(() => {
+ initKeaTests()
+ jest.clearAllMocks()
+ })
+
+ afterEach(() => {
+ cleanup()
+ })
+
+ it('records the rating against the survey as soon as a thumb is clicked', () => {
+ // Someone who rates and never opens the modal still has to count, so the rating cannot wait
+ // for the written feedback.
+ renderBanner()
+ fireEvent.click(screen.getByTestId('test-banner-thumbs-up'))
+
+ const sent = captures().find(([name]) => name === 'survey sent')
+ expect(sent).not.toBeUndefined()
+ const props = sent![1]
+ expect(props.$survey_id).toBe(SURVEY_ID)
+ expect(props[`$survey_response_${RATING_QUESTION_ID}`]).toBe('Useful')
+ expect(props.$survey_completed).toBe(false)
+ expect(props.feedback_surface).toBe('broadcasts')
+ })
+
+ it('sends the written feedback on the same submission as the rating', () => {
+ // A second submission id would split one person's rating and note into two responses.
+ renderBanner()
+ fireEvent.click(screen.getByTestId('test-banner-thumbs-up'))
+ const ratingProps = captures().find(([name]) => name === 'survey sent')![1]
+
+ fireEvent.change(screen.getByPlaceholderText('What would you change?'), {
+ target: { value: 'The recipient list matters most' },
+ })
+ fireEvent.click(screen.getByText('Send feedback'))
+
+ const completed = captures().filter(([name]) => name === 'survey sent')[1][1]
+ expect(completed.$survey_submission_id).toBe(ratingProps.$survey_submission_id)
+ expect(completed[`$survey_response_${FEEDBACK_QUESTION_ID}`]).toBe('The recipient list matters most')
+ expect(completed.$survey_completed).toBe(true)
+ })
+
+ it('does not record an impression for a banner the person already dismissed', () => {
+ // LemonBanner renders nothing once dismissed, so capturing on mount would count an
+ // impression nobody saw and make the response rate read far lower than it is.
+ const logic = lemonBannerLogic({ dismissKey: 'test-banner-dismissed' })
+ logic.mount()
+ logic.actions.dismiss()
+
+ renderBanner('test-banner-dismissed')
+
+ expect(captures().filter(([name]) => name === 'survey shown')).toHaveLength(0)
+ })
+
+ it('ignores a second rating', () => {
+ // The buttons disable after the first click; without that a double click would file two responses.
+ renderBanner()
+ fireEvent.click(screen.getByTestId('test-banner-thumbs-up'))
+ fireEvent.click(screen.getByTestId('test-banner-thumbs-down'))
+
+ expect(captures().filter(([name]) => name === 'survey sent')).toHaveLength(1)
+ })
+})
diff --git a/products/workflows/frontend/FeaturePreviewFeedbackBanner.tsx b/products/workflows/frontend/FeaturePreviewFeedbackBanner.tsx
new file mode 100644
index 000000000000..1f262e839a74
--- /dev/null
+++ b/products/workflows/frontend/FeaturePreviewFeedbackBanner.tsx
@@ -0,0 +1,165 @@
+import { useValues } from 'kea'
+import posthog from 'posthog-js'
+import { useEffect, useState } from 'react'
+
+import { IconThumbsDown, IconThumbsDownFilled, IconThumbsUp, IconThumbsUpFilled } from '@posthog/icons'
+import { LemonBanner, LemonButton, LemonModal, LemonTextArea } from '@posthog/lemon-ui'
+
+import { lemonBannerLogic } from 'lib/lemon-ui/LemonBanner/lemonBannerLogic'
+import { uuid } from 'lib/utils/dom'
+import { getSurveyIdBasedResponseKey, getSurveyResponseKey } from 'scenes/surveys/utils'
+
+import { SurveyEventName, SurveyEventProperties } from '~/types'
+
+type Rating = 'useful' | 'needs improvement'
+
+/** The choice labels the survey's first question stores, so a response is readable in the results. */
+const SURVEY_RESPONSES: Record<Rating, string> = {
+ useful: 'Useful',
+ 'needs improvement': 'Needs improvement',
+}
+
+export interface FeaturePreviewFeedbackBannerProps {
+ /** An `api`-type survey with a single-choice question then an open one. */
+ surveyId: string
+ ratingQuestionId: string
+ feedbackQuestionId: string
+ /** Distinguishes responses when several surfaces report to one survey. */
+ surface: string
+ /** Remembers a dismissal per person, so the banner does not come back on every visit. */
+ dismissKey: string
+ prompt: string
+ modalTitle: string
+ feedbackPlaceholder: string
+ 'data-attr'?: string
+}
+
+/**
+ * The thumbs-up/thumbs-down strip a feature preview carries while we are still deciding whether to
+ * keep it. The rating is recorded on click, so a rating survives someone who never opens the modal,
+ * and the written note lands on the same submission id rather than a second response.
+ */
+export function FeaturePreviewFeedbackBanner({
+ surveyId,
+ ratingQuestionId,
+ feedbackQuestionId,
+ surface,
+ dismissKey,
+ prompt,
+ modalTitle,
+ feedbackPlaceholder,
+ 'data-attr': dataAttr,
+}: FeaturePreviewFeedbackBannerProps): JSX.Element {
+ const [rating, setRating] = useState<Rating | null>(null)
+ const [submissionId, setSubmissionId] = useState<string | null>(null)
+ const [feedbackText, setFeedbackText] = useState('')
+ const [feedbackOpen, setFeedbackOpen] = useState(false)
+ // LemonBanner renders nothing once the dismissal is persisted, so without this the impression
+ // is recorded on every visit for a banner nobody sees, and the response rate reads far too low.
+ const { isDismissed } = useValues(lemonBannerLogic({ dismissKey }))
+
+ useEffect(() => {
+ if (isDismissed) {
+ return
+ }
+ posthog.capture(SurveyEventName.SHOWN, {
+ [SurveyEventProperties.SURVEY_ID]: surveyId,
+ feedback_surface: surface,
+ })
+ }, [surveyId, surface, isDismissed])
+
+ const ratePreview = (nextRating: Rating): void => {
+ if (rating) {
+ return
+ }
+
+ const nextSubmissionId = uuid()
+ const response = SURVEY_RESPONSES[nextRating]
+
+ setRating(nextRating)
+ setSubmissionId(nextSubmissionId)
+ setFeedbackOpen(true)
+ posthog.capture(SurveyEventName.SENT, {
+ [SurveyEventProperties.SURVEY_ID]: surveyId,
+ [SurveyEventProperties.SURVEY_SUBMISSION_ID]: nextSubmissionId,
+ [SurveyEventProperties.SURVEY_COMPLETED]: false,
+ [getSurveyResponseKey(0)]: response,
+ [getSurveyIdBasedResponseKey(ratingQuestionId)]: response,
+ feedback_surface: surface,
+ })
+ }
+
+ const submitFeedback = (): void => {
+ const feedback = feedbackText.trim()
+ if (!feedback || !submissionId) {
+ return
+ }
+
+ posthog.capture(SurveyEventName.SENT, {
+ [SurveyEventProperties.SURVEY_ID]: surveyId,
+ [SurveyEventProperties.SURVEY_SUBMISSION_ID]: submissionId,
+ [SurveyEventProperties.SURVEY_COMPLETED]: true,
+ [getSurveyResponseKey(1)]: feedback,
+ [getSurveyIdBasedResponseKey(feedbackQuestionId)]: feedback,
+ feedback_surface: surface,
+ })
+ setFeedbackOpen(false)
+ setFeedbackText('')
+ }
+
+ return (
+ <>
+ <LemonBanner type="info" dismissKey={dismissKey} className="m-2">
+ <div className="flex flex-wrap items-center justify-between gap-2">
+ <div className="text-secondary">{rating ? 'Thanks, your rating is saved.' : prompt}</div>
+ <div className="flex items-center gap-1">
+ <LemonButton
+ type={rating === 'useful' ? 'primary' : 'secondary'}
+ size="xsmall"
+ icon={rating === 'useful' ? <IconThumbsUpFilled /> : <IconThumbsUp />}
+ tooltip="This is useful"
+ disabled={!!rating}
+ onClick={() => ratePreview('useful')}
+ data-attr={dataAttr ? `${dataAttr}-thumbs-up` : undefined}
+ />
+ <LemonButton
+ type={rating === 'needs improvement' ? 'primary' : 'secondary'}
+ size="xsmall"
+ icon={rating === 'needs improvement' ? <IconThumbsDownFilled /> : <IconThumbsDown />}
+ tooltip="Needs improvement"
+ disabled={!!rating}
+ onClick={() => ratePreview('needs improvement')}
+ data-attr={dataAttr ? `${dataAttr}-thumbs-down` : undefined}
+ />
+ </div>
+ </div>
+ </LemonBanner>
+ <LemonModal
+ title={modalTitle}
+ description="Thanks, your rating is saved. What would make this better?"
+ isOpen={feedbackOpen}
+ onClose={() => setFeedbackOpen(false)}
+ data-attr={dataAttr ? `${dataAttr}-feedback` : undefined}
+ footer={
+ <div className="flex justify-end gap-2">
+ <LemonButton type="secondary" onClick={() => setFeedbackOpen(false)}>
+ Not now
+ </LemonButton>
+ <LemonButton type="primary" disabled={!feedbackText.trim()} onClick={submitFeedback}>
+ Send feedback
+ </LemonButton>
+ </div>
+ }
+ >
+ <LemonTextArea
+ value={feedbackText}
+ onChange={setFeedbackText}
+ placeholder={feedbackPlaceholder}
+ minRows={4}
+ autoFocus
+ data-attr={dataAttr ? `${dataAttr}-feedback-text` : undefined}
+ />
+ </LemonModal>
+ </>
+ )
+}
diff --git a/products/workflows/frontend/Workflows/hogflows/tree/HogFlowTreeFeaturePreview.tsx b/products/workflows/frontend/Workflows/hogflows/tree/HogFlowTreeFeaturePreview.tsx
index 3085956f0273..d57c2659d950 100644
--- a/products/workflows/frontend/Workflows/hogflows/tree/HogFlowTreeFeaturePreview.tsx
+++ b/products/workflows/frontend/Workflows/hogflows/tree/HogFlowTreeFeaturePreview.tsx
@@ -1,134 +1,21 @@
-import posthog from 'posthog-js'
-import { useEffect, useState } from 'react'
-
-import { IconThumbsDown, IconThumbsDownFilled, IconThumbsUp, IconThumbsUpFilled } from '@posthog/icons'
-import { LemonBanner, LemonButton, LemonModal, LemonTextArea } from '@posthog/lemon-ui'
-
-import { uuid } from 'lib/utils/dom'
-import { getSurveyIdBasedResponseKey, getSurveyResponseKey } from 'scenes/surveys/utils'
-
-import { SurveyEventName, SurveyEventProperties } from '~/types'
+import { FeaturePreviewFeedbackBanner } from '../../../FeaturePreviewFeedbackBanner'
const SURVEY_ID = '01a0856f-7ae3-0000-eef6-fec0a2e1b78f'
const RATING_QUESTION_ID = 'a899da8d-092a-41ce-ab9b-8e18b2c7cfd8'
const FEEDBACK_QUESTION_ID = 'acbad4b5-52c2-4a56-a280-5d2ddd064612'
-type WorkflowTreeFeedbackRating = 'useful' | 'needs improvement'
-
-const surveyResponses: Record<WorkflowTreeFeedbackRating, string> = {
- useful: 'Useful',
- 'needs improvement': 'Needs improvement',
-}
-
export function HogFlowTreeFeaturePreview(): JSX.Element {
- const [rating, setRating] = useState<WorkflowTreeFeedbackRating | null>(null)
- const [submissionId, setSubmissionId] = useState<string | null>(null)
- const [feedbackText, setFeedbackText] = useState('')
- const [feedbackOpen, setFeedbackOpen] = useState(false)
-
- useEffect(() => {
- posthog.capture(SurveyEventName.SHOWN, {
- [SurveyEventProperties.SURVEY_ID]: SURVEY_ID,
- feedback_surface: 'workflow_tree_editor',
- })
- }, [])
-
- const ratePreview = (nextRating: WorkflowTreeFeedbackRating): void => {
- if (rating) {
- return
- }
-
- const nextSubmissionId = uuid()
- const response = surveyResponses[nextRating]
-
- setRating(nextRating)
- setSubmissionId(nextSubmissionId)
- setFeedbackOpen(true)
- posthog.capture(SurveyEventName.SENT, {
- [SurveyEventProperties.SURVEY_ID]: SURVEY_ID,
- [SurveyEventProperties.SURVEY_SUBMISSION_ID]: nextSubmissionId,
- [SurveyEventProperties.SURVEY_COMPLETED]: false,
- [getSurveyResponseKey(0)]: response,
- [getSurveyIdBasedResponseKey(RATING_QUESTION_ID)]: response,
- feedback_surface: 'workflow_tree_editor',
- })
- }
-
- const submitFeedback = (): void => {
- const feedback = feedbackText.trim()
- if (!feedback || !submissionId) {
- return
- }
-
- posthog.capture(SurveyEventName.SENT, {
- [SurveyEventProperties.SURVEY_ID]: SURVEY_ID,
- [SurveyEventProperties.SURVEY_SUBMISSION_ID]: submissionId,
- [SurveyEventProperties.SURVEY_COMPLETED]: true,
- [getSurveyResponseKey(1)]: feedback,
- [getSurveyIdBasedResponseKey(FEEDBACK_QUESTION_ID)]: feedback,
- feedback_surface: 'workflow_tree_editor',
- })
- setFeedbackOpen(false)
- setFeedbackText('')
- }
-
return (
- <>
- <LemonBanner type="info" dismissKey="workflow-tree-feature-preview" className="m-2">
- <div className="flex flex-wrap items-center justify-between gap-2">
- <div className="text-secondary">
- {rating
- ? 'Thanks, your rating is saved.'
- : 'We’re trialling a new list based workflow view. What do you think?'}
- </div>
- <div className="flex items-center gap-1">
- <LemonButton
- type={rating === 'useful' ? 'primary' : 'secondary'}
- size="xsmall"
- icon={rating === 'useful' ? <IconThumbsUpFilled /> : <IconThumbsUp />}
- tooltip="This is useful"
- disabled={!!rating}
- onClick={() => ratePreview('useful')}
- data-attr="workflow-tree-feature-preview-thumbs-up"
- />
- <LemonButton
- type={rating === 'needs improvement' ? 'primary' : 'secondary'}
- size="xsmall"
- icon={rating === 'needs improvement' ? <IconThumbsDownFilled /> : <IconThumbsDown />}
- tooltip="Needs improvement"
- disabled={!!rating}
- onClick={() => ratePreview('needs improvement')}
- data-attr="workflow-tree-feature-preview-thumbs-down"
- />
- </div>
- </div>
- </LemonBanner>
- <LemonModal
- title="Help shape the new workflow view"
- description="Thanks, your rating is saved. What would make this better?"
- isOpen={feedbackOpen}
- onClose={() => setFeedbackOpen(false)}
- data-attr="workflow-tree-feature-preview-feedback"
- footer={
- <div className="flex justify-end gap-2">
- <LemonButton type="secondary" onClick={() => setFeedbackOpen(false)}>
- Not now
- </LemonButton>
- <LemonButton type="primary" disabled={!feedbackText.trim()} onClick={submitFeedback}>
- Send feedback
- </LemonButton>
- </div>
- }
- >
- <LemonTextArea
- value={feedbackText}
- onChange={setFeedbackText}
- placeholder="Tell us what works, what doesn’t, or what you’d change"
- minRows={4}
- autoFocus
- data-attr="workflow-tree-feature-preview-feedback-text"
- />
- </LemonModal>
- </>
+ <FeaturePreviewFeedbackBanner
+ surveyId={SURVEY_ID}
+ ratingQuestionId={RATING_QUESTION_ID}
+ feedbackQuestionId={FEEDBACK_QUESTION_ID}
+ surface="workflow_tree_editor"
+ dismissKey="workflow-tree-feature-preview"
+ prompt="We’re trialling a new list based workflow view. What do you think?"
+ modalTitle="Help shape the new workflow view"
+ feedbackPlaceholder="Tell us what works, what doesn’t, or what you’d change"
+ data-attr="workflow-tree-feature-preview"
+ />
)
}
diff --git a/products/workflows/frontend/WorkflowsScene.tsx b/products/workflows/frontend/WorkflowsScene.tsx
index 5da96a4f481a..c24457502de9 100644
--- a/products/workflows/frontend/WorkflowsScene.tsx
+++ b/products/workflows/frontend/WorkflowsScene.tsx
@@ -24,6 +24,7 @@ import { SceneTitleSection } from '~/layout/scenes/components/SceneTitleSection'
import { ProductIntentContext, ProductKey } from '~/queries/schema/schema-general'
import { AccessControlLevel, AccessControlResourceType, Breadcrumb } from '~/types'
+import { BroadcastsFeaturePreview } from './Broadcasts/BroadcastsFeaturePreview'
import { BroadcastsTable } from './Broadcasts/BroadcastsTable'
import { MessageChannels } from './Channels/MessageChannels'
import { workflowsEmptyState } from './emptyState/workflowsEmptyState'
@@ -216,7 +217,12 @@ export function WorkflowsScene(props: WorkflowsSceneProps = {}): JSX.Element {
{
label: 'Broadcasts',
key: 'broadcasts',
- content: <BroadcastsTable />,
+ content: (
+ <>
+ <BroadcastsFeaturePreview />
+ <BroadcastsTable />
+ </>
+ ),
link: urls.workflows('broadcasts'),
},
{