: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.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
chore(posthog-ai): remove the web analytics nudge (#115958)
Shy Alter734ac76bd56a
diff --git a/frontend/src/lib/constants.tsx b/frontend/src/lib/constants.tsxindex 072243e970d0..5d03fdf5f41d 100644--- a/frontend/src/lib/constants.tsx+++ b/frontend/src/lib/constants.tsx@@ -437,7 +437,6 @@ export const FEATURE_FLAGS = {MAX_BILLING_CONTEXT: 'max-billing-context', // owner: @pawel-cebula #team-billingMAX_DEEP_RESEARCH: 'max-deep-research', // owner: @kappa90 #team-posthog-aiMAX_HANDS_FREE: 'max-hands-free', // owner: #team-posthog-ai- MAX_WEB_ANALYTICS_NUDGE: 'posthog-ai-web-analytics-nudge', // owner: @jordanm-posthog #team-web-analyticsMCP_ANALYTICS_INTENT_ROUTING: 'mcp-analytics-intent-routing', // owner: #project-mcp-analyticsMCP_ANALYTICS_LEADERBOARD_HOME: 'mcp-analytics-leaderboard-home', // owner: #team-mcp-analytics, trial of the public leaderboard layout on the MCP analytics home tabMCP_GATEWAY: 'mcp-gateway', // owner: #team-context-mcp — gates the MCP gateway UI AND backend enforcement of built-in agent MCP access (delegated-only installs + restricted sandbox token scope); roll out by organizationdiff --git a/frontend/src/scenes/max/Thread.tsx b/frontend/src/scenes/max/Thread.tsxindex 8a7529f690cf..e6924c02ee09 100644--- a/frontend/src/scenes/max/Thread.tsx+++ b/frontend/src/scenes/max/Thread.tsx@@ -91,7 +91,6 @@ import { ReplayVisionScanWidget } from 'products/replay_vision/frontend/posthogAimport { LangGraphActivity, ShimmeringContent } from './components/Activity'import { FeedbackDisplay } from './components/FeedbackDisplay'-import { MaxWebAnalyticsNudge } from './components/MaxWebAnalyticsNudge'import { ContextSummary } from './Context'import { DangerousOperationApprovalCard } from './DangerousOperationApprovalCard'import { FeedbackPrompt } from './FeedbackPrompt'@@ -832,13 +831,6 @@ const Message = React.memo(function Message({}return null // We currently skip other types of messages})()}- {isFinal &&- isLastInGroup &&- message.status === 'completed' &&- message.id &&- !message.id.startsWith('temp-') && (- <MaxWebAnalyticsNudge message={message} messageId={message.id} />- )}{isLastInGroup && message.status === 'error' && (<MessageTemplate type="ai" boxClassName="border-warning"><div className="flex items-center gap-1.5">diff --git a/frontend/src/scenes/max/components/MaxWebAnalyticsNudge.tsx b/frontend/src/scenes/max/components/MaxWebAnalyticsNudge.tsxdeleted file mode 100644index 6889cda27348..000000000000--- a/frontend/src/scenes/max/components/MaxWebAnalyticsNudge.tsx+++ /dev/null@@ -1,58 +0,0 @@-import { useActions, useValues } from 'kea'--import { LemonButton } from '@posthog/lemon-ui'--import { iconForType } from '~/layout/panel-layout/ProjectTree/defaultTree'--import { MessageTemplate } from 'products/posthog_ai/frontend/api/primitives'--import { maxWebAnalyticsNudgeLogic } from '../logics/maxWebAnalyticsNudgeLogic'-import { maxLogic, ThreadMessage } from '../maxLogic'-import { maxThreadLogic } from '../maxThreadLogic'--export interface MaxWebAnalyticsNudgeProps {- message: ThreadMessage- messageId: string-}--export function MaxWebAnalyticsNudge({ message, messageId }: MaxWebAnalyticsNudgeProps): JSX.Element | null {- const { threadGrouped, isSharedThread, threadLoading, conversation } = useValues(maxThreadLogic)- const { conversationId } = useValues(maxLogic)-- const logic = maxWebAnalyticsNudgeLogic({- messageId,- threadGrouped,- isCompleted: message.status === 'completed' && !threadLoading,- isSharedThread,- conversationId,- conversationTopic: conversation?.topic ?? null,- })- const { shouldShowNudge } = useValues(logic)- const { nudgeClicked, nudgeDismissed } = useActions(logic)-- if (!shouldShowNudge) {- return null- }-- return (- <MessageTemplate type="ai" boxClassName="border-accent">- <div className="flex items-start gap-2">- <span className="text-lg shrink-0">{iconForType('web_analytics')}</span>- <div className="flex flex-col gap-1.5">- <span className="text-sm">- Want the full picture? Web analytics breaks down pageviews, traffic sources, and more in one- place.- </span>- <div className="flex gap-2">- <LemonButton type="primary" size="small" onClick={nudgeClicked}>- View in Web analytics- </LemonButton>- <LemonButton type="tertiary" size="small" onClick={nudgeDismissed}>- Dismiss- </LemonButton>- </div>- </div>- </div>- </MessageTemplate>- )-}diff --git a/frontend/src/scenes/max/logics/maxWebAnalyticsNudgeLogic.test.ts b/frontend/src/scenes/max/logics/maxWebAnalyticsNudgeLogic.test.tsdeleted file mode 100644index 0ddd0939cab1..000000000000--- a/frontend/src/scenes/max/logics/maxWebAnalyticsNudgeLogic.test.ts+++ /dev/null@@ -1,467 +0,0 @@-import { router } from 'kea-router'-import { expectLogic } from 'kea-test-utils'-import posthog from 'posthog-js'--import api from 'lib/api'-import { FEATURE_FLAGS } from 'lib/constants'-import { dayjs } from 'lib/dayjs'-import { featureFlagLogic } from 'lib/logic/featureFlagLogic'-import { Scene } from 'scenes/sceneTypes'-import { urls } from 'scenes/urls'--import { recentItemsModel } from '~/models/recentItemsModel'-import { AssistantMessageType } from '~/queries/schema/schema-assistant-messages'-import { NodeKind } from '~/queries/schema/schema-general'-import { initKeaTests } from '~/test/init'--import type { ThreadMessage } from '../maxThreadLogic'-import { maxWebAnalyticsNudgeLogic, MaxWebAnalyticsNudgeLogicProps } from './maxWebAnalyticsNudgeLogic'-import { maxWebAnalyticsNudgeSessionLogic } from './maxWebAnalyticsNudgeSessionLogic'--const WEB_CHART_MESSAGE: ThreadMessage = {- type: AssistantMessageType.Artifact,- content: {- content_type: 'visualization',- query: {- kind: NodeKind.TrendsQuery,- series: [{ kind: NodeKind.EventsNode, event: '$pageview' }],- },- },-} as any--const NON_WEB_MESSAGE: ThreadMessage = {- type: AssistantMessageType.Assistant,- content: 'hi',-} as any--function humanMessage(content: string): ThreadMessage {- return { type: AssistantMessageType.Human, content } as any-}--function buildProps(overrides: Partial<MaxWebAnalyticsNudgeLogicProps> = {}): MaxWebAnalyticsNudgeLogicProps {- return {- messageId: 'msg-1',- threadGrouped: [WEB_CHART_MESSAGE],- isCompleted: true,- isSharedThread: false,- conversationId: 'conv-1',- conversationTopic: null,- ...overrides,- }-}--function setFlagVariant(variant: string): void {- featureFlagLogic.actions.setFeatureFlags([], { [FEATURE_FLAGS.MAX_WEB_ANALYTICS_NUDGE]: variant })-}--function setFlagAbsent(): void {- featureFlagLogic.actions.setFeatureFlags([], {})-}--function setRecentVisit(scene: string, daysAgo: number): void {- recentItemsModel.actions.loadSceneLogViewsSuccess({ [scene]: dayjs().subtract(daysAgo, 'days').toISOString() })-}--function setNoRecentVisit(): void {- recentItemsModel.actions.loadSceneLogViewsSuccess({})-}--describe('maxWebAnalyticsNudgeLogic', () => {- let logic: ReturnType<typeof maxWebAnalyticsNudgeLogic.build>-- beforeEach(() => {- initKeaTests()- window.sessionStorage.clear()-- jest.spyOn(api.fileSystemLogView, 'list').mockReturnValue(new Promise(() => undefined))- jest.spyOn(api.fileSystem, 'list').mockReturnValue(new Promise(() => undefined))-- featureFlagLogic.mount()- maxWebAnalyticsNudgeSessionLogic.mount()- recentItemsModel.mount()- })-- afterEach(() => {- logic?.unmount()- maxWebAnalyticsNudgeSessionLogic.unmount()- recentItemsModel.unmount()- featureFlagLogic.unmount()- window.sessionStorage.clear()- jest.restoreAllMocks()- })-- describe('visitedWebAnalyticsRecently', () => {- it.each([- ['WebAnalytics visited 5 days ago', Scene.WebAnalytics, 5, true],- ['WebAnalytics visited 40 days ago', Scene.WebAnalytics, 40, false],- ['MarketingAnalytics visited 5 days ago', Scene.MarketingAnalytics, 5, true],- ])('%s returns %s', (_label, scene, daysAgo, expected) => {- setRecentVisit(scene as string, daysAgo)- setFlagVariant('test')- logic = maxWebAnalyticsNudgeLogic(buildProps())- logic.mount()- expect(logic.values.visitedWebAnalyticsRecently).toBe(expected)- })-- it('returns false when no scene views are recorded', () => {- setNoRecentVisit()- setFlagVariant('test')- logic = maxWebAnalyticsNudgeLogic(buildProps())- logic.mount()- expect(logic.values.visitedWebAnalyticsRecently).toBe(false)- })- })-- describe('isWebAnalyticsAnswer', () => {- beforeEach(() => {- setNoRecentVisit()- setFlagVariant('test')- })-- it('returns true for a web analytics chart message', () => {- logic = maxWebAnalyticsNudgeLogic(buildProps({ threadGrouped: [WEB_CHART_MESSAGE] }))- logic.mount()- expect(logic.values.isWebAnalyticsAnswer).toBe(true)- })-- it('returns true when the chart is not the last message in the group (chart + trailing summary text)', () => {- logic = maxWebAnalyticsNudgeLogic(buildProps({ threadGrouped: [WEB_CHART_MESSAGE, NON_WEB_MESSAGE] }))- logic.mount()- expect(logic.values.isWebAnalyticsAnswer).toBe(true)- expect(logic.values.trigger).toBe('chart')- })-- it('returns true when group is non-web but question text is web analytics related', () => {- logic = maxWebAnalyticsNudgeLogic(- buildProps({ threadGrouped: [humanMessage('where is my traffic coming from?'), NON_WEB_MESSAGE] })- )- logic.mount()- expect(logic.values.isWebAnalyticsAnswer).toBe(true)- })-- it('returns true for a "visited my website" question with no chart signals', () => {- logic = maxWebAnalyticsNudgeLogic(- buildProps({- threadGrouped: [humanMessage('How many people visited my website last week?'), NON_WEB_MESSAGE],- })- )- logic.mount()- expect(logic.values.isWebAnalyticsAnswer).toBe(true)- })-- it('returns false when group is non-web and question text has no web keywords', () => {- logic = maxWebAnalyticsNudgeLogic(- buildProps({ threadGrouped: [humanMessage('how many users signed up?'), NON_WEB_MESSAGE] })- )- logic.mount()- expect(logic.values.isWebAnalyticsAnswer).toBe(false)- })-- it('returns true when the conversation topic is web_analytics, even with a non-web group and question', () => {- logic = maxWebAnalyticsNudgeLogic(- buildProps({- threadGrouped: [humanMessage('how many users signed up?'), NON_WEB_MESSAGE],- conversationTopic: 'web_analytics',- })- )- logic.mount()- expect(logic.values.isWebAnalyticsAnswer).toBe(true)- })-- it('a non-web conversation topic does not by itself make it a web analytics answer', () => {- logic = maxWebAnalyticsNudgeLogic(- buildProps({- threadGrouped: [humanMessage('how many users signed up?'), NON_WEB_MESSAGE],- conversationTopic: 'product_analytics',- })- )- logic.mount()- expect(logic.values.isWebAnalyticsAnswer).toBe(false)- })- })-- describe('trigger', () => {- beforeEach(() => {- setNoRecentVisit()- setFlagVariant('test')- })-- it('returns "chart" for a web analytics chart message', () => {- logic = maxWebAnalyticsNudgeLogic(buildProps({ threadGrouped: [WEB_CHART_MESSAGE] }))- logic.mount()- expect(logic.values.trigger).toBe('chart')- })-- it('returns "question" when only the question text matched (non-web group + web question)', () => {- logic = maxWebAnalyticsNudgeLogic(- buildProps({ threadGrouped: [humanMessage('show me my top pages'), NON_WEB_MESSAGE] })- )- logic.mount()- expect(logic.values.trigger).toBe('question')- })-- it('returns "topic" when the conversation topic is web_analytics (authoritative over chart)', () => {- logic = maxWebAnalyticsNudgeLogic(- buildProps({ threadGrouped: [WEB_CHART_MESSAGE], conversationTopic: 'web_analytics' })- )- logic.mount()- expect(logic.values.trigger).toBe('topic')- })- })-- describe('isEligible', () => {- beforeEach(() => {- setNoRecentVisit()- setFlagVariant('test')- })-- it('is true when all conditions hold', () => {- logic = maxWebAnalyticsNudgeLogic(buildProps())- logic.mount()- expect(logic.values.isEligible).toBe(true)- })-- it.each([- ['isCompleted is false', { isCompleted: false }],- ['isSharedThread is true', { isSharedThread: true }],- ] as [string, Partial<MaxWebAnalyticsNudgeLogicProps>][])('is false when %s', (_label, propsOverride) => {- logic = maxWebAnalyticsNudgeLogic(buildProps(propsOverride))- logic.mount()- expect(logic.values.isEligible).toBe(false)- })-- it('is false when visitedWebAnalyticsRecently is true', () => {- setRecentVisit(Scene.WebAnalytics, 5)- logic = maxWebAnalyticsNudgeLogic(buildProps())- logic.mount()- expect(logic.values.isEligible).toBe(false)- })- })-- describe('isEligible when sceneLogViewsHasLoaded is false', () => {- it('is false when sceneLogViewsHasLoaded is false', () => {- setFlagVariant('test')-- logic = maxWebAnalyticsNudgeLogic(buildProps())- logic.mount()-- expect(logic.values.sceneLogViewsHasLoaded).toBe(false)- expect(logic.values.isEligible).toBe(false)- })- })-- describe('shouldShowNudge', () => {- beforeEach(() => {- setNoRecentVisit()- })-- it('is true when variant is "test", eligible, and fresh session', () => {- setFlagVariant('test')- logic = maxWebAnalyticsNudgeLogic(buildProps())- logic.mount()- expect(logic.values.shouldShowNudge).toBe(true)- })-- it('is false when variant is "control"', () => {- setFlagVariant('control')- logic = maxWebAnalyticsNudgeLogic(buildProps())- logic.mount()- expect(logic.values.shouldShowNudge).toBe(false)- })-- it('is false when flag is not enrolled', () => {- setFlagAbsent()- logic = maxWebAnalyticsNudgeLogic(buildProps())- logic.mount()- expect(logic.values.shouldShowNudge).toBe(false)- })-- it('is false after nudgeDismissed', async () => {- setFlagVariant('test')- logic = maxWebAnalyticsNudgeLogic(buildProps())- logic.mount()-- await expectLogic(logic, () => {- logic.actions.nudgeDismissed()- }).toMatchValues({ shouldShowNudge: false })- })-- it('is false when shownForMessageId already equals a DIFFERENT message id', () => {- maxWebAnalyticsNudgeSessionLogic.actions.hydrateFromStorage({- shownForMessageId: 'other-msg',- dismissed: false,- eligibleReported: false,- })-- setFlagVariant('test')- logic = maxWebAnalyticsNudgeLogic(buildProps({ messageId: 'msg-1' }))- logic.mount()- expect(logic.values.shouldShowNudge).toBe(false)- })-- it('is true when shownForMessageId equals this message id', () => {- maxWebAnalyticsNudgeSessionLogic.actions.hydrateFromStorage({- shownForMessageId: 'msg-1',- dismissed: false,- eligibleReported: false,- })-- setFlagVariant('test')- logic = maxWebAnalyticsNudgeLogic(buildProps({ messageId: 'msg-1' }))- logic.mount()- expect(logic.values.shouldShowNudge).toBe(true)- })- })-- describe('posthog.capture reporting', () => {- let captureSpy: jest.SpyInstance-- beforeEach(() => {- captureSpy = jest.spyOn(posthog, 'capture').mockImplementation(() => undefined as any)- setNoRecentVisit()- })-- afterEach(() => {- captureSpy.mockRestore()- })-- it('fires both "eligible" and "shown" exactly once for variant "test" on mount', () => {- setFlagVariant('test')- logic = maxWebAnalyticsNudgeLogic(buildProps())- logic.mount()-- const expectedProperties = {- conversation_id: 'conv-1',- message_id: 'msg-1',- variant: 'test',- trigger: 'chart',- }- expect(captureSpy).toHaveBeenCalledWith('posthog ai web analytics nudge eligible', expectedProperties)- expect(captureSpy).toHaveBeenCalledWith('posthog ai web analytics nudge shown', expectedProperties)- expect(- captureSpy.mock.calls.filter((c) => c[0] === 'posthog ai web analytics nudge eligible')- ).toHaveLength(1)- expect(captureSpy.mock.calls.filter((c) => c[0] === 'posthog ai web analytics nudge shown')).toHaveLength(1)- })-- it('fires "eligible" only (no "shown") for variant "control"', () => {- setFlagVariant('control')- logic = maxWebAnalyticsNudgeLogic(buildProps())- logic.mount()-- expect(captureSpy).toHaveBeenCalledWith(- 'posthog ai web analytics nudge eligible',- expect.objectContaining({ variant: 'control' })- )- expect(captureSpy).not.toHaveBeenCalledWith('posthog ai web analytics nudge shown', expect.anything())- })-- it('fires neither event when not enrolled in the flag', () => {- setFlagAbsent()- logic = maxWebAnalyticsNudgeLogic(buildProps())- logic.mount()-- expect(captureSpy).not.toHaveBeenCalledWith('posthog ai web analytics nudge eligible', expect.anything())- expect(captureSpy).not.toHaveBeenCalledWith('posthog ai web analytics nudge shown', expect.anything())- })- })-- describe('nudgeClicked and nudgeDismissed actions', () => {- let captureSpy: jest.SpyInstance-- beforeEach(() => {- captureSpy = jest.spyOn(posthog, 'capture').mockImplementation(() => undefined as any)- setNoRecentVisit()- setFlagVariant('test')- logic = maxWebAnalyticsNudgeLogic(buildProps())- logic.mount()- captureSpy.mockClear()- })-- afterEach(() => {- captureSpy.mockRestore()- })-- it('nudgeClicked fires the clicked event with reportProperties', async () => {- await expectLogic(logic, () => {- logic.actions.nudgeClicked()- })-- expect(captureSpy).toHaveBeenCalledWith('posthog ai web analytics nudge clicked', {- conversation_id: 'conv-1',- message_id: 'msg-1',- variant: 'test',- trigger: 'chart',- })- })-- it('nudgeClicked navigates to web analytics so the chat moves to the side panel', async () => {- const pushSpy = jest.spyOn(router.actions, 'push')-- await expectLogic(logic, () => {- logic.actions.nudgeClicked()- })-- expect(pushSpy).toHaveBeenCalledWith(urls.webAnalytics(), { utm_source: 'posthog-ai-nudge' })- })-- it('nudgeDismissed fires the dismissed event and flips shouldShowNudge to false', async () => {- expect(logic.values.shouldShowNudge).toBe(true)-- await expectLogic(logic, () => {- logic.actions.nudgeDismissed()- }).toMatchValues({ shouldShowNudge: false })-- expect(captureSpy).toHaveBeenCalledWith('posthog ai web analytics nudge dismissed', {- conversation_id: 'conv-1',- message_id: 'msg-1',- variant: 'test',- trigger: 'chart',- })- })- })-- describe('once-per-session deduplication', () => {- let captureSpy: jest.SpyInstance- let logic2: ReturnType<typeof maxWebAnalyticsNudgeLogic.build>-- beforeEach(() => {- captureSpy = jest.spyOn(posthog, 'capture').mockImplementation(() => undefined as any)- setNoRecentVisit()- setFlagVariant('test')- })-- afterEach(() => {- logic2?.unmount()- captureSpy.mockRestore()- })-- it('does not fire eligible or shown again for a second message, and shouldShowNudge is false on it', async () => {- logic = maxWebAnalyticsNudgeLogic(buildProps({ messageId: 'msg-1' }))- logic.mount()-- const eligibleCalls1 = captureSpy.mock.calls.filter(- (c) => c[0] === 'posthog ai web analytics nudge eligible'- ).length- const shownCalls1 = captureSpy.mock.calls.filter(- (c) => c[0] === 'posthog ai web analytics nudge shown'- ).length- expect(eligibleCalls1).toBe(1)- expect(shownCalls1).toBe(1)-- captureSpy.mockClear()-- logic2 = maxWebAnalyticsNudgeLogic(buildProps({ messageId: 'msg-2' }))- logic2.mount()-- await new Promise((resolve) => setTimeout(resolve, 0))-- expect(- captureSpy.mock.calls.filter((c) => c[0] === 'posthog ai web analytics nudge eligible')- ).toHaveLength(0)- expect(captureSpy.mock.calls.filter((c) => c[0] === 'posthog ai web analytics nudge shown')).toHaveLength(0)-- expect(logic2.values.shouldShowNudge).toBe(false)- })- })-})diff --git a/frontend/src/scenes/max/logics/maxWebAnalyticsNudgeLogic.ts b/frontend/src/scenes/max/logics/maxWebAnalyticsNudgeLogic.tsdeleted file mode 100644index 36de995f3a98..000000000000--- a/frontend/src/scenes/max/logics/maxWebAnalyticsNudgeLogic.ts+++ /dev/null@@ -1,303 +0,0 @@-import { MakeLogicType, actions, afterMount, connect, kea, key, listeners, path, props, selectors } from 'kea'-import { router } from 'kea-router'-import { subscriptions } from 'kea-subscriptions'-import posthog from 'posthog-js'--import { FEATURE_FLAGS } from 'lib/constants'-import { dayjs } from 'lib/dayjs'-import { featureFlagLogic } from 'lib/logic/featureFlagLogic'-import { Scene } from 'scenes/sceneTypes'-import { urls } from 'scenes/urls'--import { recentItemsModel } from '~/models/recentItemsModel'-import { HumanMessage } from '~/queries/schema/schema-assistant-messages'-import { ConversationTopic } from '~/types'--import type { FeatureFlagsSet } from '../../../lib/logic/featureFlagLogic'-import { maxGlobalLogic } from '../maxGlobalLogic'-import type { ThreadMessage } from '../maxThreadLogic'-import { isHumanMessage } from '../utils'-import { isWebAnalyticsRelatedMessage, isWebAnalyticsRelatedQuestion } from '../utils/detectWebAnalyticsQuery'-import { maxWebAnalyticsNudgeSessionLogic } from './maxWebAnalyticsNudgeSessionLogic'--const WEB_ANALYTICS_RECENT_DAYS = 30--const WEB_ANALYTICS_SCENE_REFS: string[] = [- Scene.WebAnalytics,- Scene.WebAnalyticsPageReports,- Scene.WebAnalyticsWebVitals,- Scene.WebAnalyticsHealth,- Scene.WebAnalyticsLive,- Scene.MarketingAnalytics,-]--function getFinalAnswerGroup(messages: ThreadMessage[]): ThreadMessage[] {- const group: ThreadMessage[] = []- for (let i = messages.length - 1; i >= 0; i--) {- if (isHumanMessage(messages[i])) {- break- }- group.unshift(messages[i])- }- return group-}--export type NudgeTrigger = 'topic' | 'chart' | 'question'--export interface MaxWebAnalyticsNudgeLogicProps {- messageId: string- threadGrouped: ThreadMessage[]- isCompleted: boolean- isSharedThread: boolean- conversationId: string | null- // Domain classified by PostHog AI (from the conversation's first question); authoritative when present.- conversationTopic: ConversationTopic | null-}--export interface NudgeReportProperties {- conversation_id: string | null- message_id: string- variant: string | null- trigger: NudgeTrigger-}--// Generated by kea-typegen. Update if you're an agent, ignore if you're human.-export interface maxWebAnalyticsNudgeLogicValues {- featureFlags: FeatureFlagsSet // featureFlagLogic- dismissedThisSession: boolean // maxWebAnalyticsNudgeSessionLogic- eligibleReportedThisSession: boolean // maxWebAnalyticsNudgeSessionLogic- shownForMessageId: string | null // maxWebAnalyticsNudgeSessionLogic- sceneLogViewsByRef: Record<string, string> // recentItemsModel- sceneLogViewsHasLoaded: boolean // recentItemsModel- finalAnswerGroup: ThreadMessage[]- groupHasWebChart: boolean- isEligible: boolean- isWebAnalyticsAnswer: boolean- lastHumanQuestion: string | null- reportProperties: NudgeReportProperties- shouldShowNudge: boolean- topicIsWebAnalytics: boolean- trigger: NudgeTrigger- variant: string | null- visitedWebAnalyticsRecently: boolean-}--// Generated by kea-typegen. Update if you're an agent, ignore if you're human.-export interface maxWebAnalyticsNudgeLogicActions {- markEligibleReported: () => {- value: true- } // maxWebAnalyticsNudgeSessionLogic- markNudgeDismissed: () => {- value: true- } // maxWebAnalyticsNudgeSessionLogic- markNudgeShown: (messageId: string) => {- messageId: string- } // maxWebAnalyticsNudgeSessionLogic- evaluateReporting: () => {- value: true- }- nudgeClicked: () => {- value: true- }- nudgeDismissed: () => {- value: true- }-}--// Generated by kea-typegen. Update if you're an agent, ignore if you're human.-export interface maxWebAnalyticsNudgeLogicMeta {- key: string- __keaTypeGenInternalSelectorTypes: {- variant: (featureFlags: FeatureFlagsSet) => string | null- finalAnswerGroup: (threadGrouped: ThreadMessage[]) => ThreadMessage[]- lastHumanQuestion: (threadGrouped: ThreadMessage[]) => string | null- groupHasWebChart: (finalAnswerGroup: ThreadMessage[]) => boolean- topicIsWebAnalytics: (conversationTopic: ConversationTopic | null) => boolean- trigger: (topicIsWebAnalytics: boolean, groupHasWebChart: boolean) => NudgeTrigger- isWebAnalyticsAnswer: (- topicIsWebAnalytics: boolean,- groupHasWebChart: boolean,- lastHumanQuestion: string | null- ) => boolean- visitedWebAnalyticsRecently: (sceneLogViewsByRef: Record<string, string>) => boolean- isEligible: (- isWebAnalyticsAnswer: boolean,- visitedWebAnalyticsRecently: boolean,- sceneLogViewsHasLoaded: boolean,- isCompleted: boolean,- isSharedThread: boolean- ) => boolean- shouldShowNudge: (- isEligible: boolean,- variant: string | null,- dismissedThisSession: boolean,- shownForMessageId: string | null,- messageId: string- ) => boolean- reportProperties: (- variant: string | null,- trigger: NudgeTrigger,- conversationId: string | null,- messageId: string- ) => NudgeReportProperties- }-}--export type maxWebAnalyticsNudgeLogicType = MakeLogicType<- maxWebAnalyticsNudgeLogicValues,- maxWebAnalyticsNudgeLogicActions,- MaxWebAnalyticsNudgeLogicProps,- maxWebAnalyticsNudgeLogicMeta->--export const maxWebAnalyticsNudgeLogic = kea<maxWebAnalyticsNudgeLogicType>([- path(['scenes', 'max', 'logics', 'maxWebAnalyticsNudgeLogic']),- props({} as MaxWebAnalyticsNudgeLogicProps),- key((props) => props.messageId),-- connect(() => ({- values: [- featureFlagLogic,- ['featureFlags'],- recentItemsModel,- ['sceneLogViewsByRef', 'sceneLogViewsHasLoaded'],- maxWebAnalyticsNudgeSessionLogic,- ['shownForMessageId', 'dismissedThisSession', 'eligibleReportedThisSession'],- ],- actions: [maxWebAnalyticsNudgeSessionLogic, ['markNudgeShown', 'markNudgeDismissed', 'markEligibleReported']],- })),-- actions({- nudgeClicked: true,- nudgeDismissed: true,- evaluateReporting: true,- }),-- selectors({- variant: [- (s) => [s.featureFlags],- (featureFlags: import('lib/logic/featureFlagLogic').FeatureFlagsSet): string | null => {- const value = featureFlags[FEATURE_FLAGS.MAX_WEB_ANALYTICS_NUDGE]- return typeof value === 'string' ? value : null- },- ],- finalAnswerGroup: [- (_s, p) => [p.threadGrouped],- (threadGrouped: ThreadMessage[]): ThreadMessage[] => getFinalAnswerGroup(threadGrouped),- ],- lastHumanQuestion: [- (_s, p) => [p.threadGrouped],- (threadGrouped: ThreadMessage[]): string | null =>- (threadGrouped.filter(isHumanMessage).pop() as HumanMessage | undefined)?.content ?? null,- ],- groupHasWebChart: [- (s) => [s.finalAnswerGroup],- (finalAnswerGroup: ThreadMessage[]): boolean => finalAnswerGroup.some(isWebAnalyticsRelatedMessage),- ],- topicIsWebAnalytics: [- (_s, p) => [p.conversationTopic],- (conversationTopic: ConversationTopic | null): boolean => conversationTopic === 'web_analytics',- ],- trigger: [- (s) => [s.topicIsWebAnalytics, s.groupHasWebChart],- (topicIsWebAnalytics: boolean, groupHasWebChart: boolean): NudgeTrigger =>- topicIsWebAnalytics ? 'topic' : groupHasWebChart ? 'chart' : 'question',- ],- isWebAnalyticsAnswer: [- (s) => [s.topicIsWebAnalytics, s.groupHasWebChart, s.lastHumanQuestion],- (topicIsWebAnalytics: boolean, groupHasWebChart: boolean, lastHumanQuestion: string | null): boolean =>- topicIsWebAnalytics || groupHasWebChart || isWebAnalyticsRelatedQuestion(lastHumanQuestion),- ],- visitedWebAnalyticsRecently: [- (s) => [s.sceneLogViewsByRef],- (sceneLogViewsByRef: Record<string, string>): boolean => {- const cutoff = dayjs().subtract(WEB_ANALYTICS_RECENT_DAYS, 'days')- return WEB_ANALYTICS_SCENE_REFS.some((ref) => {- const viewedAt = sceneLogViewsByRef[ref]- return !!viewedAt && dayjs(viewedAt).isAfter(cutoff)- })- },- ],- isEligible: [- (s, p) => [- s.isWebAnalyticsAnswer,- s.visitedWebAnalyticsRecently,- s.sceneLogViewsHasLoaded,- p.isCompleted,- p.isSharedThread,- ],- (- isWebAnalyticsAnswer: boolean,- visitedRecently: boolean,- sceneLogViewsHasLoaded: boolean,- isCompleted: boolean,- isSharedThread: boolean- ): boolean =>- isWebAnalyticsAnswer && !visitedRecently && sceneLogViewsHasLoaded && isCompleted && !isSharedThread,- ],- shouldShowNudge: [- (s, p) => [s.isEligible, s.variant, s.dismissedThisSession, s.shownForMessageId, p.messageId],- (- isEligible: boolean,- variant: string | null,- dismissed: boolean,- shownForMessageId: string | null,- messageId: string- ): boolean =>- isEligible &&- variant === 'test' &&- !dismissed &&- (shownForMessageId === null || shownForMessageId === messageId),- ],- reportProperties: [- (s, p) => [s.variant, s.trigger, p.conversationId, p.messageId],- (- variant: string | null,- trigger: NudgeTrigger,- conversationId: string | null,- messageId: string- ): NudgeReportProperties => ({- conversation_id: conversationId,- message_id: messageId,- variant,- trigger,- }),- ],- }),-- listeners(({ props, values, actions }) => ({- nudgeClicked: () => {- posthog.capture('posthog ai web analytics nudge clicked', values.reportProperties)- // Move the chat into the side panel so it survives navigating away to web analytics.- maxGlobalLogic.findMounted()?.actions.openSidePanelMax(props.conversationId ?? undefined)- router.actions.push(urls.webAnalytics(), { utm_source: 'posthog-ai-nudge' })- },- nudgeDismissed: () => {- posthog.capture('posthog ai web analytics nudge dismissed', values.reportProperties)- actions.markNudgeDismissed()- },- evaluateReporting: () => {- if (- values.isEligible &&- !values.eligibleReportedThisSession &&- (values.variant === 'control' || values.variant === 'test')- ) {- actions.markEligibleReported()- posthog.capture('posthog ai web analytics nudge eligible', values.reportProperties)- }- if (values.shouldShowNudge && values.shownForMessageId === null) {- actions.markNudgeShown(props.messageId)- posthog.capture('posthog ai web analytics nudge shown', values.reportProperties)- }- },- })),-- subscriptions(({ actions }) => ({- isEligible: () => actions.evaluateReporting(),- shouldShowNudge: () => actions.evaluateReporting(),- })),-- afterMount(({ actions }) => {- actions.evaluateReporting()- }),-])diff --git a/frontend/src/scenes/max/logics/maxWebAnalyticsNudgeSessionLogic.ts b/frontend/src/scenes/max/logics/maxWebAnalyticsNudgeSessionLogic.tsdeleted file mode 100644index 4e598d63b097..000000000000--- a/frontend/src/scenes/max/logics/maxWebAnalyticsNudgeSessionLogic.ts+++ /dev/null@@ -1,121 +0,0 @@-import { MakeLogicType, actions, afterMount, kea, listeners, path, reducers } from 'kea'--import { permanentlyMount } from 'lib/utils/kea-logic-builders'--const STORAGE_KEY = 'posthog-ai-web-analytics-nudge-session'--export interface NudgeSessionState {- shownForMessageId: string | null- dismissed: boolean- eligibleReported: boolean-}--const EMPTY_STATE: NudgeSessionState = {- shownForMessageId: null,- dismissed: false,- eligibleReported: false,-}--function readState(): NudgeSessionState {- try {- const raw = window.sessionStorage.getItem(STORAGE_KEY)- if (!raw) {- return EMPTY_STATE- }- return { ...EMPTY_STATE, ...(JSON.parse(raw) as Partial<NudgeSessionState>) }- } catch {- return EMPTY_STATE- }-}--function writeState(state: NudgeSessionState): void {- try {- window.sessionStorage.setItem(STORAGE_KEY, JSON.stringify(state))- } catch {- return- }-}--// Generated by kea-typegen. Update if you're an agent, ignore if you're human.-export interface maxWebAnalyticsNudgeSessionLogicValues {- dismissedThisSession: boolean- eligibleReportedThisSession: boolean- shownForMessageId: string | null-}--// Generated by kea-typegen. Update if you're an agent, ignore if you're human.-export interface maxWebAnalyticsNudgeSessionLogicActions {- hydrateFromStorage: (state: NudgeSessionState) => {- state: NudgeSessionState- }- markEligibleReported: () => {- value: true- }- markNudgeDismissed: () => {- value: true- }- markNudgeShown: (messageId: string) => {- messageId: string- }-}--export type maxWebAnalyticsNudgeSessionLogicType = MakeLogicType<- maxWebAnalyticsNudgeSessionLogicValues,- maxWebAnalyticsNudgeSessionLogicActions->--export const maxWebAnalyticsNudgeSessionLogic = kea<maxWebAnalyticsNudgeSessionLogicType>([- path(['scenes', 'max', 'logics', 'maxWebAnalyticsNudgeSessionLogic']),-- actions({- markNudgeShown: (messageId: string) => ({ messageId }),- markNudgeDismissed: true,- markEligibleReported: true,- hydrateFromStorage: (state: NudgeSessionState) => ({ state }),- }),-- reducers({- shownForMessageId: [- null as string | null,- {- markNudgeShown: (_, { messageId }) => messageId,- hydrateFromStorage: (_, { state }) => state.shownForMessageId,- },- ],- dismissedThisSession: [- false,- {- markNudgeDismissed: () => true,- hydrateFromStorage: (_, { state }) => state.dismissed,- },- ],- eligibleReportedThisSession: [- false,- {- markEligibleReported: () => true,- hydrateFromStorage: (_, { state }) => state.eligibleReported,- },- ],- }),-- listeners(({ values }) => {- const persist = (): void => {- writeState({- shownForMessageId: values.shownForMessageId,- dismissed: values.dismissedThisSession,- eligibleReported: values.eligibleReportedThisSession,- })- }- return {- markNudgeShown: persist,- markNudgeDismissed: persist,- markEligibleReported: persist,- }- }),-- afterMount(({ actions }) => {- actions.hydrateFromStorage(readState())- }),-- permanentlyMount(),-])