: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
feat(mcp-analytics): add the how it works frame and its first stage (#128678)
Lucas Faria79c21fba4eed
diff --git a/products/mcp_analytics/frontend/emptyState/MCPHowItWorks.scss b/products/mcp_analytics/frontend/emptyState/MCPHowItWorks.scssnew file mode 100644index 000000000000..252a442ba374--- /dev/null+++ b/products/mcp_analytics/frontend/emptyState/MCPHowItWorks.scss@@ -0,0 +1,240 @@+.MCPHowItWorks {+ --mcp-how-surface: var(--color-bg-surface-primary);+ --mcp-how-card: var(--color-bg-surface-secondary);+ --mcp-how-border: var(--color-border-primary);+ --mcp-how-line: var(--color-border-secondary);+ --mcp-how-text: var(--color-text-primary);+ --mcp-how-text-secondary: var(--color-text-secondary);+ --mcp-how-muted: var(--color-text-tertiary);+ --mcp-how-blue: var(--color-blue-500);+ --mcp-how-yellow: var(--brand-yellow);+ --mcp-how-purple: var(--color-purple-500);+ --mcp-how-green: var(--color-green-500);+ --mcp-how-orange: var(--color-accent);++ // Text on the colored step badges and chips stays dark in both themes, because the fills stay bright.+ --mcp-how-ink: var(--color-neutral-950);+ --mcp-how-halo: none;+ --mcp-how-mono: ui-monospace, sfmono-regular, menlo, consolas, monospace;++ display: block;+ font-weight: 500;+ color: var(--mcp-how-text);+ container: mcp-how-it-works / inline-size;++ // The dark hedgehog outline would vanish into a dark background, so it gets a light halo.+ [theme='dark'] & {+ --mcp-how-halo: drop-shadow(0 0 1.5px var(--color-text-primary)) drop-shadow(0 0 1px var(--color-text-primary));+ }++ svg {+ flex: none;+ }++ &__diagram {+ display: flex;+ flex-direction: column;+ padding: 4px 0 10px;+ }++ &__tabs {+ display: grid;+ grid-template-columns: repeat(3, minmax(0, 1fr));+ gap: 6px;+ order: 2;+ width: 100%;+ max-width: 520px;+ margin: 0 auto 10px;+ }++ &__tab {+ --c: var(--mcp-how-blue);++ position: relative;+ display: flex;+ gap: 7px;+ align-items: center;+ min-width: 0;+ padding: 7px 9px;+ overflow: hidden;+ font: inherit;+ font-size: 13px;+ font-weight: 700;+ line-height: 1.15;+ color: var(--mcp-how-text-secondary);+ text-align: left;+ appearance: none;+ cursor: pointer;+ background: transparent;+ border: 1.5px solid var(--mcp-how-border);+ border-radius: 9px;+ transition:+ border-color 0.3s ease,+ background 0.3s ease,+ color 0.3s ease;++ &:hover {+ color: var(--mcp-how-text);+ border-color: var(--mcp-how-line);+ }++ &[data-p='2'] {+ --c: var(--mcp-how-yellow);+ }++ &[data-p='3'] {+ --c: var(--mcp-how-green);+ }++ &::after {+ position: absolute;+ bottom: 0;+ left: 0;+ width: 0;+ height: 2px;+ content: '';+ background: var(--c);+ }++ &[aria-selected='true'] {+ color: var(--mcp-how-text);+ background: var(--mcp-how-card);+ border-color: var(--c);+ }+ }++ &__diagram--auto &__tab[aria-selected='true']::after {+ animation: MCPHowItWorks__progress var(--mcp-how-step-duration) linear forwards;+ }++ &__diagram--done &__tab[aria-selected='true']::after {+ width: 100%;+ }++ &__tab-num {+ display: grid;+ flex: none;+ place-items: center;+ width: 22px;+ height: 22px;+ font-size: 12px;+ color: var(--mcp-how-text-secondary);+ background: var(--mcp-how-card);+ border-radius: 50%;+ transition:+ background 0.3s ease,+ color 0.3s ease;+ }++ &__tab[aria-selected='true'] &__tab-num {+ color: var(--mcp-how-ink);+ background: var(--c);+ }++ &__tab-title {+ min-width: 0;+ overflow-wrap: anywhere;+ }++ &__flow {+ display: grid;+ grid-template-columns: minmax(0, 1fr);+ order: 3;+ width: 100%;+ max-width: 520px;+ margin: 0 auto;+ }++ &__step {+ --c: var(--mcp-how-blue);++ grid-area: 1 / 1;+ visibility: hidden;+ opacity: 0;+ transition: opacity 0.35s ease;++ &--2 {+ --c: var(--mcp-how-yellow);+ }++ &--3 {+ --c: var(--mcp-how-green);+ }+ }++ &__diagram:is([data-phase='0'], [data-phase='1']) &__step--1,+ &__diagram[data-phase='2'] &__step--2,+ &__diagram[data-phase='3'] &__step--3 {+ visibility: visible;+ opacity: 1;+ }++ &__stage {+ position: relative;+ width: 100%;+ height: 252px;+ overflow: hidden;+ background: var(--mcp-how-card);+ border: 1.5px solid var(--c);+ border-radius: 12px;+ box-shadow: 0 3px 0 var(--mcp-how-line);+ }++ // Reveal: each `__rv` element fades up once its step is reached, after its own `--d` delay.++ &__rv {+ opacity: 0;+ transition:+ opacity 0.5s ease var(--d, 0s),+ transform 0.5s ease var(--d, 0s);+ transform: translateY(8px);+ }++ &__diagram:is([data-phase='1'], [data-phase='2'], [data-phase='3']) &__step--1 &__rv,+ &__diagram:is([data-phase='2'], [data-phase='3']) &__step--2 &__rv,+ &__diagram[data-phase='3'] &__step--3 &__rv {+ opacity: 1;+ transform: none;+ }++ // Phase 0 resets every reveal at once, so a replay starts from a hidden stage.+ &__diagram[data-phase='0'] * {+ transition-delay: 0s !important;+ transition-duration: 0s !important;+ animation: none !important;+ }++ // Under reduced motion and in Storybook the sidebar opens on the last step and stays still.+ &--static *,+ &--static *::before,+ &--static *::after {+ transition: none !important;+ animation: none !important;+ }++ @container mcp-how-it-works (max-width: 420px) {+ &__tab {+ flex-direction: column;+ gap: 4px;+ align-items: flex-start;+ padding: 7px 8px;+ font-size: 12px;+ }++ &__stage {+ height: 272px;+ }+ }++ @container mcp-how-it-works (max-width: 340px) {+ &__tab-title {+ font-size: 11px;+ }+ }+}++@keyframes MCPHowItWorks__progress {+ to {+ width: 100%;+ }+}diff --git a/products/mcp_analytics/frontend/emptyState/MCPHowItWorks.tsx b/products/mcp_analytics/frontend/emptyState/MCPHowItWorks.tsxnew file mode 100644index 000000000000..bd558ddc2561--- /dev/null+++ b/products/mcp_analytics/frontend/emptyState/MCPHowItWorks.tsx@@ -0,0 +1,175 @@+import './MCPHowItWorks.scss'++import { type CSSProperties, type ComponentType, type KeyboardEvent, useEffect, useRef, useState } from 'react'++import type { ProductEmptyStateMode } from 'lib/components/ProductEmptyState/types'+import { cn } from 'lib/utils/css-classes'+import { inStorybook, inStorybookTestRunner } from 'lib/utils/dom'++import { MCPHowItWorksWrapStage } from './MCPHowItWorksWrapStage'++type Step = number+/** 0 is the frame before the first reveal, and the frame a replay restarts from. */+type Phase = 0 | Step++interface MCPHowItWorksProps {+ mode: ProductEmptyStateMode+ preview: boolean+}++const STEPS: { step: Step; title: string; Stage: ComponentType<MCPHowItWorksProps> }[] = [+ { step: 1, title: 'Wrap your MCP server', Stage: MCPHowItWorksWrapStage },+]+const LAST_STEP: Step = STEPS.length++const STEP_MS = 4300++function isStatic(): boolean {+ return inStorybook() || inStorybookTestRunner() || !!window.matchMedia?.('(prefers-reduced-motion: reduce)').matches+}++/**+ * How MCP analytics works, in three steps the Doc Brown hedgehog walks through: the setup screen's+ * sidebar. It plays 1, 2, 3 once when it scrolls into view and stops on the last step. Picking a+ * step stops the autoplay and replays that step's reveal.+ */+export function MCPHowItWorks({ mode, preview }: MCPHowItWorksProps): JSX.Element {+ const [staticRender] = useState(isStatic)+ const [phase, setPhase] = useState<Phase>(staticRender ? LAST_STEP : 0)+ const [replayTo, setReplayTo] = useState<Step | null>(null)+ const [autoplay, setAutoplay] = useState(false)+ const rootRef = useRef<HTMLDivElement>(null)+ const tabRefs = useRef<(HTMLButtonElement | null)[]>([])++ useEffect(() => {+ const root = rootRef.current+ if (staticRender || !root) {+ return+ }+ const observer = new IntersectionObserver(+ ([entry]) => {+ if (entry.isIntersecting) {+ observer.disconnect()+ setPhase(1)+ setAutoplay(true)+ }+ },+ { threshold: 0.3 }+ )+ observer.observe(root)+ return () => observer.disconnect()+ }, [staticRender])++ useEffect(() => {+ if (!autoplay || phase === 0) {+ return+ }+ if (phase === LAST_STEP) {+ setAutoplay(false)+ return+ }+ const timeout = window.setTimeout(() => setPhase(phase + 1), STEP_MS)+ return () => window.clearTimeout(timeout)+ }, [autoplay, phase])++ // A replay holds phase 0 for two frames, so the browser paints the hidden state before the reveal transitions run.+ useEffect(() => {+ if (replayTo === null) {+ return+ }+ let second = 0+ const first = window.requestAnimationFrame(() => {+ second = window.requestAnimationFrame(() => {+ setPhase(replayTo)+ setReplayTo(null)+ })+ })+ return () => {+ window.cancelAnimationFrame(first)+ window.cancelAnimationFrame(second)+ }+ }, [replayTo])++ const selected: Step = replayTo ?? (phase === 0 ? 1 : phase)++ const selectStep = (step: Step): void => {+ setAutoplay(false)+ if (staticRender) {+ setPhase(step)+ return+ }+ setPhase(0)+ setReplayTo(step)+ }++ const onTabKeyDown = (event: KeyboardEvent<HTMLButtonElement>): void => {+ const moves: Record<string, Step> = {+ ArrowRight: (selected % LAST_STEP) + 1,+ ArrowLeft: ((selected + LAST_STEP - 2) % LAST_STEP) + 1,+ Home: 1,+ End: LAST_STEP,+ }+ const next = moves[event.key]+ if (next) {+ event.preventDefault()+ selectStep(next)+ tabRefs.current[next - 1]?.focus()+ }+ }++ return (+ <div className={cn('MCPHowItWorks', staticRender && 'MCPHowItWorks--static')} ref={rootRef}>+ <section+ className={cn(+ 'MCPHowItWorks__diagram',+ autoplay && 'MCPHowItWorks__diagram--auto',+ !autoplay && phase !== 0 && 'MCPHowItWorks__diagram--done'+ )}+ data-phase={phase}+ style={{ '--mcp-how-step-duration': `${STEP_MS}ms` } as CSSProperties}+ aria-label="MCP analytics in three steps: wrap your MCP server, get a pre-built dashboard, ask questions from anywhere"+ >+ <div className="MCPHowItWorks__tabs" role="tablist" aria-label="How MCP analytics works, step by step">+ {STEPS.map(({ step, title }) => (+ <button+ key={step}+ ref={(element) => {+ tabRefs.current[step - 1] = element+ }}+ type="button"+ role="tab"+ id={`mcp-how-it-works-tab-${step}`}+ aria-controls={`mcp-how-it-works-step-${step}`}+ aria-selected={selected === step}+ tabIndex={selected === step ? 0 : -1}+ className="MCPHowItWorks__tab"+ data-p={step}+ onClick={() => selectStep(step)}+ onKeyDown={onTabKeyDown}+ data-attr={`mcp-analytics-how-it-works-step-${step}`}+ >+ <span className="MCPHowItWorks__tab-num">{step}</span>+ <span className="MCPHowItWorks__tab-title">{title}</span>+ </button>+ ))}+ </div>++ <div className="MCPHowItWorks__flow">+ {STEPS.map(({ step, Stage }) => (+ <div+ key={step}+ className={`MCPHowItWorks__step MCPHowItWorks__step--${step}`}+ role="tabpanel"+ id={`mcp-how-it-works-step-${step}`}+ aria-labelledby={`mcp-how-it-works-tab-${step}`}+ >+ <div className="MCPHowItWorks__stage">+ <Stage mode={mode} preview={preview} />+ </div>+ </div>+ ))}+ </div>+ </section>+ </div>+ )+}diff --git a/products/mcp_analytics/frontend/emptyState/MCPHowItWorksWrapStage.scss b/products/mcp_analytics/frontend/emptyState/MCPHowItWorksWrapStage.scssnew file mode 100644index 000000000000..e8d08a044526--- /dev/null+++ b/products/mcp_analytics/frontend/emptyState/MCPHowItWorksWrapStage.scss@@ -0,0 +1,171 @@+.MCPHowItWorks {+ &__ring {+ position: absolute;+ inset: 32px 28px 78px;+ display: grid;+ place-items: center;+ border: 2px dashed var(--mcp-how-blue);+ border-radius: 16px;+ opacity: 0;+ transition:+ opacity 0.6s ease 0.35s,+ transform 0.7s cubic-bezier(0.2, 0.8, 0.2, 1) 0.35s;+ transform: scale(1.14);+ }++ &__diagram:is([data-phase='1'], [data-phase='2'], [data-phase='3']) &__ring {+ opacity: 1;+ transform: none;+ }++ &__diagram[data-phase='1'] &__ring {+ animation: MCPHowItWorks__zap 1.1s ease 1s 2;+ }++ &__ph-badge {+ position: absolute;+ top: -17px;+ left: 16px;+ display: grid;+ place-items: center;+ width: 32px;+ height: 32px;+ font-size: 19px;+ color: var(--color-white);+ background: var(--mcp-how-blue);+ border: 3px solid var(--mcp-how-card);+ border-radius: 50%;+ }++ &__server {+ position: relative;+ display: flex;+ flex-direction: column;+ gap: 9px;+ width: 72%;+ padding: 12px;+ background: var(--mcp-how-surface);+ border: 1.5px solid var(--mcp-how-border);+ border-radius: 10px;+ }++ &__server-top {+ display: flex;+ gap: 8px;+ align-items: center;+ font-size: 14px;+ font-weight: 700;++ svg {+ font-size: 20px;+ }+ }++ &__tool {+ display: flex;+ gap: 8px;+ align-items: center;+ font-size: 14px;+ color: var(--mcp-how-muted);++ i {+ display: block;+ flex: 1;+ height: 7px;+ background: var(--mcp-how-border);+ border-radius: 4px;+ }++ &:nth-child(3) i {+ max-width: 70%;+ }++ &:nth-child(4) i {+ max-width: 48%;+ }+ }++ &__live {+ position: absolute;+ top: -12px;+ right: -12px;+ display: grid;+ place-items: center;+ width: 26px;+ height: 26px;+ font-size: 15px;+ color: var(--mcp-how-ink);+ background: var(--mcp-how-green);+ border: 3px solid var(--mcp-how-card);+ border-radius: 50%;+ }++ &__wiz {+ position: absolute;+ bottom: 14px;+ left: 50%;+ display: flex;+ gap: 8px;+ align-items: center;+ padding: 5px 5px 5px 11px;+ font-family: var(--mcp-how-mono);+ font-size: 11.5px;+ font-weight: 500;+ color: var(--mcp-how-text);+ white-space: nowrap;+ background: var(--mcp-how-surface);+ border: 1.5px solid var(--mcp-how-border);+ border-radius: 7px;+ box-shadow: 0 2px 0 var(--mcp-how-line);+ translate: -50% 0;+ }++ &__wiz-prompt {+ color: var(--mcp-how-muted);+ user-select: none;+ }++ &__wiz-cmd {+ user-select: all;+ }++ &__copy {+ display: grid;+ place-items: center;+ width: 26px;+ height: 26px;+ padding: 0;+ font-size: 15px;+ color: var(--mcp-how-text-secondary);+ appearance: none;+ cursor: pointer;+ background: var(--mcp-how-card);+ border: 0;+ border-radius: 5px;+ transition:+ background 0.2s ease,+ color 0.2s ease;++ &:hover {+ color: var(--mcp-how-text);+ background: var(--mcp-how-border);+ }++ &--done,+ &--done:hover {+ color: var(--mcp-how-ink);+ background: var(--mcp-how-green);+ }+ }+}++@keyframes MCPHowItWorks__zap {+ 0%,+ 100% {+ box-shadow: 0 0 0 0 transparent;+ }++ 50% {+ box-shadow: 0 0 0 6px color-mix(in oklab, var(--mcp-how-blue) 24%, transparent);+ }+}diff --git a/products/mcp_analytics/frontend/emptyState/MCPHowItWorksWrapStage.tsx b/products/mcp_analytics/frontend/emptyState/MCPHowItWorksWrapStage.tsxnew file mode 100644index 000000000000..a75eb3144e46--- /dev/null+++ b/products/mcp_analytics/frontend/emptyState/MCPHowItWorksWrapStage.tsx@@ -0,0 +1,80 @@+import './MCPHowItWorksWrapStage.scss'++import { useActions } from 'kea'+import { useState } from 'react'++import { IconCheck, IconCopy, IconLogomark, IconMCP, IconWrench } from '@posthog/icons'++import { condenseCommand } from 'lib/components/CommandBlock/CommandBlock'+import { productSetupStatusLogic } from 'lib/components/ProductEmptyState/productSetupStatusLogic'+import type { ProductEmptyStateMode } from 'lib/components/ProductEmptyState/types'+import { copyToClipboard } from 'lib/utils/copyToClipboard'+import { cn } from 'lib/utils/css-classes'++import { ProductKey } from '~/queries/schema/schema-general'++import { useMCPAnalyticsWizardCommand } from '../onboarding/MCPAnalyticsInstall'++const COPIED_MS = 1600++export function MCPHowItWorksWrapStage({+ mode,+ preview,+}: {+ mode: ProductEmptyStateMode+ preview: boolean+}): JSX.Element {+ const [copied, setCopied] = useState(false)+ const { command, isCloudOrDev } = useMCPAnalyticsWizardCommand()+ const { reportSetupInteraction } = useActions(productSetupStatusLogic({ productKey: ProductKey.MCP_ANALYTICS }))++ const copyCommand = (): void => {+ void copyToClipboard(command, 'MCP analytics wizard command').then((ok) => {+ if (ok) {+ reportSetupInteraction('wizard command copied', mode, 'wizard', preview)+ setCopied(true)+ window.setTimeout(() => setCopied(false), COPIED_MS)+ }+ })+ }++ return (+ <>+ <div className="MCPHowItWorks__ring">+ <span className="MCPHowItWorks__ph-badge MCPHowItWorks__rv [--d:0.7s]">+ <IconLogomark />+ </span>+ <div className="MCPHowItWorks__server MCPHowItWorks__rv [--d:0.2s]">+ <div className="MCPHowItWorks__server-top">+ <IconMCP />+ MCP server+ </div>+ {[0, 1, 2].map((tool) => (+ <div key={tool} className="MCPHowItWorks__tool">+ <IconWrench />+ <i />+ </div>+ ))}+ <span className="MCPHowItWorks__live MCPHowItWorks__rv [--d:1.5s]">+ <IconCheck />+ </span>+ </div>+ </div>+ <div className="MCPHowItWorks__wiz MCPHowItWorks__rv [--d:1s]">+ <span className="MCPHowItWorks__wiz-prompt">$</span>+ <span className="MCPHowItWorks__wiz-cmd">{condenseCommand(command)}</span>+ {isCloudOrDev ? (+ <button+ type="button"+ className={cn('MCPHowItWorks__copy', copied && 'MCPHowItWorks__copy--done')}+ aria-label="Copy command"+ onClick={copyCommand}+ data-attr="mcp-analytics-how-it-works-copy-wizard"+ >+ {copied ? <IconCheck /> : <IconCopy />}+ </button>+ ) : null}+ </div>+ </>+ )+}