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.

4.0 KB
Raw Blame
import { Link } from '@posthog/lemon-ui'

import { LemonTable, LemonTableColumns } from 'lib/lemon-ui/LemonTable'
import { urls } from 'scenes/urls'

import type { HealthIssue } from '../types'
import { issueActionsColumn, severityColumn } from './healthTableColumns'

interface CheckMeta {
    title: string
    description: string
    docsUrl?: string
    linkLabel?: string
}

const CHECK_META: Record<string, CheckMeta> = {
    no_live_events: {
        title: '$pageview',
        description: 'No pageview events detected recently. Complete the PostHog installation to start seeing events.',
        docsUrl: 'https://posthog.com/docs/product-analytics/capture-events',
    },
    no_pageleave_events: {
        title: '$pageleave',
        description: 'Without $pageleave events, bounce rate and session duration might be inaccurate.',
        docsUrl: 'https://posthog.com/docs/web-analytics/dashboard#bounce-rate',
    },
    scroll_depth: {
        title: 'Scroll depth',
        description: 'Enable scroll depth to see how far users read your content before leaving.',
        docsUrl: 'https://posthog.com/tutorials/scroll-depth',
    },
    authorized_urls: {
        title: 'Authorized URLs',
        description: "No authorized URLs configured. Some filters won't work correctly until you set your domains.",
        docsUrl: urls.settings('environment-web-analytics', 'web-analytics-authorized-urls'),
        linkLabel: 'Settings',
    },
    reverse_proxy: {
        title: 'Reverse proxy',
        description:
            'A reverse proxy routes requests through your domain and helps prevent ad blockers from blocking tracking.',
        docsUrl: 'https://posthog.com/docs/advanced/proxy',
    },
    web_vitals: {
        title: '$web_vitals',
        description:
            'Core Web Vitals (LCP, INP, CLS) measure real user experience. Google uses these metrics for search ranking.',
        docsUrl: 'https://posthog.com/docs/web-analytics/web-vitals',
    },
    path_cleaning_suggestions: {
        title: 'Path cleaning',
        description:
            'AI-suggested path cleaning rules are ready to review. Applying them groups similar pages (like /users/123 and /users/456) in your breakdowns.',
        docsUrl: urls.settings('environment-product-analytics', 'path-cleaning'),
        linkLabel: 'Review suggestions',
    },
}

export function WebAnalyticsHealthTable({
    issues,
    onSnooze,
    onDismiss,
    onUndismiss,
}: {
    issues: HealthIssue[]
    onSnooze: (id: string, duration: string) => void
    onDismiss: (id: string) => void
    onUndismiss: (id: string) => void
}): JSX.Element {
    const columns: LemonTableColumns<HealthIssue> = [
        {
            title: 'Check',
            key: 'check',
            render: function Render(_, issue: HealthIssue) {
                const meta = CHECK_META[issue.kind]

                return (
                    <div className="py-1">
                        <div className="flex items-center gap-2">
                            {meta?.title.startsWith('$') ? (
                                <code className="font-medium text-sm bg-fill-primary px-1.5 py-0.5 rounded">
                                    {meta.title}
                                </code>
                            ) : (
                                <span className="font-medium">{meta?.title ?? issue.kind}</span>
                            )}
                            {meta?.docsUrl && (
                                <Link to={meta.docsUrl} className="text-xs text-muted">
                                    {meta.linkLabel ?? 'Docs'}
                                </Link>
                            )}
                        </div>
                        {meta?.description && <div className="text-xs text-muted mt-0.5">{meta.description}</div>}
                    </div>
                )
            },
        },
        severityColumn(),
        issueActionsColumn(onSnooze, onDismiss, onUndismiss),
    ]

    return <LemonTable dataSource={issues} columns={columns} embedded size="small" rowClassName="group" />
}