用途:在 PostHog 的 Web 与产品分析中识别、度量并排除机器人、爬虫和 AI 智能体流量,让指标只反映人类访问,同时单独衡量自动化流量。适用于历史窗口、已保存洞察、仪表盘和过滤;实时(最近 30 分钟)与 Live 标签请用 exploring-live-traffic 技能。
主要能力:PostHog 在查询时按 user agent 分类每个请求。虚拟属性可直接在洞察构建器、过滤器和细分中使用:$virt_is_bot(布尔)、$virt_traffic_type(Regular、AI Agent、Bot、Automation)、$virt_traffic_category(如 ai_crawler、ai_search、search_crawler、monitoring、headless_browser、no_user_agent 等)、$virt_bot_name、$virt_bot_operator。HogQL 函数需显式传入 UA:isLikelyBot、getTrafficType、getTrafficCategory、getBotType、getBotName、getBotOperator。建议用 coalesce(nullIf(properties.$raw_user_agent, ''), properties.$user_agent) 同时覆盖服务端与 JS SDK 采集。
使用方式:排除机器人可在任意 TrendsQuery/FunnelsQuery 的 properties 中加 {"key":"$virt_is_bot","value":["false"],"operator":"exact","type":"event"};按 $virt_traffic_type 细分可看自动化占比;按 $virt_bot_name 或 $virt_bot_operator 细分可看哪些机器人或公司访问;过滤 $virt_traffic_type exact AI Agent 可专门度量 AI 智能体流量。原始 SQL 可用 NOT isLikelyBot(...) 统计人类浏览量,或按 getBotName/getBotOperator 分组统计。
自定义规则:内置列表只覆盖已知的自声明 UA。可通过 Settings → Environment → Custom bots、MCP 工具(web-analytics-bot-rules-list/create/destroy)或 REST API(/api/projects/{project_id}/web_analytics_bot_rules/)添加规则。规则匹配一个事件属性(默认 UA,也支持 $ip、$lib、$host、$pathname、$current_url、$browser、$os、$geoip_country_code、$referrer 等),使用 contains、regex(RE2)或 cidr(仅 $ip)。创建和删除需项目管理员。
限制:分类依赖已采集的 user agent,未采集 UA 的事件无法分类,空 UA 归为 Automation/no_user_agent 且 isLikelyBot 返回 true。检测是基于 UA 的启发式,属于尽力而为,可能被伪造或误判。不执行 JS 的爬虫不会触发 $pageview,需通过服务端访问日志以 $http_log 事件携带 $raw_user_agent 才能度量。若用户限定单一域名,需继承 $host 过滤。机器人定义会随时间变化,同一查询日后可能得到不同分类结果。