filtering-bot-traffic

Identify, measure, and exclude bot and AI-agent traffic in PostHog analytics using HogQL functions and virtual properties.

713|118|Updated Aug 11, 2020
One-click install
npx skills add https://github.com/PostHog/posthog-foss --skill filtering-bot-traffic
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: filtering-bot-traffic
Source: https://github.com/PostHog/posthog-foss/tree/main/products/web_analytics/skills/filtering-bot-traffic
Command: npx skills add https://github.com/PostHog/posthog-foss --skill filtering-bot-traffic

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Bot, crawler, and AI-agent traffic inflates pageview and visitor counts, making product and web analytics unreliable. This Skill shows how to classify every request by user agent in PostHog so you can exclude automated traffic, measure how much of your traffic is non-human, and identify which bots and AI tools are hitting your site.

Core Features & Use Cases

  • Human-only analytics: Add a $virt_is_bot = false filter to any insight, trend, or funnel so visitor, session, and pageview counts reflect real users only.
  • Bot traffic measurement: Break down pageview trends by $virt_traffic_type, $virt_bot_name, or $virt_bot_operator to quantify automated traffic and see which crawlers (Googlebot, GPTBot, ClaudeBot) visit your site.
  • AI-agent visibility: Filter for the AI Agent traffic type to measure how AI search and assistant tools read your content, supporting AEO and answer-engine analysis.
  • Use Case: A content team notices a traffic spike and wants to know if it is real. Break down the last 30 days of pageviews by $virt_traffic_type to reveal that 40% came from AI crawlers, then filter them out of the growth dashboard.

Quick Start

Ask the agent to show what percentage of my pageviews in the last 30 days came from bots versus humans, broken down by traffic type.

Frequently Asked Questions about filtering-bot-traffic

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I exclude bot traffic from PostHog analytics?

Add an event property filter with key $virt_is_bot, operator exact, and value false to any TrendsQuery, FunnelsQuery, or insight. Visitor, session, and pageview counts then reflect human traffic only without changing stored data.

How do I measure how much of my traffic is bots or AI crawlers?

Break a pageview trend down by the $virt_traffic_type property to split traffic into Regular, AI Agent, Bot, and Automation buckets. To see which specific bots visit, filter $virt_is_bot to true and break down by $virt_bot_name or $virt_bot_operator.

What is the difference between $virt_is_bot and the isLikelyBot HogQL function?

Both use the same user-agent classification. Virtual properties like $virt_is_bot read the user agent automatically and work in the insight builder and filters, while isLikelyBot(ua) takes an explicit user agent argument for hand-written SQL queries.

Why don't I see GPTBot or other crawlers in my PostHog data?

Most crawlers and AI agents never execute JavaScript, so posthog-js never captures a $pageview for them. You need server-side capture that forwards access logs as $http_log events with $raw_user_agent, via the Vercel logs source, an edge worker, or the capture API.

Does bot detection in PostHog work on historical events?

Yes, classification is computed at query time from the event's $raw_user_agent or $user_agent, so it works on any historical event that captured a user agent. Events without a user agent classify as Automation with category no_user_agent.

Is PostHog bot detection accurate enough to trust for filtering?

Detection is a user-agent heuristic, so treat it as best-effort rather than ground truth. Some bots spoof real browser user agents and some legitimate tools use bot-like ones, and the detected-bot list evolves over time.