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(subscriptions): open feedback survey on report downvote (#79117)

Vasco de Krijgerb6d7e4f3a984
diff --git a/frontend/jest.setup.ts b/frontend/jest.setup.ts
index 084c3e232dc7..1e3b26afc57d 100644
--- a/frontend/jest.setup.ts
+++ b/frontend/jest.setup.ts
@@ -178,6 +178,7 @@ jest.mock('posthog-js', () => {
isFeatureEnabled: jest.fn(),
getEarlyAccessFeatures: jest.fn(),
getSurveys: jest.fn(),
+ displaySurvey: jest.fn(),
onFeatureFlags: jest.fn(() => () => {}),
debug: jest.fn(),
get_session_id: jest.fn(),
diff --git a/products/subscriptions/frontend/scenes/subscriptionSceneLogic.test.ts b/products/subscriptions/frontend/scenes/subscriptionSceneLogic.test.ts
index fe01c32334dc..988e41db730b 100644
--- a/products/subscriptions/frontend/scenes/subscriptionSceneLogic.test.ts
+++ b/products/subscriptions/frontend/scenes/subscriptionSceneLogic.test.ts
@@ -15,7 +15,7 @@ import {
} from 'products/subscriptions/frontend/generated/api.schemas'
import type { SubscriptionApi } from 'products/subscriptions/frontend/generated/api.schemas'
-import { subscriptionSceneLogic } from './subscriptionSceneLogic'
+import { NEGATIVE_FEEDBACK_SURVEY_ID, subscriptionSceneLogic } from './subscriptionSceneLogic'
const MOCK_USER = {
id: 1,
@@ -203,6 +203,7 @@ describe('subscriptionSceneLogic', () => {
})
initKeaTests()
const captureSpy = jest.spyOn(posthog, 'capture')
+ const displaySurveySpy = jest.spyOn(posthog, 'displaySurvey')
const logic = subscriptionSceneLogic({ id: '2' })
logic.mount()
@@ -221,6 +222,10 @@ describe('subscriptionSceneLogic', () => {
source,
previous_feedback: null,
})
+ // The "what was wrong?" survey opens only on a downvote, and this Slack/email flow must
+ // show it before the redirect strips the feedback params.
+ const expectedSurveyCalls = feedback === 'negative' ? [[NEGATIVE_FEEDBACK_SURVEY_ID]] : []
+ expect(displaySurveySpy.mock.calls).toEqual(expectedSurveyCalls)
// A feedback landing is also a click-through on the delivered report.
expect(captureSpy).toHaveBeenCalledWith('ai_report_clicked', {
subscription_id: 2,
@@ -234,6 +239,7 @@ describe('subscriptionSceneLogic', () => {
logic.unmount()
captureSpy.mockRestore()
+ displaySurveySpy.mockRestore()
})
it('captures ai_report_clicked from the report CTA delivery param and strips it', async () => {
@@ -273,6 +279,7 @@ describe('subscriptionSceneLogic', () => {
})
initKeaTests()
const captureSpy = jest.spyOn(posthog, 'capture')
+ const displaySurveySpy = jest.spyOn(posthog, 'displaySurvey')
const logic = subscriptionSceneLogic({ id: '2' })
logic.mount()
@@ -290,12 +297,15 @@ describe('subscriptionSceneLogic', () => {
}).toFinishAllListeners()
expect(captureSpy.mock.calls.filter(([event]) => event === 'ai_report_feedback')).toHaveLength(0)
+ // The already-recorded delivery is skipped, so the survey isn't reshown on a re-click either.
+ expect(displaySurveySpy).not.toHaveBeenCalled()
// Params are still stripped, and the originally recorded feedback wins.
expect(router.values.searchParams).toEqual({})
expect(logic.values.deliveryFeedback).toEqual({ 'd-123': 'positive' })
logic.unmount()
captureSpy.mockRestore()
+ displaySurveySpy.mockRestore()
})
it('persists recorded feedback across remounts', async () => {
@@ -330,6 +340,7 @@ describe('subscriptionSceneLogic', () => {
})
initKeaTests()
const captureSpy = jest.spyOn(posthog, 'capture')
+ const displaySurveySpy = jest.spyOn(posthog, 'displaySurvey')
const logic = subscriptionSceneLogic({ id: '2' })
logic.mount()
@@ -344,6 +355,8 @@ describe('subscriptionSceneLogic', () => {
source: 'in_app',
previous_feedback: null,
})
+ // Downvoting from the in-app thumbs opens the follow-up survey too.
+ expect(displaySurveySpy).toHaveBeenCalledWith(NEGATIVE_FEEDBACK_SURVEY_ID)
expect(logic.values.deliveryFeedback).toEqual({ 'd-9': 'negative' })
// Thanks flashes first, then expiry settles the row into the recorded option.
expect(logic.values.recentlyThankedDeliveries).toEqual({ 'd-9': true })
@@ -365,8 +378,11 @@ describe('subscriptionSceneLogic', () => {
previous_feedback: 'negative',
})
expect(logic.values.deliveryFeedback).toEqual({ 'd-9': 'positive' })
+ // Switching to a positive vote must not reopen the survey.
+ expect(displaySurveySpy).toHaveBeenCalledTimes(1)
logic.unmount()
captureSpy.mockRestore()
+ displaySurveySpy.mockRestore()
})
})
diff --git a/products/subscriptions/frontend/scenes/subscriptionSceneLogic.tsx b/products/subscriptions/frontend/scenes/subscriptionSceneLogic.tsx
index 78b72258ced8..a36c46a9c05f 100644
--- a/products/subscriptions/frontend/scenes/subscriptionSceneLogic.tsx
+++ b/products/subscriptions/frontend/scenes/subscriptionSceneLogic.tsx
@@ -35,6 +35,9 @@ export type DeliveryFeedbackSource = 'email' | 'slack' | 'in_app'
export const FEEDBACK_THANKS_DISPLAY_MS = 1000
+// Shown as a popup when someone votes a report down, asking what was wrong with it.
+export const NEGATIVE_FEEDBACK_SURVEY_ID = '019fd71b-1df8-0000-6b5f-2c35bb4aacc2'
+
function parseCursorFromPaginationUrl(url: string | null | undefined): string | undefined {
if (!url) {
return undefined
@@ -288,6 +291,12 @@ export const subscriptionSceneLogic = kea<subscriptionSceneLogicType>([
// event per person + delivery, so a switched vote simply wins.
previous_feedback: selectors.deliveryFeedback(previousState)[deliveryId] ?? null,
})
+ if (feedback === 'negative') {
+ // Show the follow-up survey directly rather than via its event trigger. The Slack
+ // link's router redirect strips the feedback params before trigger conditions
+ // evaluate, so displaySurvey is the reliable path for that flow.
+ posthog.displaySurvey(NEGATIVE_FEEDBACK_SURVEY_ID)
+ }
// In-app thumbs show a per-row "Thanks" state instead of a toast.
if (source !== 'in_app') {
lemonToast.success('Thanks for your feedback')