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(mcp-analytics): ask for feedback after dashboard exploration (#103155)

Lucas Faria52c1d1b1007a
diff --git a/docs/internal/mcp-analytics-feedback.md b/docs/internal/mcp-analytics-feedback.md
index 59bba28a5c52..3bd929cbc29f 100644
--- a/docs/internal/mcp-analytics-feedback.md
+++ b/docs/internal/mcp-analytics-feedback.md
@@ -1,11 +1,17 @@
-# MCP analytics session feedback
+# MCP analytics contextual feedback
The session detail panel shows a thumbs question after 30 seconds with loaded tool calls.
+The dashboard also offers feedback after a user changes its date, property, or test-account filters and all refreshed queries finish successfully with tool-call data.
+Opening a dashboard link, including a filtered link, does not count as an interaction.
+The dashboard uses the same 30-second reading delay, thumbs question, and optional text, with dashboard-specific copy.
+Filter changes restart a pending delay, but an opened prompt and unfinished text stay available through refreshes.
Refreshing feature flags keeps an already-pending delay when the same survey remains eligible.
Leaving the panel or hiding the tab cancels the delay; returning starts a fresh delay.
The SDK must return an active matching survey, and capture must be enabled for a signed-in, non-impersonated user.
-Showing the prompt starts a 30-day cooldown shared across sequential placements for that user in this browser.
-Mount only one placement at a time; simultaneous placements do not synchronize their in-memory cooldowns.
+An impression requires at least half the prompt to enter the viewport while the browser tab is visible.
+Recording that impression starts a 30-day cooldown shared across placements for that user in this browser.
+Mounted placements share one cooldown per user and recheck it when their delay ends, so only one placement can record an impression; the others hide once it does.
+The cooldown remains browser-local; it does not synchronize across devices.
Feedback is requested in context; the page header has no general Feedback button.
## Configuration and rollout
@@ -14,7 +20,7 @@ Feedback is requested in context; the page header has no general Feedback button
Recurring survey iterations are not supported.
The survey belongs to the project configured for PostHog’s own analytics SDK, not the customer project being viewed.
Its questions must be a two-point emoji rating followed by optional open text, both with stable IDs.
-`MCP_ANALYTICS_SESSION_FEEDBACK_PROMPT` supplies the displayed copy and placement metadata.
+`MCP_ANALYTICS_SESSION_FEEDBACK_PROMPT` and `MCP_ANALYTICS_DASHBOARD_FEEDBACK_PROMPT` supply the displayed copy and placement metadata.
Incompatible, draft, stopped, or nonmatching surveys do not start a prompt.
The API survey can launch before deployment because it does not display itself.
@@ -24,7 +30,7 @@ This change needs no update to the existing header survey configuration.
## Events and reporting
-- `survey shown` records the impression and starts the cooldown.
+- `survey shown` records the first viewport impression and starts the cooldown; rendering offscreen does neither.
- `survey sent` records the first answer immediately with `$survey_completed: false`.
- Done or Send feedback sends the same answer and optional text with `$survey_completed: true` and the same submission ID.
- Navigating away does not emit a dismissal or abandonment event; any partial response already captured remains.
diff --git a/frontend/snapshots.yml b/frontend/snapshots.yml
index c296a33cb49d..18804f12384e 100644
--- a/frontend/snapshots.yml
+++ b/frontend/snapshots.yml
@@ -6048,6 +6048,10 @@ snapshots:
hash: v1.k794b7964.b9a43443a726379620a7b8fcb5a97d6f42eb092717a96a050c1d60e4850d7f29.pqYVY5w4VqCVPWENMeYL5kO5uRWJ3YGEAh2gPbkpg_U
products-mcp-analytics-feedback-prompt--contextual-copy--light:
hash: v1.k794b7964.d065e4cb7ecb9502ba7374baaf23d2c0cc4f0885abfcb2e807b6b814e5fdd3d0.tqChEQrfpmRX7tuHb1yU-8v1NiwD-WMDKzBHOirvgEQ
+ products-mcp-analytics-feedback-prompt--dashboard--dark:
+ hash: v1.k794b7964.abf05309b6d53f8ed5bd4e95f172d010aa16182aa688e2a7af19f0a90e333b90.4ej0K229S4L1BIvzue7WJmsGoHdwKJnaVjBNBXxGmU8
+ products-mcp-analytics-feedback-prompt--dashboard--light:
+ hash: v1.k794b7964.ab004091751bca87390230b89d22d97e155e9a88e638e29c5ded1c28fbd13137.a81ftUX03UAAVNhH0EZJG8UrSCuk9pNWO8JIv8hF1HI
products-mcp-analytics-feedback-prompt--default--dark:
hash: v1.k794b7964.7c336ecc0b0049054b4a219dea0d12091417decdbf348f9000428570bcca6167.UalRR5QQm9N4vreFdBsJT71WOiU2wexgEXUFTh332Sc
products-mcp-analytics-feedback-prompt--default--light:
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index e9b59a9ae68b..563a72c6c8db 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -3983,6 +3983,9 @@ importers:
react:
specifier: 18.3.1
version: 18.3.1
+ react-intersection-observer:
+ specifier: 9.5.3
+ version: 9.5.3([email protected])
devDependencies:
kea-test-utils:
specifier: 'catalog:'
diff --git a/products/mcp_analytics/frontend/MCPAnalyticsDashboardOverview.tsx b/products/mcp_analytics/frontend/MCPAnalyticsDashboardOverview.tsx
index 6dcfe581d06f..d7ee6e8b9321 100644
--- a/products/mcp_analytics/frontend/MCPAnalyticsDashboardOverview.tsx
+++ b/products/mcp_analytics/frontend/MCPAnalyticsDashboardOverview.tsx
@@ -18,6 +18,8 @@ import { ModelBarChart } from './dashboard/ModelBarChart'
import { NotableSessionsTable } from './dashboard/NotableSessionsTable'
import { ToolErrorRateChart } from './dashboard/ToolErrorRateChart'
import { ToolUsageChart } from './dashboard/ToolUsageChart'
+import { MCP_ANALYTICS_DASHBOARD_FEEDBACK_PROMPT } from './feedback/constants'
+import { MCPAnalyticsFeedbackPrompt } from './feedback/MCPAnalyticsFeedbackPrompt'
import { MCPAnalyticsFirstLook } from './firstLook/MCPAnalyticsFirstLook'
import { mcpAnalyticsFiltersLogic } from './mcpAnalyticsFiltersLogic'
import { mcpDashboardOverviewLogic } from './mcpDashboardOverviewLogic'
@@ -46,8 +48,10 @@ export function MCPAnalyticsDashboardOverview(): JSX.Element {
dateFilter,
interval,
queryFilters,
+ canShowFeedback,
+ feedbackContextKey,
} = useValues(mcpDashboardOverviewLogic)
- const { setDateFilter } = useActions(mcpDashboardOverviewLogic)
+ const { setDateFilter, markFilterInteraction } = useActions(mcpDashboardOverviewLogic)
const { filterTestAccounts, propertyFilters } = useValues(mcpAnalyticsFiltersLogic)
const { setFilterTestAccounts, setPropertyFilters } = useActions(mcpAnalyticsFiltersLogic)
const { timezone } = useValues(teamLogic)
@@ -63,14 +67,20 @@ export function MCPAnalyticsDashboardOverview(): JSX.Element {
<McpDateFilter
dateFrom={dateFilter.dateFrom}
dateTo={dateFilter.dateTo}
- onChange={(dateFrom, dateTo) => setDateFilter(dateFrom, dateTo)}
+ onChange={(dateFrom, dateTo) => {
+ setDateFilter(dateFrom, dateTo)
+ markFilterInteraction()
+ }}
dataAttr="mcp-dashboard-date-filter"
/>
<div data-attr="mcp-dashboard-property-filter">
<PropertyFilters
pageKey="mcp-dashboard-overview"
propertyFilters={propertyFilters}
- onChange={setPropertyFilters}
+ onChange={(filters) => {
+ setPropertyFilters(filters)
+ markFilterInteraction()
+ }}
taxonomicGroupTypes={[
TaxonomicFilterGroupType.MCPProperties,
TaxonomicFilterGroupType.EventProperties,
@@ -85,11 +95,19 @@ export function MCPAnalyticsDashboardOverview(): JSX.Element {
right={
<TestAccountFilterSwitch
checked={filterTestAccounts}
- onChange={setFilterTestAccounts}
+ onChange={(enabled) => {
+ setFilterTestAccounts(enabled)
+ markFilterInteraction()
+ }}
data-attr="mcp-dashboard-test-account-filter"
/>
}
/>
+ <MCPAnalyticsFeedbackPrompt
+ contextKey={feedbackContextKey}
+ eligible={canShowFeedback}
+ prompt={MCP_ANALYTICS_DASHBOARD_FEEDBACK_PROMPT}
+ />
<MCPAnalyticsFirstLook />
<section className="flex min-w-0 flex-col gap-4" data-quill>
<h2 className="mb-4 text-xl font-semibold text-primary">Key metrics</h2>
diff --git a/products/mcp_analytics/frontend/feedback/MCPAnalyticsFeedbackPrompt.stories.tsx b/products/mcp_analytics/frontend/feedback/MCPAnalyticsFeedbackPrompt.stories.tsx
index e94e8d7df6ea..e84a8a8eba2a 100644
--- a/products/mcp_analytics/frontend/feedback/MCPAnalyticsFeedbackPrompt.stories.tsx
+++ b/products/mcp_analytics/frontend/feedback/MCPAnalyticsFeedbackPrompt.stories.tsx
@@ -8,7 +8,11 @@ import { userLogic } from 'scenes/userLogic'
import { mswDecorator } from '~/mocks/browser'
import { MCPSessionDetail } from '../sessions/MCPSessionDetail'
-import { MCP_ANALYTICS_USEFULNESS_SURVEY_ID, MCP_ANALYTICS_SESSION_FEEDBACK_PROMPT } from './constants'
+import {
+ MCP_ANALYTICS_USEFULNESS_SURVEY_ID,
+ MCP_ANALYTICS_SESSION_FEEDBACK_PROMPT,
+ MCP_ANALYTICS_DASHBOARD_FEEDBACK_PROMPT,
+} from './constants'
import { mcpAnalyticsFeedbackLogic } from './mcpAnalyticsFeedbackLogic'
import { MCPAnalyticsFeedbackPrompt } from './MCPAnalyticsFeedbackPrompt'
@@ -162,3 +166,8 @@ export const ContextualCopy: Story = {
},
},
}
+
+export const Dashboard: Story = {
+ ...Narrow,
+ args: { prompt: MCP_ANALYTICS_DASHBOARD_FEEDBACK_PROMPT },
+}
diff --git a/products/mcp_analytics/frontend/feedback/MCPAnalyticsFeedbackPrompt.tsx b/products/mcp_analytics/frontend/feedback/MCPAnalyticsFeedbackPrompt.tsx
index 9f49e2d4b3c6..4480f7e6185e 100644
--- a/products/mcp_analytics/frontend/feedback/MCPAnalyticsFeedbackPrompt.tsx
+++ b/products/mcp_analytics/frontend/feedback/MCPAnalyticsFeedbackPrompt.tsx
@@ -1,9 +1,11 @@
import { useActions, useValues } from 'kea'
-import { useId } from 'react'
+import { useEffect, useId } from 'react'
+import { useInView } from 'react-intersection-observer'
import { IconThumbsDown, IconThumbsUp } from '@posthog/icons'
import { LemonBanner, LemonButton, LemonLabel, LemonTextArea } from '@posthog/lemon-ui'
+import { usePageVisibility } from 'lib/hooks/usePageVisibility'
import { userLogic } from 'scenes/userLogic'
import { MCPAnalyticsFeedbackPromptConfig, MCP_ANALYTICS_FEEDBACK_RATINGS } from './constants'
@@ -17,9 +19,11 @@ const thumbRatings = [
export function MCPAnalyticsFeedbackPrompt({
contextKey,
prompt: promptConfig,
+ eligible = true,
}: {
contextKey: string
prompt: MCPAnalyticsFeedbackPromptConfig
+ eligible?: boolean
}): JSX.Element | null {
const questionId = useId()
const detailId = useId()
@@ -27,18 +31,27 @@ export function MCPAnalyticsFeedbackPrompt({
const logic = mcpAnalyticsFeedbackLogic({
userId: user?.uuid ?? '',
contextKey,
+ eligible,
prompt: promptConfig,
isImpersonated: user?.is_impersonated ?? false,
})
const { visible, survey, prompt, answer, detail, completed, submitting, error } = useValues(logic)
- const { dismissPrompt, setDetail, submitResponse } = useActions(logic)
+ const { dismissPrompt, recordImpression, setDetail, submitResponse } = useActions(logic)
+ const { ref, inView } = useInView({ threshold: 0.5, skip: !visible })
+ const { isVisible: pageVisible } = usePageVisibility()
+
+ useEffect(() => {
+ if (visible && inView && pageVisible) {
+ recordImpression()
+ }
+ }, [visible, inView, pageVisible, recordImpression])
if (!visible || !survey) {
return null
}
return (
- <div className="shrink-0 p-2" data-attr="mcp-analytics-feedback-prompt">
+ <div ref={ref} className="shrink-0 p-2" data-attr="mcp-analytics-feedback-prompt">
<LemonBanner type="info" hideIcon onClose={dismissPrompt}>
{completed ? (
<div role="status">Thanks for your feedback.</div>
diff --git a/products/mcp_analytics/frontend/feedback/constants.ts b/products/mcp_analytics/frontend/feedback/constants.ts
index b68c0fc6a41d..be4719cd030f 100644
--- a/products/mcp_analytics/frontend/feedback/constants.ts
+++ b/products/mcp_analytics/frontend/feedback/constants.ts
@@ -17,3 +17,11 @@ export const MCP_ANALYTICS_SESSION_FEEDBACK_PROMPT: MCPAnalyticsFeedbackPromptCo
question: 'Did this session help you find what you needed?',
followUpQuestion: 'What did you learn, or what was missing?',
}
+
+export const MCP_ANALYTICS_DASHBOARD_FEEDBACK_PROMPT: MCPAnalyticsFeedbackPromptConfig = {
+ entryPoint: 'dashboard_review_prompt',
+ tab: 'dashboard',
+ version: 1,
+ question: 'Did this dashboard help you understand how your MCP server is being used?',
+ followUpQuestion: 'What did you learn, or what was missing?',
+}
diff --git a/products/mcp_analytics/frontend/feedback/mcpAnalyticsFeedbackCooldownLogic.ts b/products/mcp_analytics/frontend/feedback/mcpAnalyticsFeedbackCooldownLogic.ts
new file mode 100644
index 000000000000..4096a5018623
--- /dev/null
+++ b/products/mcp_analytics/frontend/feedback/mcpAnalyticsFeedbackCooldownLogic.ts
@@ -0,0 +1,44 @@
+import { LogicWrapper, MakeLogicType, actions, kea, key, path, props, reducers } from 'kea'
+
+interface FeedbackCooldownProps {
+ userId: string
+}
+
+// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
+export interface mcpAnalyticsFeedbackCooldownLogicValues {
+ lastPromptAt: number
+}
+
+// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
+export interface mcpAnalyticsFeedbackCooldownLogicActions {
+ recordPrompt: (timestamp: number) => {
+ timestamp: number
+ }
+}
+
+// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
+export interface mcpAnalyticsFeedbackCooldownLogicMeta {
+ key: string
+}
+
+export type mcpAnalyticsFeedbackCooldownLogicType = MakeLogicType<
+ mcpAnalyticsFeedbackCooldownLogicValues,
+ mcpAnalyticsFeedbackCooldownLogicActions,
+ FeedbackCooldownProps,
+ mcpAnalyticsFeedbackCooldownLogicMeta
+>
+
+export const mcpAnalyticsFeedbackCooldownLogic: LogicWrapper<mcpAnalyticsFeedbackCooldownLogicType> =
+ kea<mcpAnalyticsFeedbackCooldownLogicType>([
+ props({} as FeedbackCooldownProps),
+ key(({ userId }: FeedbackCooldownProps): string => userId),
+ path((key) => ['products', 'mcp_analytics', 'frontend', 'feedback', 'mcpAnalyticsFeedbackCooldownLogic', key]),
+ actions({ recordPrompt: (timestamp: number) => ({ timestamp }) }),
+ reducers(({ props }) => ({
+ lastPromptAt: [
+ 0,
+ { persist: true, storageKey: `mcp-analytics-feedback-last-prompt:${props.userId}` },
+ { recordPrompt: (_, { timestamp }) => timestamp },
+ ],
+ })),
+ ])
diff --git a/products/mcp_analytics/frontend/feedback/mcpAnalyticsFeedbackLogic.test.ts b/products/mcp_analytics/frontend/feedback/mcpAnalyticsFeedbackLogic.test.ts
index 7646b852dedc..6f21b159d8eb 100644
--- a/products/mcp_analytics/frontend/feedback/mcpAnalyticsFeedbackLogic.test.ts
+++ b/products/mcp_analytics/frontend/feedback/mcpAnalyticsFeedbackLogic.test.ts
@@ -109,6 +109,7 @@ describe('mcpAnalyticsFeedbackLogic', () => {
expect(logic.values.visible).toBe(false)
jest.advanceTimersByTime(1)
expect(logic.values.visible).toBe(true)
+ logic.actions.recordImpression()
expect(posthog.capture).toHaveBeenCalledWith(
'survey shown',
expect.objectContaining({
@@ -125,6 +126,22 @@ describe('mcpAnalyticsFeedbackLogic', () => {
}
)
+ it('does not count an offscreen prompt or consume its cooldown', () => {
+ loadSurvey()
+ jest.advanceTimersByTime(FEEDBACK_PROMPT_DELAY_MS)
+ expect(logic.values.visible).toBe(true)
+ expect(logic.values.lastPromptAt).toBe(0)
+ expect(posthog.capture).not.toHaveBeenCalled()
+ const hidden = jest.spyOn(document, 'hidden', 'get').mockReturnValue(true)
+ logic.actions.recordImpression()
+ expect(logic.values.lastPromptAt).toBe(0)
+ hidden.mockReturnValue(false)
+ logic.actions.recordImpression()
+ logic.actions.recordImpression()
+ expect(logic.values.lastPromptAt).toBe(Date.now())
+ expect(jest.mocked(posthog.capture).mock.calls.filter(([event]) => event === 'survey shown')).toHaveLength(1)
+ })
+
it('keeps the reading delay across flag reloads and uses the latest survey metadata', () => {
loadSurvey()
jest.advanceTimersByTime(FEEDBACK_PROMPT_DELAY_MS / 2)
@@ -136,6 +153,7 @@ describe('mcpAnalyticsFeedbackLogic', () => {
flagsLoaded([], {})
jest.advanceTimersByTime(1)
expect(logic.values.visible).toBe(true)
+ logic.actions.recordImpression()
expect(posthog.capture).toHaveBeenCalledWith(
'survey shown',
expect.objectContaining({ $survey_name: refreshedSurvey.name })
@@ -212,6 +230,7 @@ describe('mcpAnalyticsFeedbackLogic', () => {
it('keeps the cooldown across placements after dismissal', () => {
loadSurvey()
jest.advanceTimersByTime(FEEDBACK_PROMPT_DELAY_MS)
+ logic.actions.recordImpression()
logic.actions.dismissPrompt()
expect(logic.values.visible).toBe(false)
unmount()
@@ -239,6 +258,51 @@ describe('mcpAnalyticsFeedbackLogic', () => {
expect(logic.values.visible).toBe(true)
})
+ it('shows only one prompt when dashboard and session placements are pending together', () => {
+ loadSurvey()
+ const dashboard = mcpAnalyticsFeedbackLogic({
+ userId: 'example-user',
+ contextKey: 'example-dashboard',
+ isImpersonated: false,
+ prompt: {
+ ...MCP_ANALYTICS_SESSION_FEEDBACK_PROMPT,
+ entryPoint: 'dashboard_review_prompt',
+ tab: 'dashboard',
+ },
+ })
+ const unmountDashboard = dashboard.mount()
+ loadSurvey()
+ jest.advanceTimersByTime(FEEDBACK_PROMPT_DELAY_MS)
+ logic.actions.recordImpression()
+ dashboard.actions.recordImpression()
+ expect([logic.values.visible, dashboard.values.visible].filter(Boolean)).toHaveLength(1)
+ expect(jest.mocked(posthog.capture).mock.calls.filter(([name]) => name === 'survey shown')).toHaveLength(1)
+ unmountDashboard()
+ })
+
+ it('restarts the delay after refreshes and preserves an opened response', () => {
+ loadSurvey()
+ jest.advanceTimersByTime(FEEDBACK_PROMPT_DELAY_MS / 2)
+ mcpAnalyticsFeedbackLogic({ ...logic.props, eligible: false })
+ jest.advanceTimersByTime(FEEDBACK_PROMPT_DELAY_MS)
+ expect(logic.values.visible).toBe(false)
+ mcpAnalyticsFeedbackLogic({ ...logic.props, eligible: true })
+ jest.advanceTimersByTime(FEEDBACK_PROMPT_DELAY_MS - 1)
+ expect(logic.values.visible).toBe(false)
+ jest.advanceTimersByTime(1)
+ logic.actions.submitResponse('1', false)
+ logic.actions.setDetail('Found an unexpected usage pattern.')
+ const submissionId = logic.values.submissionId
+ mcpAnalyticsFeedbackLogic({ ...logic.props, eligible: false })
+ mcpAnalyticsFeedbackLogic({ ...logic.props, eligible: true })
+ expect(logic.values).toMatchObject({
+ visible: true,
+ answer: '1',
+ detail: 'Found an unexpected usage pattern.',
+ submissionId,
+ })
+ })
+
it('cancels a pending invitation when leaving the session detail', () => {
loadSurvey()
unmount()
diff --git a/products/mcp_analytics/frontend/feedback/mcpAnalyticsFeedbackLogic.ts b/products/mcp_analytics/frontend/feedback/mcpAnalyticsFeedbackLogic.ts
index a3ca17ac46b3..6307714197e4 100644
--- a/products/mcp_analytics/frontend/feedback/mcpAnalyticsFeedbackLogic.ts
+++ b/products/mcp_analytics/frontend/feedback/mcpAnalyticsFeedbackLogic.ts
@@ -3,12 +3,14 @@ import {
MakeLogicType,
actions,
afterMount,
+ connect,
getContext,
kea,
key,
listeners,
path,
props,
+ propsChanged,
reducers,
selectors,
} from 'kea'
@@ -23,6 +25,7 @@ import {
MCP_ANALYTICS_FEEDBACK_RATINGS,
MCP_ANALYTICS_USEFULNESS_SURVEY_ID,
} from './constants'
+import { mcpAnalyticsFeedbackCooldownLogic } from './mcpAnalyticsFeedbackCooldownLogic'
export const FEEDBACK_PROMPT_DELAY_MS = 30_000
export const FEEDBACK_PROMPT_COOLDOWN_MS = 30 * 24 * 60 * 60 * 1000
@@ -32,15 +35,17 @@ export interface MCPAnalyticsFeedbackLogicProps {
contextKey: string
prompt: MCPAnalyticsFeedbackPromptConfig
isImpersonated: boolean
+ eligible?: boolean
}
// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
export interface mcpAnalyticsFeedbackLogicValues {
+ lastPromptAt: number // mcpAnalyticsFeedbackCooldownLogic
answer: string
completed: boolean
detail: string
error: boolean
- lastPromptAt: number
+ impressionRecorded: boolean
prompt: MCPAnalyticsFeedbackPromptConfig
submissionId: string
submitting: boolean
@@ -51,12 +56,24 @@ export interface mcpAnalyticsFeedbackLogicValues {
// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
export interface mcpAnalyticsFeedbackLogicActions {
+ recordPrompt: (timestamp: number) => {
+ timestamp: number
+ } // mcpAnalyticsFeedbackCooldownLogic
captureStarted: () => {
value: true
}
dismissPrompt: () => {
value: true
}
+ hidePrompt: () => {
+ value: true
+ }
+ impressionRecorded: () => {
+ value: true
+ }
+ recordImpression: () => {
+ value: true
+ }
responseFailed: () => {
value: true
}
@@ -126,9 +143,13 @@ function hasFeedbackQuestions(survey: Survey): boolean {
export const mcpAnalyticsFeedbackLogic: LogicWrapper<mcpAnalyticsFeedbackLogicType> =
kea<mcpAnalyticsFeedbackLogicType>([
- props({} as MCPAnalyticsFeedbackLogicProps),
+ props({ eligible: true } as MCPAnalyticsFeedbackLogicProps),
key(({ userId, contextKey, prompt }) => JSON.stringify([userId, prompt.entryPoint, contextKey])),
path((key) => ['products', 'mcp_analytics', 'frontend', 'feedback', 'mcpAnalyticsFeedbackLogic', key]),
+ connect(({ userId }: MCPAnalyticsFeedbackLogicProps) => ({
+ values: [mcpAnalyticsFeedbackCooldownLogic({ userId }), ['lastPromptAt']],
+ actions: [mcpAnalyticsFeedbackCooldownLogic({ userId }), ['recordPrompt']],
+ })),
actions({
schedulePrompt: (survey: Survey | null) => ({ survey }),
showPrompt: (survey: Survey, timestamp: number, submissionId: string) => ({
@@ -136,7 +157,10 @@ export const mcpAnalyticsFeedbackLogic: LogicWrapper<mcpAnalyticsFeedbackLogicTy
timestamp,
submissionId,
}),
+ recordImpression: true,
+ impressionRecorded: true,
dismissPrompt: true,
+ hidePrompt: true,
setDetail: (detail: string) => ({ detail }),
submitResponse: (answer: string, completed: boolean) => ({ answer, completed }),
responseQueued: (answer: string, completed: boolean) => ({ answer, completed }),
@@ -145,7 +169,8 @@ export const mcpAnalyticsFeedbackLogic: LogicWrapper<mcpAnalyticsFeedbackLogicTy
}),
reducers(({ props }) => ({
prompt: [props.prompt, { showPrompt: () => ({ ...props.prompt }) }],
- visible: [false, { showPrompt: () => true, dismissPrompt: () => false }],
+ visible: [false, { showPrompt: () => true, hidePrompt: () => false }],
+ impressionRecorded: [false, { impressionRecorded: () => true }],
survey: [null as Survey | null, { showPrompt: (_, { survey }) => survey }],
submissionId: ['', { showPrompt: (_, { submissionId }) => submissionId }],
answer: ['', { responseQueued: (_, { answer }) => answer }],
@@ -156,11 +181,6 @@ export const mcpAnalyticsFeedbackLogic: LogicWrapper<mcpAnalyticsFeedbackLogicTy
{ captureStarted: () => true, responseQueued: () => false, responseFailed: () => false },
],
error: [false, { captureStarted: () => false, responseFailed: () => true }],
- lastPromptAt: [
- 0,
- { persist: true, storageKey: `mcp-analytics-feedback-last-prompt:${props.userId}` },
- { showPrompt: (_, { timestamp }) => timestamp },
- ],
})),
selectors({
surveyEventProperties: [
@@ -188,7 +208,9 @@ export const mcpAnalyticsFeedbackLogic: LogicWrapper<mcpAnalyticsFeedbackLogicTy
}),
listeners(({ actions, values, props, cache }) => ({
schedulePrompt: ({ survey }) => {
+ cache.matchingSurvey = survey
if (
+ props.eligible === false ||
!props.userId ||
props.isImpersonated ||
values.visible ||
@@ -217,7 +239,11 @@ export const mcpAnalyticsFeedbackLogic: LogicWrapper<mcpAnalyticsFeedbackLogicTy
return
}
const surveyToShow: Survey | null = cache.pendingSurvey
- if (surveyToShow && posthog.is_capturing()) {
+ if (
+ surveyToShow &&
+ posthog.is_capturing() &&
+ Date.now() - values.lastPromptAt >= FEEDBACK_PROMPT_COOLDOWN_MS
+ ) {
actions.showPrompt(surveyToShow, Date.now(), crypto.randomUUID())
}
cache.pendingSurvey = null
@@ -226,16 +252,36 @@ export const mcpAnalyticsFeedbackLogic: LogicWrapper<mcpAnalyticsFeedbackLogicTy
return () => window.clearTimeout(timer)
}, 'prompt-delay')
},
- showPrompt: () => {
+ recordImpression: () => {
+ if (!values.visible || values.impressionRecorded || document.hidden || !posthog.is_capturing()) {
+ return
+ }
+ if (Date.now() - values.lastPromptAt < FEEDBACK_PROMPT_COOLDOWN_MS) {
+ actions.hidePrompt()
+ return
+ }
+ actions.impressionRecorded()
+ actions.recordPrompt(Date.now())
posthog.capture(SurveyEventName.SHOWN, values.surveyEventProperties)
},
+ recordPrompt: () => {
+ if (!values.impressionRecorded) {
+ actions.hidePrompt()
+ cache.disposables.dispose('prompt-delay')
+ }
+ },
dismissPrompt: () => {
- if (values.survey && !values.completed) {
+ if (!values.visible) {
+ return
+ }
+ actions.recordImpression()
+ if (values.impressionRecorded && values.survey && !values.completed) {
posthog.capture(SurveyEventName.DISMISSED, {
...values.surveyEventProperties,
[SurveyEventProperties.SURVEY_PARTIALLY_COMPLETED]: !!values.answer,
})
}
+ actions.hidePrompt()
},
submitResponse: ({ answer, completed }) => {
const { survey } = values
@@ -253,6 +299,10 @@ export const mcpAnalyticsFeedbackLogic: LogicWrapper<mcpAnalyticsFeedbackLogicTy
) {
return
}
+ actions.recordImpression()
+ if (!values.impressionRecorded) {
+ return
+ }
actions.captureStarted()
try {
const queued = posthog.capture(SurveyEventName.SENT, {
@@ -276,6 +326,14 @@ export const mcpAnalyticsFeedbackLogic: LogicWrapper<mcpAnalyticsFeedbackLogicTy
}
},
})),
+ propsChanged(({ actions, props, cache, values }, previousProps) => {
+ if (props.eligible !== previousProps.eligible) {
+ if (props.eligible === false && !values.impressionRecorded) {
+ actions.hidePrompt()
+ }
+ actions.schedulePrompt(cache.matchingSurvey ?? null)
+ }
+ }),
afterMount(({ actions, cache }) => {
const context = getContext()
cache.disposables.add(() =>
diff --git a/products/mcp_analytics/frontend/mcpDashboardOverviewLogic.test.ts b/products/mcp_analytics/frontend/mcpDashboardOverviewLogic.test.ts
index d38a520785ba..97afc9a3c678 100644
--- a/products/mcp_analytics/frontend/mcpDashboardOverviewLogic.test.ts
+++ b/products/mcp_analytics/frontend/mcpDashboardOverviewLogic.test.ts
@@ -598,5 +598,57 @@ describe('mcpDashboardOverviewLogic', () => {
reloads.every((call) => JSON.stringify(filtersOf(call).properties) === JSON.stringify([filter]))
).toBe(true)
})
+
+ it.each(['date', 'property', 'test accounts'])(
+ 'offers feedback after a %s interaction and a successful nonempty refresh',
+ async (filter) => {
+ const populatedResponse = async (
+ node: Parameters<typeof api.query>[0]
+ ): Promise<{ results: (string | number)[][] }> => ({
+ results:
+ 'query' in node && typeof node.query === 'string' && node.query.includes('AS bucket')
+ ? [[dayjs().format('YYYY-MM-DD'), 2, 10, 0, 100]]
+ : [],
+ })
+ mockApi.query.mockImplementation(populatedResponse)
+ router.actions.push(urls.mcpAnalyticsDashboard(), { date_from: '-14d' })
+ const logic = mcpDashboardOverviewLogic()
+ logic.mount()
+ await expectLogic(logic).toFinishAllListeners()
+ expect(logic.values.kpis.toolCalls.value).toBe(10)
+ expect(logic.values.canShowFeedback).toBe(false)
+
+ if (filter === 'date') {
+ logic.actions.setDateFilter('-30d', null)
+ } else if (filter === 'property') {
+ logic.actions.setPropertyFilters([EVENT_FILTER])
+ } else {
+ logic.actions.setFilterTestAccounts(true)
+ }
+ logic.actions.markFilterInteraction()
+ expect(logic.values.canShowFeedback).toBe(false)
+ await expectLogic(logic).toFinishAllListeners()
+ expect(logic.values.canShowFeedback).toBe(true)
+ const previousContext = logic.values.feedbackContextKey
+
+ mockApi.query.mockImplementation(async (node) => {
+ if (node.kind === 'MCPHarnessBreakdownQuery') {
+ throw new Error('Example query failure')
+ }
+ return populatedResponse(node)
+ })
+ await expectLogic(logic, () => logic.actions.setDateFilter('-7d', null)).toFinishAllListeners()
+ expect(logic.values.feedbackContextKey).toBe(previousContext)
+ expect(logic.values.canShowFeedback).toBe(false)
+
+ mockApi.query.mockResolvedValue({ results: [] })
+ await expectLogic(logic, () => logic.actions.reloadAll()).toFinishAllListeners()
+ expect(logic.values.canShowFeedback).toBe(false)
+
+ mockApi.query.mockImplementation(populatedResponse)
+ await expectLogic(logic, () => logic.actions.reloadAll()).toFinishAllListeners()
+ expect(logic.values.canShowFeedback).toBe(true)
+ }
+ )
})
})
diff --git a/products/mcp_analytics/frontend/mcpDashboardOverviewLogic.ts b/products/mcp_analytics/frontend/mcpDashboardOverviewLogic.ts
index df9fe56d6d4a..836742bf2a39 100644
--- a/products/mcp_analytics/frontend/mcpDashboardOverviewLogic.ts
+++ b/products/mcp_analytics/frontend/mcpDashboardOverviewLogic.ts
@@ -379,15 +379,21 @@ export interface mcpDashboardOverviewLogicValues {
clusters: readonly MCPIntentClusterApi[] // mcpClusteringLogic
hasSnapshot: boolean // mcpClusteringLogic
totalClusterCount: number // mcpClusteringLogic
+ currentTeamId: number | null // teamLogic
timezone: string // teamLogic
activityIncompleteTail: boolean
activityRows: ActivityRow[]
activityRowsLoading: boolean
bucketKeys: string[]
+ canShowFeedback: boolean
dailyActivity: DailyActivity
+ dashboardLoading: boolean
dateFilter: DateFilter
+ feedbackContextKey: string
+ feedbackLoadFailed: boolean
harnessRows: HarnessRow[]
harnessRowsLoading: boolean
+ hasFilterInteraction: boolean
hasModelData: boolean
intentClusterCount: KPIMetric
interval: IntervalType
@@ -584,6 +590,9 @@ export interface mcpDashboardOverviewLogicActions {
users: KPIMetric
payload?: void
}
+ markFilterInteraction: () => {
+ value: true
+ }
reloadAll: () => {
value: true
}
@@ -599,6 +608,23 @@ export interface mcpDashboardOverviewLogicActions {
// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
export interface mcpDashboardOverviewLogicMeta {
__keaTypeGenInternalSelectorTypes: {
+ dashboardLoading: (
+ kpisLoading: boolean,
+ usersLoading: boolean,
+ toolRowsLoading: boolean,
+ sessionRowsLoading: boolean,
+ harnessRowsLoading: boolean,
+ modelRowsLoading: boolean,
+ activityRowsLoading: boolean,
+ toolDailyRowsLoading: boolean
+ ) => boolean
+ canShowFeedback: (
+ hasFilterInteraction: boolean,
+ dashboardLoading: boolean,
+ feedbackLoadFailed: boolean,
+ kpis: KPIData
+ ) => boolean
+ feedbackContextKey: (currentTeamId: number | null) => string
queryFilters: (
dateFilter: DateFilter,
sharedQueryFilters: Required<Pick<HogQLFilters, 'filterTestAccounts' | 'properties'>>
@@ -629,7 +655,7 @@ export const mcpDashboardOverviewLogic = kea<mcpDashboardOverviewLogicType>([
mcpClusteringLogic,
['clusters', 'hasSnapshot', 'totalClusterCount'],
teamLogic,
- ['timezone'],
+ ['timezone', 'currentTeamId'],
mcpAnalyticsFiltersLogic,
['queryFilters as sharedQueryFilters'],
],
@@ -638,8 +664,24 @@ export const mcpDashboardOverviewLogic = kea<mcpDashboardOverviewLogicType>([
actions({
setDateFilter: (dateFrom: string | null, dateTo: string | null) => ({ dateFrom, dateTo }),
reloadAll: true,
+ markFilterInteraction: true,
}),
reducers({
+ hasFilterInteraction: [false, { markFilterInteraction: () => true }],
+ feedbackLoadFailed: [
+ false,
+ {
+ reloadAll: () => false,
+ loadKPIsFailure: () => true,
+ loadUsersFailure: () => true,
+ loadToolRowsFailure: () => true,
+ loadSessionRowsFailure: () => true,
+ loadHarnessRowsFailure: () => true,
+ loadModelRowsFailure: () => true,
+ loadActivityRowsFailure: () => true,
+ loadToolDailyRowsFailure: () => true,
+ },
+ ],
dateFilter: [
DEFAULT_DATE_FILTER,
{
@@ -836,6 +878,25 @@ export const mcpDashboardOverviewLogic = kea<mcpDashboardOverviewLogicType>([
],
})),
selectors({
+ dashboardLoading: [
+ (s) => [
+ s.kpisLoading,
+ s.usersLoading,
+ s.toolRowsLoading,
+ s.sessionRowsLoading,
+ s.harnessRowsLoading,
+ s.modelRowsLoading,
+ s.activityRowsLoading,
+ s.toolDailyRowsLoading,
+ ],
+ (...loading: boolean[]): boolean => loading.some(Boolean),
+ ],
+ canShowFeedback: [
+ (s) => [s.hasFilterInteraction, s.dashboardLoading, s.feedbackLoadFailed, s.kpis],
+ (interacted: boolean, loading: boolean, failed: boolean, kpis: KPIData): boolean =>
+ interacted && !loading && !failed && kpis.toolCalls.value > 0,
+ ],
+ feedbackContextKey: [(s) => [s.currentTeamId], (teamId: number | null): string => String(teamId ?? undefined)],
queryFilters: [
(s) => [s.dateFilter, s.sharedQueryFilters],
(dateFilter: DateFilter, sharedQueryFilters: MCPSharedQueryFilters): HogQLFilters => ({
diff --git a/products/mcp_analytics/package.json b/products/mcp_analytics/package.json
index 1120cdf66c11..4b671d0da6a4 100644
--- a/products/mcp_analytics/package.json
+++ b/products/mcp_analytics/package.json
@@ -11,7 +11,8 @@
"kea": "catalog:",
"kea-loaders": "catalog:",
"kea-router": "catalog:",
- "posthog-js": "catalog:"
+ "posthog-js": "catalog:",
+ "react-intersection-observer": "9.5.3"
},
"devDependencies": {
"kea-test-utils": "catalog:"