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.

fix(hogql): don't count missing user agent as bot on server and mobile SDK events (#119634)

posthog[bot]24d9398853b6
diff --git a/posthog/hogql/functions/test/test_traffic_type_functions.py b/posthog/hogql/functions/test/test_traffic_type_functions.py
index 7fa7cc420a2f..801b00c68e5b 100644
--- a/posthog/hogql/functions/test/test_traffic_type_functions.py
+++ b/posthog/hogql/functions/test/test_traffic_type_functions.py
@@ -1051,6 +1051,95 @@ class TestCookielessClassification(ClickhouseTestMixin, BaseTest):
)
+class TestServerAndMobileSdkClassification(ClickhouseTestMixin, BaseTest):
+ def _classify(self, properties: dict, definitions: list[CustomBotRule] | None = None) -> tuple:
+ if definitions:
+ self.team.modifiers = {"customBotDefinitions": [d.model_dump(mode="json") for d in definitions]}
+ self.team.save()
+
+ tag = uuid4().hex
+ _create_event(
+ team=self.team,
+ distinct_id="visitor",
+ event="signed_up",
+ properties={**properties, "_test_tag": tag},
+ )
+ flush_persons_and_events()
+
+ response = execute_hogql_query(
+ "SELECT `$virt_is_bot`, `$virt_traffic_type`, `$virt_traffic_category`, `$virt_bot_name`, "
+ "`$virt_bot_operator`, getBotType(properties.`$raw_user_agent`, properties.`$ip`) "
+ f"FROM events WHERE properties._test_tag = '{tag}'",
+ self.team,
+ )
+ assert response.results is not None
+ return response.results[0]
+
+ @parameterized.expand(
+ [
+ ("node", "posthog-node", {}),
+ ("python_empty_user_agent", "posthog-python", {"$raw_user_agent": ""}),
+ ("react_native", "posthog-react-native", {}),
+ ("ios", "posthog-ios", {}),
+ ]
+ )
+ def test_a_server_or_mobile_event_with_no_user_agent_is_regular(self, _name: str, lib: str, properties: dict):
+ assert self._classify({"$lib": lib, **properties}) == (False, "Regular", "regular", "", "", "")
+
+ def test_a_server_event_with_no_user_agent_is_regular_with_cookieless_on(self) -> None:
+ # The cloud default: the cookieless and SDK reasons are combined.
+ self.team.modifiers = {"cookielessTrafficIsRegular": True}
+ self.team.save()
+ assert self._classify({"$lib": "posthog-node"}) == (False, "Regular", "regular", "", "", "")
+
+ @parameterized.expand([("web", {"$lib": "web"}), ("no_lib", {}), ("unknown_lib", {"$lib": "curl"})])
+ def test_other_events_with_no_user_agent_are_still_automation(self, _name: str, properties: dict) -> None:
+ assert self._classify(properties) == (True, "Automation", "no_user_agent", "", "", "no_user_agent")
+
+ @parameterized.expand(
+ [
+ ("user_agent", {"$raw_user_agent": "Googlebot/2.1"}, False),
+ ("ip", {"$ip": "66.249.66.1"}, False),
+ ("user_agent_with_project_rules", {"$raw_user_agent": "Googlebot/2.1"}, True),
+ ("ip_with_project_rules", {"$ip": "66.249.66.1"}, True),
+ ]
+ )
+ def test_positive_bot_signals_still_classify_server_events(
+ self, _name: str, properties: dict, with_project_rules: bool
+ ) -> None:
+ definitions = (
+ [_custom_bot(name="Staging checker", key=CustomBotField.FIELD_HOST, pattern="staging")]
+ if with_project_rules
+ else None
+ )
+ assert self._classify({"$lib": "posthog-node", **properties}, definitions=definitions) == (
+ True,
+ "Bot",
+ "search_crawler",
+ "Googlebot",
+ "Google",
+ "search_crawler",
+ )
+
+ def test_a_project_rule_still_names_a_server_event(self):
+ is_bot, traffic_type, category, name, _operator, bot_type = self._classify(
+ {"$lib": "posthog-node", "$host": "staging.example.com"},
+ definitions=[
+ _custom_bot(
+ name="Staging checker", key=CustomBotField.FIELD_HOST, pattern="staging", category="monitoring"
+ )
+ ],
+ )
+
+ assert (is_bot, traffic_type, category, name, bot_type) == (
+ True,
+ "Bot",
+ "monitoring",
+ "Staging checker",
+ "monitoring",
+ )
+
+
COOKIELESS_ON = HogQLQueryModifiers(cookielessTrafficIsRegular=True)
diff --git a/posthog/hogql/functions/traffic_type.py b/posthog/hogql/functions/traffic_type.py
index 1ba832265ffe..c5630c45b83f 100644
--- a/posthog/hogql/functions/traffic_type.py
+++ b/posthog/hogql/functions/traffic_type.py
@@ -29,7 +29,7 @@ from posthog.hogql import ast
from posthog.dataclasses import frozen
-from products.web_analytics.backend.hogql_queries.bot_definitions import BOT_DEFINITIONS
+from products.web_analytics.backend.hogql_queries.bot_definitions import BOT_DEFINITIONS, SERVER_AND_MOBILE_SDK_LIBS
from products.web_analytics.backend.hogql_queries.bot_ip_definitions import (
BOT_IP_DEFINITIONS,
bot_ip_prefix_groups_by_definition,
@@ -52,6 +52,7 @@ if TYPE_CHECKING:
COOKIELESS_MODE_FIELD = "$cookieless_mode"
+LIB_FIELD = "$lib"
def _custom_groups(modifiers: Optional["HogQLQueryModifiers"]) -> list[CustomBotGroup]:
@@ -104,25 +105,44 @@ def _property_expr(key: str, args: list[ast.Expr]) -> Optional[ast.Expr]:
return None
-def _cookieless_missing_user_agent(
+def _string_property(property_expr: ast.Expr) -> ast.Expr:
+ return ast.Call(name="ifNull", args=[ast.Call(name="toString", args=[property_expr]), ast.Constant(value="")])
+
+
+def _expected_missing_user_agent(
args: list[ast.Expr], modifiers: Optional["HogQLQueryModifiers"]
) -> Optional[ast.Expr]:
- if modifiers is None or not modifiers.cookielessTrafficIsRegular:
- return None
- cookieless_expr = _property_expr(COOKIELESS_MODE_FIELD, args)
- if cookieless_expr is None:
+ """Match events whose user agent is missing for a known reason, so the empty-user-agent rule
+ does not count them as automation. Positive bot signals and project rules still apply.
+
+ Two reasons are known: a cookieless event (when the modifier is on), and an event from a server
+ or mobile SDK, which sends no user agent unless the app forwards one.
+ """
+ reasons: list[ast.Expr] = []
+ if modifiers is not None and modifiers.cookielessTrafficIsRegular:
+ cookieless_expr = _property_expr(COOKIELESS_MODE_FIELD, args)
+ if cookieless_expr is not None:
+ reasons.append(
+ ast.CompareOperation(
+ op=ast.CompareOperationOp.Eq,
+ left=_string_property(cookieless_expr),
+ right=ast.Constant(value="true"),
+ )
+ )
+ lib_expr = _property_expr(LIB_FIELD, args)
+ if lib_expr is not None:
+ reasons.append(
+ ast.CompareOperation(
+ op=ast.CompareOperationOp.In,
+ left=_string_property(lib_expr),
+ right=ast.Tuple(exprs=[ast.Constant(value=lib) for lib in SERVER_AND_MOBILE_SDK_LIBS]),
+ )
+ )
+ if not reasons:
return None
- cookieless = ast.CompareOperation(
- op=ast.CompareOperationOp.Eq,
- left=ast.Call(
- name="ifNull",
- args=[ast.Call(name="toString", args=[cookieless_expr]), ast.Constant(value="")],
- ),
- right=ast.Constant(value="true"),
- )
return ast.And(
exprs=[
- cookieless,
+ reasons[0] if len(reasons) == 1 else ast.Or(exprs=reasons),
ast.CompareOperation(
op=ast.CompareOperationOp.Eq,
left=ast.Call(name="ifNull", args=[args[0], ast.Constant(value="")]),
@@ -312,7 +332,7 @@ def _build_bot_array_lookup(
builtin_labels = [getattr(bot_def, attr) for bot_def in BOT_DEFINITIONS.values()]
groups = _custom_groups(modifiers)
- cookieless = _cookieless_missing_user_agent(args, modifiers)
+ expected_missing = _expected_missing_user_agent(args, modifiers)
if not groups:
# No project rules: one pass over the built-in patterns plus the empty-user-agent sentinel.
@@ -327,12 +347,12 @@ def _build_bot_array_lookup(
ast.ArrayAccess(array=labels_array, property=index_call, nullish=False),
],
)
- if cookieless is None:
+ if expected_missing is None:
return lookup
- return ast.Call(name="if", args=[cookieless, fallback, lookup])
+ return ast.Call(name="if", args=[expected_missing, fallback, lookup])
# With project rules the checks become an ordered chain, in this order: the project's own
- # rules, then the cookieless missing-UA fallback, then the built-ins, then the empty user
+ # rules, then the expected missing-UA fallback, then the built-ins, then the empty user
# agent, then the built-in IP ranges. A rule someone wrote by hand says more about what
# they want counted than a default we shipped, so a matching project rule always wins.
#
@@ -344,8 +364,8 @@ def _build_bot_array_lookup(
branch = _custom_group_branch(group, args, attr)
if branch is not None:
branches.extend([branch.matched, branch.label])
- if cookieless is not None:
- branches.extend([cookieless, fallback])
+ if expected_missing is not None:
+ branches.extend([expected_missing, fallback])
builtin_index = ast.Call(
name="multiMatchAnyIndex", args=[safe_user_agent, _string_array(list(BOT_DEFINITIONS.keys()))]
)
@@ -421,8 +441,9 @@ def is_bot(node: ast.Call, args: list[ast.Expr], modifiers: Optional["HogQLQuery
HogQL function: isLikelyBot(user_agent[, ip])
Returns true if the user agent matches bot/automation patterns, or (when given) the
- client IP falls in a known bot IP range. NULL user agents are treated as bots
- (empty UA is considered automation).
+ client IP falls in a known bot IP range. NULL or empty user agents count as automation,
+ except on events from server and mobile SDKs (and cookieless events when that modifier is
+ on), where a missing user agent is expected.
Uses multiMatchAnyIndex for efficient single-pass matching (same as get_traffic_type etc.);
the IP check is a handful of hash-set lookups and only evaluates for rows the UA check
@@ -439,9 +460,9 @@ def is_bot(node: ast.Call, args: list[ast.Expr], modifiers: Optional["HogQLQuery
index_call = ast.Call(name="multiMatchAnyIndex", args=[safe_user_agent, patterns_array])
builtin_matched: ast.Expr = _matched(index_call)
- cookieless = _cookieless_missing_user_agent(args, modifiers)
- if cookieless is not None:
- builtin_matched = ast.And(exprs=[ast.Not(expr=cookieless), builtin_matched])
+ expected_missing = _expected_missing_user_agent(args, modifiers)
+ if expected_missing is not None:
+ builtin_matched = ast.And(exprs=[ast.Not(expr=expected_missing), builtin_matched])
conditions: list[ast.Expr] = [builtin_matched]
for group in _custom_groups(modifiers):
diff --git a/products/web_analytics/backend/hogql_queries/bot_definitions.py b/products/web_analytics/backend/hogql_queries/bot_definitions.py
index cde400581ce8..b86f1b392f25 100644
--- a/products/web_analytics/backend/hogql_queries/bot_definitions.py
+++ b/products/web_analytics/backend/hogql_queries/bot_definitions.py
@@ -1018,3 +1018,33 @@ BOT_DEFINITIONS: dict[str, BotDefinition] = {
documentation_url="https://posthog.com/docs/ai-research/image-fetcher-bot",
),
}
+
+
+# $lib values of SDKs that run on a server or in a native app. They send no user agent unless the app
+# forwards one, so on their events a missing user agent is not a sign of automation. Browser SDKs
+# ("web", "js") are left out on purpose. Keep in step with sdk_metrics in posthog/tasks/usage_report.py.
+SERVER_AND_MOBILE_SDK_LIBS: tuple[str, ...] = (
+ "posthog-node",
+ "posthog-node-mcp",
+ "posthog-edge",
+ "posthog-convex",
+ "posthog-python",
+ "posthog-python-mcp",
+ "posthog-ruby",
+ "posthog-rails",
+ "posthog-go",
+ "posthog-php",
+ "posthog-java",
+ "posthog-server",
+ "posthog-dotnet",
+ "posthog-aspnetcore",
+ "posthog-elixir",
+ "posthog-rs",
+ "posthog-roblox",
+ "posthog-ios",
+ "posthog-android",
+ "posthog-react-native",
+ "posthog-flutter",
+ "posthog-kmp",
+ "posthog-unity",
+)
diff --git a/products/web_analytics/backend/hogql_queries/test/__snapshots__/test_web_bots.ambr b/products/web_analytics/backend/hogql_queries/test/__snapshots__/test_web_bots.ambr
index f8fa95f63456..668e9539de54 100644
--- a/products/web_analytics/backend/hogql_queries/test/__snapshots__/test_web_bots.ambr
+++ b/products/web_analytics/backend/hogql_queries/test/__snapshots__/test_web_bots.ambr
@@ -1,12 +1,12 @@
# serializer version: 1
# name: TestWebBotsTableQueryRunner.test_date_range_excludes_outside_events
'''
- SELECT if(ifNull(equals(multiMatchAnyIndex(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$raw_user_agent'), ''), 'null'), '^"|"$', ''), ''), [/* 344 bot literals */]), 0), 0), if(equals(multiIf(or(/* bot ip ranges */), 1, or(/* bot ip ranges */), 2, or(/* bot ip ranges */), 3, or(/* bot ip ranges */), 4, or(/* bot ip ranges */), 5, or(/* bot ip ranges */), 6, or(/* bot ip ranges */), 7, or(/* bot ip ranges */), 8, or(/* bot ip ranges */), 9, or(/* bot ip ranges */), 10, or(/* bot ip ranges */), 11, 0), 0), '', ['Googlebot', 'Google special crawler', 'Google fetcher', 'ChatGPT', 'OpenAI Search', 'GPTBot', 'Perplexity User', 'Perplexity', 'Bingbot', 'Applebot', 'Ahrefs'][multiIf(or(/* bot ip ranges */), 1, or(/* bot ip ranges */), 2, or(/* bot ip ranges */), 3, or(/* bot ip ranges */), 4, or(/* bot ip ranges */), 5, or(/* bot ip ranges */), 6, or(/* bot ip ranges */), 7, or(/* bot ip ranges */), 8, or(/* bot ip ranges */), 9, or(/* bot ip ranges */), 10, or(/* bot ip ranges */), 11, 0)]), [/* 344 bot literals */][multiMatchAnyIndex(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$raw_user_agent'), ''), 'null'), '^"|"$', ''), ''), [/* 344 bot literals */])]) AS Crawler,
- if(ifNull(equals(multiMatchAnyIndex(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$raw_user_agent'), ''), 'null'), '^"|"$', ''), ''), [/* 344 bot literals */]), 0), 0), if(equals(multiIf(or(/* bot ip ranges */), 1, or(/* bot ip ranges */), 2, or(/* bot ip ranges */), 3, or(/* bot ip ranges */), 4, or(/* bot ip ranges */), 5, or(/* bot ip ranges */), 6, or(/* bot ip ranges */), 7, or(/* bot ip ranges */), 8, or(/* bot ip ranges */), 9, or(/* bot ip ranges */), 10, or(/* bot ip ranges */), 11, 0), 0), 'regular', ['search_crawler', 'search_crawler', 'search_crawler', 'ai_assistant', 'ai_search', 'ai_crawler', 'ai_assistant', 'ai_search', 'search_crawler', 'ai_search', 'seo_crawler'][multiIf(or(/* bot ip ranges */), 1, or(/* bot ip ranges */), 2, or(/* bot ip ranges */), 3, or(/* bot ip ranges */), 4, or(/* bot ip ranges */), 5, or(/* bot ip ranges */), 6, or(/* bot ip ranges */), 7, or(/* bot ip ranges */), 8, or(/* bot ip ranges */), 9, or(/* bot ip ranges */), 10, or(/* bot ip ranges */), 11, 0)]), [/* 344 bot literals */][multiMatchAnyIndex(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$raw_user_agent'), ''), 'null'), '^"|"$', ''), ''), [/* 344 bot literals */])]) AS Category,
+ SELECT if(and(in(ifNull(toString(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$lib'), ''), 'null'), '^"|"$', '')), ''), tuple('posthog-node', 'posthog-node-mcp', 'posthog-edge', 'posthog-convex', 'posthog-python', 'posthog-python-mcp', 'posthog-ruby', 'posthog-rails', 'posthog-go', 'posthog-php', 'posthog-java', 'posthog-server', 'posthog-dotnet', 'posthog-aspnetcore', 'posthog-elixir', 'posthog-rs', 'posthog-roblox', 'posthog-ios', 'posthog-android', 'posthog-react-native', 'posthog-flutter', 'posthog-kmp', 'posthog-unity')), ifNull(equals(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$raw_user_agent'), ''), 'null'), '^"|"$', ''), ''), ''), 0)), if(equals(multiIf(or(/* bot ip ranges */), 1, or(/* bot ip ranges */), 2, or(/* bot ip ranges */), 3, or(/* bot ip ranges */), 4, or(/* bot ip ranges */), 5, or(/* bot ip ranges */), 6, or(/* bot ip ranges */), 7, or(/* bot ip ranges */), 8, or(/* bot ip ranges */), 9, or(/* bot ip ranges */), 10, or(/* bot ip ranges */), 11, 0), 0), '', ['Googlebot', 'Google special crawler', 'Google fetcher', 'ChatGPT', 'OpenAI Search', 'GPTBot', 'Perplexity User', 'Perplexity', 'Bingbot', 'Applebot', 'Ahrefs'][multiIf(or(/* bot ip ranges */), 1, or(/* bot ip ranges */), 2, or(/* bot ip ranges */), 3, or(/* bot ip ranges */), 4, or(/* bot ip ranges */), 5, or(/* bot ip ranges */), 6, or(/* bot ip ranges */), 7, or(/* bot ip ranges */), 8, or(/* bot ip ranges */), 9, or(/* bot ip ranges */), 10, or(/* bot ip ranges */), 11, 0)]), if(ifNull(equals(multiMatchAnyIndex(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$raw_user_agent'), ''), 'null'), '^"|"$', ''), ''), [/* 344 bot literals */]), 0), 0), if(equals(multiIf(or(/* bot ip ranges */), 1, or(/* bot ip ranges */), 2, or(/* bot ip ranges */), 3, or(/* bot ip ranges */), 4, or(/* bot ip ranges */), 5, or(/* bot ip ranges */), 6, or(/* bot ip ranges */), 7, or(/* bot ip ranges */), 8, or(/* bot ip ranges */), 9, or(/* bot ip ranges */), 10, or(/* bot ip ranges */), 11, 0), 0), '', ['Googlebot', 'Google special crawler', 'Google fetcher', 'ChatGPT', 'OpenAI Search', 'GPTBot', 'Perplexity User', 'Perplexity', 'Bingbot', 'Applebot', 'Ahrefs'][multiIf(or(/* bot ip ranges */), 1, or(/* bot ip ranges */), 2, or(/* bot ip ranges */), 3, or(/* bot ip ranges */), 4, or(/* bot ip ranges */), 5, or(/* bot ip ranges */), 6, or(/* bot ip ranges */), 7, or(/* bot ip ranges */), 8, or(/* bot ip ranges */), 9, or(/* bot ip ranges */), 10, or(/* bot ip ranges */), 11, 0)]), [/* 344 bot literals */][multiMatchAnyIndex(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$raw_user_agent'), ''), 'null'), '^"|"$', ''), ''), [/* 344 bot literals */])])) AS Crawler,
+ if(and(in(ifNull(toString(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$lib'), ''), 'null'), '^"|"$', '')), ''), tuple('posthog-node', 'posthog-node-mcp', 'posthog-edge', 'posthog-convex', 'posthog-python', 'posthog-python-mcp', 'posthog-ruby', 'posthog-rails', 'posthog-go', 'posthog-php', 'posthog-java', 'posthog-server', 'posthog-dotnet', 'posthog-aspnetcore', 'posthog-elixir', 'posthog-rs', 'posthog-roblox', 'posthog-ios', 'posthog-android', 'posthog-react-native', 'posthog-flutter', 'posthog-kmp', 'posthog-unity')), ifNull(equals(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$raw_user_agent'), ''), 'null'), '^"|"$', ''), ''), ''), 0)), if(equals(multiIf(or(/* bot ip ranges */), 1, or(/* bot ip ranges */), 2, or(/* bot ip ranges */), 3, or(/* bot ip ranges */), 4, or(/* bot ip ranges */), 5, or(/* bot ip ranges */), 6, or(/* bot ip ranges */), 7, or(/* bot ip ranges */), 8, or(/* bot ip ranges */), 9, or(/* bot ip ranges */), 10, or(/* bot ip ranges */), 11, 0), 0), 'regular', ['search_crawler', 'search_crawler', 'search_crawler', 'ai_assistant', 'ai_search', 'ai_crawler', 'ai_assistant', 'ai_search', 'search_crawler', 'ai_search', 'seo_crawler'][multiIf(or(/* bot ip ranges */), 1, or(/* bot ip ranges */), 2, or(/* bot ip ranges */), 3, or(/* bot ip ranges */), 4, or(/* bot ip ranges */), 5, or(/* bot ip ranges */), 6, or(/* bot ip ranges */), 7, or(/* bot ip ranges */), 8, or(/* bot ip ranges */), 9, or(/* bot ip ranges */), 10, or(/* bot ip ranges */), 11, 0)]), if(ifNull(equals(multiMatchAnyIndex(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$raw_user_agent'), ''), 'null'), '^"|"$', ''), ''), [/* 344 bot literals */]), 0), 0), if(equals(multiIf(or(/* bot ip ranges */), 1, or(/* bot ip ranges */), 2, or(/* bot ip ranges */), 3, or(/* bot ip ranges */), 4, or(/* bot ip ranges */), 5, or(/* bot ip ranges */), 6, or(/* bot ip ranges */), 7, or(/* bot ip ranges */), 8, or(/* bot ip ranges */), 9, or(/* bot ip ranges */), 10, or(/* bot ip ranges */), 11, 0), 0), 'regular', ['search_crawler', 'search_crawler', 'search_crawler', 'ai_assistant', 'ai_search', 'ai_crawler', 'ai_assistant', 'ai_search', 'search_crawler', 'ai_search', 'seo_crawler'][multiIf(or(/* bot ip ranges */), 1, or(/* bot ip ranges */), 2, or(/* bot ip ranges */), 3, or(/* bot ip ranges */), 4, or(/* bot ip ranges */), 5, or(/* bot ip ranges */), 6, or(/* bot ip ranges */), 7, or(/* bot ip ranges */), 8, or(/* bot ip ranges */), 9, or(/* bot ip ranges */), 10, or(/* bot ip ranges */), 11, 0)]), [/* 344 bot literals */][multiMatchAnyIndex(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$raw_user_agent'), ''), 'null'), '^"|"$', ''), ''), [/* 344 bot literals */])])) AS Category,
count() AS Requests,
max(toTimeZone(events.timestamp, 'UTC')) AS `Last seen`
FROM events
- WHERE and(equals(events.team_id, 99999), and(ifNull(equals(accurateCastOrNull(or(ifNull(notEquals(multiMatchAnyIndex(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$raw_user_agent'), ''), 'null'), '^"|"$', ''), ''), [/* 344 bot literals */]), 0), 1), or(/* bot ip ranges */)), 'Bool'), 1), 0), notEquals(if(ifNull(equals(multiMatchAnyIndex(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$raw_user_agent'), ''), 'null'), '^"|"$', ''), ''), [/* 344 bot literals */]), 0), 0), if(equals(multiIf(or(/* bot ip ranges */), 1, or(/* bot ip ranges */), 2, or(/* bot ip ranges */), 3, or(/* bot ip ranges */), 4, or(/* bot ip ranges */), 5, or(/* bot ip ranges */), 6, or(/* bot ip ranges */), 7, or(/* bot ip ranges */), 8, or(/* bot ip ranges */), 9, or(/* bot ip ranges */), 10, or(/* bot ip ranges */), 11, 0), 0), '', ['Googlebot', 'Google special crawler', 'Google fetcher', 'ChatGPT', 'OpenAI Search', 'GPTBot', 'Perplexity User', 'Perplexity', 'Bingbot', 'Applebot', 'Ahrefs'][multiIf(or(/* bot ip ranges */), 1, or(/* bot ip ranges */), 2, or(/* bot ip ranges */), 3, or(/* bot ip ranges */), 4, or(/* bot ip ranges */), 5, or(/* bot ip ranges */), 6, or(/* bot ip ranges */), 7, or(/* bot ip ranges */), 8, or(/* bot ip ranges */), 9, or(/* bot ip ranges */), 10, or(/* bot ip ranges */), 11, 0)]), [/* 344 bot literals */][multiMatchAnyIndex(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$raw_user_agent'), ''), 'null'), '^"|"$', ''), ''), [/* 344 bot literals */])]), ''), in(events.event, tuple('$pageview', '$screen', '$http_log')), or(and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2026-03-01 00:00:00', 'UTC'))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2026-03-31 23:59:59', 'UTC')))), 0), 1))
+ WHERE and(equals(events.team_id, 99999), and(ifNull(equals(accurateCastOrNull(or(and(not(and(in(ifNull(toString(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$lib'), ''), 'null'), '^"|"$', '')), ''), tuple('posthog-node', 'posthog-node-mcp', 'posthog-edge', 'posthog-convex', 'posthog-python', 'posthog-python-mcp', 'posthog-ruby', 'posthog-rails', 'posthog-go', 'posthog-php', 'posthog-java', 'posthog-server', 'posthog-dotnet', 'posthog-aspnetcore', 'posthog-elixir', 'posthog-rs', 'posthog-roblox', 'posthog-ios', 'posthog-android', 'posthog-react-native', 'posthog-flutter', 'posthog-kmp', 'posthog-unity')), ifNull(equals(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$raw_user_agent'), ''), 'null'), '^"|"$', ''), ''), ''), 0))), ifNull(notEquals(multiMatchAnyIndex(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$raw_user_agent'), ''), 'null'), '^"|"$', ''), ''), [/* 344 bot literals */]), 0), 1)), or(/* bot ip ranges */)), 'Bool'), 1), 0), notEquals(if(and(in(ifNull(toString(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$lib'), ''), 'null'), '^"|"$', '')), ''), tuple('posthog-node', 'posthog-node-mcp', 'posthog-edge', 'posthog-convex', 'posthog-python', 'posthog-python-mcp', 'posthog-ruby', 'posthog-rails', 'posthog-go', 'posthog-php', 'posthog-java', 'posthog-server', 'posthog-dotnet', 'posthog-aspnetcore', 'posthog-elixir', 'posthog-rs', 'posthog-roblox', 'posthog-ios', 'posthog-android', 'posthog-react-native', 'posthog-flutter', 'posthog-kmp', 'posthog-unity')), ifNull(equals(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$raw_user_agent'), ''), 'null'), '^"|"$', ''), ''), ''), 0)), if(equals(multiIf(or(/* bot ip ranges */), 1, or(/* bot ip ranges */), 2, or(/* bot ip ranges */), 3, or(/* bot ip ranges */), 4, or(/* bot ip ranges */), 5, or(/* bot ip ranges */), 6, or(/* bot ip ranges */), 7, or(/* bot ip ranges */), 8, or(/* bot ip ranges */), 9, or(/* bot ip ranges */), 10, or(/* bot ip ranges */), 11, 0), 0), '', ['Googlebot', 'Google special crawler', 'Google fetcher', 'ChatGPT', 'OpenAI Search', 'GPTBot', 'Perplexity User', 'Perplexity', 'Bingbot', 'Applebot', 'Ahrefs'][multiIf(or(/* bot ip ranges */), 1, or(/* bot ip ranges */), 2, or(/* bot ip ranges */), 3, or(/* bot ip ranges */), 4, or(/* bot ip ranges */), 5, or(/* bot ip ranges */), 6, or(/* bot ip ranges */), 7, or(/* bot ip ranges */), 8, or(/* bot ip ranges */), 9, or(/* bot ip ranges */), 10, or(/* bot ip ranges */), 11, 0)]), if(ifNull(equals(multiMatchAnyIndex(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$raw_user_agent'), ''), 'null'), '^"|"$', ''), ''), [/* 344 bot literals */]), 0), 0), if(equals(multiIf(or(/* bot ip ranges */), 1, or(/* bot ip ranges */), 2, or(/* bot ip ranges */), 3, or(/* bot ip ranges */), 4, or(/* bot ip ranges */), 5, or(/* bot ip ranges */), 6, or(/* bot ip ranges */), 7, or(/* bot ip ranges */), 8, or(/* bot ip ranges */), 9, or(/* bot ip ranges */), 10, or(/* bot ip ranges */), 11, 0), 0), '', ['Googlebot', 'Google special crawler', 'Google fetcher', 'ChatGPT', 'OpenAI Search', 'GPTBot', 'Perplexity User', 'Perplexity', 'Bingbot', 'Applebot', 'Ahrefs'][multiIf(or(/* bot ip ranges */), 1, or(/* bot ip ranges */), 2, or(/* bot ip ranges */), 3, or(/* bot ip ranges */), 4, or(/* bot ip ranges */), 5, or(/* bot ip ranges */), 6, or(/* bot ip ranges */), 7, or(/* bot ip ranges */), 8, or(/* bot ip ranges */), 9, or(/* bot ip ranges */), 10, or(/* bot ip ranges */), 11, 0)]), [/* 344 bot literals */][multiMatchAnyIndex(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$raw_user_agent'), ''), 'null'), '^"|"$', ''), ''), [/* 344 bot literals */])])), ''), in(events.event, tuple('$pageview', '$screen', '$http_log')), or(and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2026-03-01 00:00:00', 'UTC'))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2026-03-31 23:59:59', 'UTC')))), 0), 1))
GROUP BY Crawler,
Category
ORDER BY Requests DESC
@@ -27,12 +27,12 @@
# ---
# name: TestWebBotsTableQueryRunner.test_only_bot_traffic_grouped_by_breakdown_0_Crawler
'''
- SELECT if(ifNull(equals(multiMatchAnyIndex(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$raw_user_agent'), ''), 'null'), '^"|"$', ''), ''), [/* 344 bot literals */]), 0), 0), if(equals(multiIf(or(/* bot ip ranges */), 1, or(/* bot ip ranges */), 2, or(/* bot ip ranges */), 3, or(/* bot ip ranges */), 4, or(/* bot ip ranges */), 5, or(/* bot ip ranges */), 6, or(/* bot ip ranges */), 7, or(/* bot ip ranges */), 8, or(/* bot ip ranges */), 9, or(/* bot ip ranges */), 10, or(/* bot ip ranges */), 11, 0), 0), '', ['Googlebot', 'Google special crawler', 'Google fetcher', 'ChatGPT', 'OpenAI Search', 'GPTBot', 'Perplexity User', 'Perplexity', 'Bingbot', 'Applebot', 'Ahrefs'][multiIf(or(/* bot ip ranges */), 1, or(/* bot ip ranges */), 2, or(/* bot ip ranges */), 3, or(/* bot ip ranges */), 4, or(/* bot ip ranges */), 5, or(/* bot ip ranges */), 6, or(/* bot ip ranges */), 7, or(/* bot ip ranges */), 8, or(/* bot ip ranges */), 9, or(/* bot ip ranges */), 10, or(/* bot ip ranges */), 11, 0)]), [/* 344 bot literals */][multiMatchAnyIndex(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$raw_user_agent'), ''), 'null'), '^"|"$', ''), ''), [/* 344 bot literals */])]) AS Crawler,
- if(ifNull(equals(multiMatchAnyIndex(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$raw_user_agent'), ''), 'null'), '^"|"$', ''), ''), [/* 344 bot literals */]), 0), 0), if(equals(multiIf(or(/* bot ip ranges */), 1, or(/* bot ip ranges */), 2, or(/* bot ip ranges */), 3, or(/* bot ip ranges */), 4, or(/* bot ip ranges */), 5, or(/* bot ip ranges */), 6, or(/* bot ip ranges */), 7, or(/* bot ip ranges */), 8, or(/* bot ip ranges */), 9, or(/* bot ip ranges */), 10, or(/* bot ip ranges */), 11, 0), 0), 'regular', ['search_crawler', 'search_crawler', 'search_crawler', 'ai_assistant', 'ai_search', 'ai_crawler', 'ai_assistant', 'ai_search', 'search_crawler', 'ai_search', 'seo_crawler'][multiIf(or(/* bot ip ranges */), 1, or(/* bot ip ranges */), 2, or(/* bot ip ranges */), 3, or(/* bot ip ranges */), 4, or(/* bot ip ranges */), 5, or(/* bot ip ranges */), 6, or(/* bot ip ranges */), 7, or(/* bot ip ranges */), 8, or(/* bot ip ranges */), 9, or(/* bot ip ranges */), 10, or(/* bot ip ranges */), 11, 0)]), [/* 344 bot literals */][multiMatchAnyIndex(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$raw_user_agent'), ''), 'null'), '^"|"$', ''), ''), [/* 344 bot literals */])]) AS Category,
+ SELECT if(and(in(ifNull(toString(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$lib'), ''), 'null'), '^"|"$', '')), ''), tuple('posthog-node', 'posthog-node-mcp', 'posthog-edge', 'posthog-convex', 'posthog-python', 'posthog-python-mcp', 'posthog-ruby', 'posthog-rails', 'posthog-go', 'posthog-php', 'posthog-java', 'posthog-server', 'posthog-dotnet', 'posthog-aspnetcore', 'posthog-elixir', 'posthog-rs', 'posthog-roblox', 'posthog-ios', 'posthog-android', 'posthog-react-native', 'posthog-flutter', 'posthog-kmp', 'posthog-unity')), ifNull(equals(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$raw_user_agent'), ''), 'null'), '^"|"$', ''), ''), ''), 0)), if(equals(multiIf(or(/* bot ip ranges */), 1, or(/* bot ip ranges */), 2, or(/* bot ip ranges */), 3, or(/* bot ip ranges */), 4, or(/* bot ip ranges */), 5, or(/* bot ip ranges */), 6, or(/* bot ip ranges */), 7, or(/* bot ip ranges */), 8, or(/* bot ip ranges */), 9, or(/* bot ip ranges */), 10, or(/* bot ip ranges */), 11, 0), 0), '', ['Googlebot', 'Google special crawler', 'Google fetcher', 'ChatGPT', 'OpenAI Search', 'GPTBot', 'Perplexity User', 'Perplexity', 'Bingbot', 'Applebot', 'Ahrefs'][multiIf(or(/* bot ip ranges */), 1, or(/* bot ip ranges */), 2, or(/* bot ip ranges */), 3, or(/* bot ip ranges */), 4, or(/* bot ip ranges */), 5, or(/* bot ip ranges */), 6, or(/* bot ip ranges */), 7, or(/* bot ip ranges */), 8, or(/* bot ip ranges */), 9, or(/* bot ip ranges */), 10, or(/* bot ip ranges */), 11, 0)]), if(ifNull(equals(multiMatchAnyIndex(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$raw_user_agent'), ''), 'null'), '^"|"$', ''), ''), [/* 344 bot literals */]), 0), 0), if(equals(multiIf(or(/* bot ip ranges */), 1, or(/* bot ip ranges */), 2, or(/* bot ip ranges */), 3, or(/* bot ip ranges */), 4, or(/* bot ip ranges */), 5, or(/* bot ip ranges */), 6, or(/* bot ip ranges */), 7, or(/* bot ip ranges */), 8, or(/* bot ip ranges */), 9, or(/* bot ip ranges */), 10, or(/* bot ip ranges */), 11, 0), 0), '', ['Googlebot', 'Google special crawler', 'Google fetcher', 'ChatGPT', 'OpenAI Search', 'GPTBot', 'Perplexity User', 'Perplexity', 'Bingbot', 'Applebot', 'Ahrefs'][multiIf(or(/* bot ip ranges */), 1, or(/* bot ip ranges */), 2, or(/* bot ip ranges */), 3, or(/* bot ip ranges */), 4, or(/* bot ip ranges */), 5, or(/* bot ip ranges */), 6, or(/* bot ip ranges */), 7, or(/* bot ip ranges */), 8, or(/* bot ip ranges */), 9, or(/* bot ip ranges */), 10, or(/* bot ip ranges */), 11, 0)]), [/* 344 bot literals */][multiMatchAnyIndex(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$raw_user_agent'), ''), 'null'), '^"|"$', ''), ''), [/* 344 bot literals */])])) AS Crawler,
+ if(and(in(ifNull(toString(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$lib'), ''), 'null'), '^"|"$', '')), ''), tuple('posthog-node', 'posthog-node-mcp', 'posthog-edge', 'posthog-convex', 'posthog-python', 'posthog-python-mcp', 'posthog-ruby', 'posthog-rails', 'posthog-go', 'posthog-php', 'posthog-java', 'posthog-server', 'posthog-dotnet', 'posthog-aspnetcore', 'posthog-elixir', 'posthog-rs', 'posthog-roblox', 'posthog-ios', 'posthog-android', 'posthog-react-native', 'posthog-flutter', 'posthog-kmp', 'posthog-unity')), ifNull(equals(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$raw_user_agent'), ''), 'null'), '^"|"$', ''), ''), ''), 0)), if(equals(multiIf(or(/* bot ip ranges */), 1, or(/* bot ip ranges */), 2, or(/* bot ip ranges */), 3, or(/* bot ip ranges */), 4, or(/* bot ip ranges */), 5, or(/* bot ip ranges */), 6, or(/* bot ip ranges */), 7, or(/* bot ip ranges */), 8, or(/* bot ip ranges */), 9, or(/* bot ip ranges */), 10, or(/* bot ip ranges */), 11, 0), 0), 'regular', ['search_crawler', 'search_crawler', 'search_crawler', 'ai_assistant', 'ai_search', 'ai_crawler', 'ai_assistant', 'ai_search', 'search_crawler', 'ai_search', 'seo_crawler'][multiIf(or(/* bot ip ranges */), 1, or(/* bot ip ranges */), 2, or(/* bot ip ranges */), 3, or(/* bot ip ranges */), 4, or(/* bot ip ranges */), 5, or(/* bot ip ranges */), 6, or(/* bot ip ranges */), 7, or(/* bot ip ranges */), 8, or(/* bot ip ranges */), 9, or(/* bot ip ranges */), 10, or(/* bot ip ranges */), 11, 0)]), if(ifNull(equals(multiMatchAnyIndex(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$raw_user_agent'), ''), 'null'), '^"|"$', ''), ''), [/* 344 bot literals */]), 0), 0), if(equals(multiIf(or(/* bot ip ranges */), 1, or(/* bot ip ranges */), 2, or(/* bot ip ranges */), 3, or(/* bot ip ranges */), 4, or(/* bot ip ranges */), 5, or(/* bot ip ranges */), 6, or(/* bot ip ranges */), 7, or(/* bot ip ranges */), 8, or(/* bot ip ranges */), 9, or(/* bot ip ranges */), 10, or(/* bot ip ranges */), 11, 0), 0), 'regular', ['search_crawler', 'search_crawler', 'search_crawler', 'ai_assistant', 'ai_search', 'ai_crawler', 'ai_assistant', 'ai_search', 'search_crawler', 'ai_search', 'seo_crawler'][multiIf(or(/* bot ip ranges */), 1, or(/* bot ip ranges */), 2, or(/* bot ip ranges */), 3, or(/* bot ip ranges */), 4, or(/* bot ip ranges */), 5, or(/* bot ip ranges */), 6, or(/* bot ip ranges */), 7, or(/* bot ip ranges */), 8, or(/* bot ip ranges */), 9, or(/* bot ip ranges */), 10, or(/* bot ip ranges */), 11, 0)]), [/* 344 bot literals */][multiMatchAnyIndex(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$raw_user_agent'), ''), 'null'), '^"|"$', ''), ''), [/* 344 bot literals */])])) AS Category,
count() AS Requests,
max(toTimeZone(events.timestamp, 'UTC')) AS `Last seen`
FROM events
- WHERE and(equals(events.team_id, 99999), and(ifNull(equals(accurateCastOrNull(or(ifNull(notEquals(multiMatchAnyIndex(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$raw_user_agent'), ''), 'null'), '^"|"$', ''), ''), [/* 344 bot literals */]), 0), 1), or(/* bot ip ranges */)), 'Bool'), 1), 0), notEquals(if(ifNull(equals(multiMatchAnyIndex(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$raw_user_agent'), ''), 'null'), '^"|"$', ''), ''), [/* 344 bot literals */]), 0), 0), if(equals(multiIf(or(/* bot ip ranges */), 1, or(/* bot ip ranges */), 2, or(/* bot ip ranges */), 3, or(/* bot ip ranges */), 4, or(/* bot ip ranges */), 5, or(/* bot ip ranges */), 6, or(/* bot ip ranges */), 7, or(/* bot ip ranges */), 8, or(/* bot ip ranges */), 9, or(/* bot ip ranges */), 10, or(/* bot ip ranges */), 11, 0), 0), '', ['Googlebot', 'Google special crawler', 'Google fetcher', 'ChatGPT', 'OpenAI Search', 'GPTBot', 'Perplexity User', 'Perplexity', 'Bingbot', 'Applebot', 'Ahrefs'][multiIf(or(/* bot ip ranges */), 1, or(/* bot ip ranges */), 2, or(/* bot ip ranges */), 3, or(/* bot ip ranges */), 4, or(/* bot ip ranges */), 5, or(/* bot ip ranges */), 6, or(/* bot ip ranges */), 7, or(/* bot ip ranges */), 8, or(/* bot ip ranges */), 9, or(/* bot ip ranges */), 10, or(/* bot ip ranges */), 11, 0)]), [/* 344 bot literals */][multiMatchAnyIndex(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$raw_user_agent'), ''), 'null'), '^"|"$', ''), ''), [/* 344 bot literals */])]), ''), in(events.event, tuple('$pageview', '$screen', '$http_log')), or(and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2026-01-01 00:00:00', 'UTC'))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2026-01-31 23:59:59', 'UTC')))), 0), 1))
+ WHERE and(equals(events.team_id, 99999), and(ifNull(equals(accurateCastOrNull(or(and(not(and(in(ifNull(toString(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$lib'), ''), 'null'), '^"|"$', '')), ''), tuple('posthog-node', 'posthog-node-mcp', 'posthog-edge', 'posthog-convex', 'posthog-python', 'posthog-python-mcp', 'posthog-ruby', 'posthog-rails', 'posthog-go', 'posthog-php', 'posthog-java', 'posthog-server', 'posthog-dotnet', 'posthog-aspnetcore', 'posthog-elixir', 'posthog-rs', 'posthog-roblox', 'posthog-ios', 'posthog-android', 'posthog-react-native', 'posthog-flutter', 'posthog-kmp', 'posthog-unity')), ifNull(equals(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$raw_user_agent'), ''), 'null'), '^"|"$', ''), ''), ''), 0))), ifNull(notEquals(multiMatchAnyIndex(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$raw_user_agent'), ''), 'null'), '^"|"$', ''), ''), [/* 344 bot literals */]), 0), 1)), or(/* bot ip ranges */)), 'Bool'), 1), 0), notEquals(if(and(in(ifNull(toString(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$lib'), ''), 'null'), '^"|"$', '')), ''), tuple('posthog-node', 'posthog-node-mcp', 'posthog-edge', 'posthog-convex', 'posthog-python', 'posthog-python-mcp', 'posthog-ruby', 'posthog-rails', 'posthog-go', 'posthog-php', 'posthog-java', 'posthog-server', 'posthog-dotnet', 'posthog-aspnetcore', 'posthog-elixir', 'posthog-rs', 'posthog-roblox', 'posthog-ios', 'posthog-android', 'posthog-react-native', 'posthog-flutter', 'posthog-kmp', 'posthog-unity')), ifNull(equals(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$raw_user_agent'), ''), 'null'), '^"|"$', ''), ''), ''), 0)), if(equals(multiIf(or(/* bot ip ranges */), 1, or(/* bot ip ranges */), 2, or(/* bot ip ranges */), 3, or(/* bot ip ranges */), 4, or(/* bot ip ranges */), 5, or(/* bot ip ranges */), 6, or(/* bot ip ranges */), 7, or(/* bot ip ranges */), 8, or(/* bot ip ranges */), 9, or(/* bot ip ranges */), 10, or(/* bot ip ranges */), 11, 0), 0), '', ['Googlebot', 'Google special crawler', 'Google fetcher', 'ChatGPT', 'OpenAI Search', 'GPTBot', 'Perplexity User', 'Perplexity', 'Bingbot', 'Applebot', 'Ahrefs'][multiIf(or(/* bot ip ranges */), 1, or(/* bot ip ranges */), 2, or(/* bot ip ranges */), 3, or(/* bot ip ranges */), 4, or(/* bot ip ranges */), 5, or(/* bot ip ranges */), 6, or(/* bot ip ranges */), 7, or(/* bot ip ranges */), 8, or(/* bot ip ranges */), 9, or(/* bot ip ranges */), 10, or(/* bot ip ranges */), 11, 0)]), if(ifNull(equals(multiMatchAnyIndex(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$raw_user_agent'), ''), 'null'), '^"|"$', ''), ''), [/* 344 bot literals */]), 0), 0), if(equals(multiIf(or(/* bot ip ranges */), 1, or(/* bot ip ranges */), 2, or(/* bot ip ranges */), 3, or(/* bot ip ranges */), 4, or(/* bot ip ranges */), 5, or(/* bot ip ranges */), 6, or(/* bot ip ranges */), 7, or(/* bot ip ranges */), 8, or(/* bot ip ranges */), 9, or(/* bot ip ranges */), 10, or(/* bot ip ranges */), 11, 0), 0), '', ['Googlebot', 'Google special crawler', 'Google fetcher', 'ChatGPT', 'OpenAI Search', 'GPTBot', 'Perplexity User', 'Perplexity', 'Bingbot', 'Applebot', 'Ahrefs'][multiIf(or(/* bot ip ranges */), 1, or(/* bot ip ranges */), 2, or(/* bot ip ranges */), 3, or(/* bot ip ranges */), 4, or(/* bot ip ranges */), 5, or(/* bot ip ranges */), 6, or(/* bot ip ranges */), 7, or(/* bot ip ranges */), 8, or(/* bot ip ranges */), 9, or(/* bot ip ranges */), 10, or(/* bot ip ranges */), 11, 0)]), [/* 344 bot literals */][multiMatchAnyIndex(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$raw_user_agent'), ''), 'null'), '^"|"$', ''), ''), [/* 344 bot literals */])])), ''), in(events.event, tuple('$pageview', '$screen', '$http_log')), or(and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2026-01-01 00:00:00', 'UTC'))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2026-01-31 23:59:59', 'UTC')))), 0), 1))
GROUP BY Crawler,
Category
ORDER BY Requests DESC
@@ -54,11 +54,11 @@
# name: TestWebBotsTableQueryRunner.test_only_bot_traffic_grouped_by_breakdown_1_Path
'''
SELECT replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$pathname'), ''), 'null'), '^"|"$', '') AS Path,
- count(DISTINCT if(ifNull(equals(multiMatchAnyIndex(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$raw_user_agent'), ''), 'null'), '^"|"$', ''), ''), [/* 344 bot literals */]), 0), 0), if(equals(multiIf(or(/* bot ip ranges */), 1, or(/* bot ip ranges */), 2, or(/* bot ip ranges */), 3, or(/* bot ip ranges */), 4, or(/* bot ip ranges */), 5, or(/* bot ip ranges */), 6, or(/* bot ip ranges */), 7, or(/* bot ip ranges */), 8, or(/* bot ip ranges */), 9, or(/* bot ip ranges */), 10, or(/* bot ip ranges */), 11, 0), 0), '', ['Googlebot', 'Google special crawler', 'Google fetcher', 'ChatGPT', 'OpenAI Search', 'GPTBot', 'Perplexity User', 'Perplexity', 'Bingbot', 'Applebot', 'Ahrefs'][multiIf(or(/* bot ip ranges */), 1, or(/* bot ip ranges */), 2, or(/* bot ip ranges */), 3, or(/* bot ip ranges */), 4, or(/* bot ip ranges */), 5, or(/* bot ip ranges */), 6, or(/* bot ip ranges */), 7, or(/* bot ip ranges */), 8, or(/* bot ip ranges */), 9, or(/* bot ip ranges */), 10, or(/* bot ip ranges */), 11, 0)]), [/* 344 bot literals */][multiMatchAnyIndex(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$raw_user_agent'), ''), 'null'), '^"|"$', ''), ''), [/* 344 bot literals */])])) AS Crawlers,
+ count(DISTINCT if(and(in(ifNull(toString(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$lib'), ''), 'null'), '^"|"$', '')), ''), tuple('posthog-node', 'posthog-node-mcp', 'posthog-edge', 'posthog-convex', 'posthog-python', 'posthog-python-mcp', 'posthog-ruby', 'posthog-rails', 'posthog-go', 'posthog-php', 'posthog-java', 'posthog-server', 'posthog-dotnet', 'posthog-aspnetcore', 'posthog-elixir', 'posthog-rs', 'posthog-roblox', 'posthog-ios', 'posthog-android', 'posthog-react-native', 'posthog-flutter', 'posthog-kmp', 'posthog-unity')), ifNull(equals(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$raw_user_agent'), ''), 'null'), '^"|"$', ''), ''), ''), 0)), if(equals(multiIf(or(/* bot ip ranges */), 1, or(/* bot ip ranges */), 2, or(/* bot ip ranges */), 3, or(/* bot ip ranges */), 4, or(/* bot ip ranges */), 5, or(/* bot ip ranges */), 6, or(/* bot ip ranges */), 7, or(/* bot ip ranges */), 8, or(/* bot ip ranges */), 9, or(/* bot ip ranges */), 10, or(/* bot ip ranges */), 11, 0), 0), '', ['Googlebot', 'Google special crawler', 'Google fetcher', 'ChatGPT', 'OpenAI Search', 'GPTBot', 'Perplexity User', 'Perplexity', 'Bingbot', 'Applebot', 'Ahrefs'][multiIf(or(/* bot ip ranges */), 1, or(/* bot ip ranges */), 2, or(/* bot ip ranges */), 3, or(/* bot ip ranges */), 4, or(/* bot ip ranges */), 5, or(/* bot ip ranges */), 6, or(/* bot ip ranges */), 7, or(/* bot ip ranges */), 8, or(/* bot ip ranges */), 9, or(/* bot ip ranges */), 10, or(/* bot ip ranges */), 11, 0)]), if(ifNull(equals(multiMatchAnyIndex(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$raw_user_agent'), ''), 'null'), '^"|"$', ''), ''), [/* 344 bot literals */]), 0), 0), if(equals(multiIf(or(/* bot ip ranges */), 1, or(/* bot ip ranges */), 2, or(/* bot ip ranges */), 3, or(/* bot ip ranges */), 4, or(/* bot ip ranges */), 5, or(/* bot ip ranges */), 6, or(/* bot ip ranges */), 7, or(/* bot ip ranges */), 8, or(/* bot ip ranges */), 9, or(/* bot ip ranges */), 10, or(/* bot ip ranges */), 11, 0), 0), '', ['Googlebot', 'Google special crawler', 'Google fetcher', 'ChatGPT', 'OpenAI Search', 'GPTBot', 'Perplexity User', 'Perplexity', 'Bingbot', 'Applebot', 'Ahrefs'][multiIf(or(/* bot ip ranges */), 1, or(/* bot ip ranges */), 2, or(/* bot ip ranges */), 3, or(/* bot ip ranges */), 4, or(/* bot ip ranges */), 5, or(/* bot ip ranges */), 6, or(/* bot ip ranges */), 7, or(/* bot ip ranges */), 8, or(/* bot ip ranges */), 9, or(/* bot ip ranges */), 10, or(/* bot ip ranges */), 11, 0)]), [/* 344 bot literals */][multiMatchAnyIndex(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$raw_user_agent'), ''), 'null'), '^"|"$', ''), ''), [/* 344 bot literals */])]))) AS Crawlers,
count() AS Requests,
max(toTimeZone(events.timestamp, 'UTC')) AS `Last seen`
FROM events
- WHERE and(equals(events.team_id, 99999), and(ifNull(equals(accurateCastOrNull(or(ifNull(notEquals(multiMatchAnyIndex(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$raw_user_agent'), ''), 'null'), '^"|"$', ''), ''), [/* 344 bot literals */]), 0), 1), or(/* bot ip ranges */)), 'Bool'), 1), 0), notEquals(if(ifNull(equals(multiMatchAnyIndex(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$raw_user_agent'), ''), 'null'), '^"|"$', ''), ''), [/* 344 bot literals */]), 0), 0), if(equals(multiIf(or(/* bot ip ranges */), 1, or(/* bot ip ranges */), 2, or(/* bot ip ranges */), 3, or(/* bot ip ranges */), 4, or(/* bot ip ranges */), 5, or(/* bot ip ranges */), 6, or(/* bot ip ranges */), 7, or(/* bot ip ranges */), 8, or(/* bot ip ranges */), 9, or(/* bot ip ranges */), 10, or(/* bot ip ranges */), 11, 0), 0), '', ['Googlebot', 'Google special crawler', 'Google fetcher', 'ChatGPT', 'OpenAI Search', 'GPTBot', 'Perplexity User', 'Perplexity', 'Bingbot', 'Applebot', 'Ahrefs'][multiIf(or(/* bot ip ranges */), 1, or(/* bot ip ranges */), 2, or(/* bot ip ranges */), 3, or(/* bot ip ranges */), 4, or(/* bot ip ranges */), 5, or(/* bot ip ranges */), 6, or(/* bot ip ranges */), 7, or(/* bot ip ranges */), 8, or(/* bot ip ranges */), 9, or(/* bot ip ranges */), 10, or(/* bot ip ranges */), 11, 0)]), [/* 344 bot literals */][multiMatchAnyIndex(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$raw_user_agent'), ''), 'null'), '^"|"$', ''), ''), [/* 344 bot literals */])]), ''), in(events.event, tuple('$pageview', '$screen', '$http_log')), isNotNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$pathname'), ''), 'null'), '^"|"$', '')), or(and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2026-01-01 00:00:00', 'UTC'))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2026-01-31 23:59:59', 'UTC')))), 0), 1))
+ WHERE and(equals(events.team_id, 99999), and(ifNull(equals(accurateCastOrNull(or(and(not(and(in(ifNull(toString(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$lib'), ''), 'null'), '^"|"$', '')), ''), tuple('posthog-node', 'posthog-node-mcp', 'posthog-edge', 'posthog-convex', 'posthog-python', 'posthog-python-mcp', 'posthog-ruby', 'posthog-rails', 'posthog-go', 'posthog-php', 'posthog-java', 'posthog-server', 'posthog-dotnet', 'posthog-aspnetcore', 'posthog-elixir', 'posthog-rs', 'posthog-roblox', 'posthog-ios', 'posthog-android', 'posthog-react-native', 'posthog-flutter', 'posthog-kmp', 'posthog-unity')), ifNull(equals(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$raw_user_agent'), ''), 'null'), '^"|"$', ''), ''), ''), 0))), ifNull(notEquals(multiMatchAnyIndex(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$raw_user_agent'), ''), 'null'), '^"|"$', ''), ''), [/* 344 bot literals */]), 0), 1)), or(/* bot ip ranges */)), 'Bool'), 1), 0), notEquals(if(and(in(ifNull(toString(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$lib'), ''), 'null'), '^"|"$', '')), ''), tuple('posthog-node', 'posthog-node-mcp', 'posthog-edge', 'posthog-convex', 'posthog-python', 'posthog-python-mcp', 'posthog-ruby', 'posthog-rails', 'posthog-go', 'posthog-php', 'posthog-java', 'posthog-server', 'posthog-dotnet', 'posthog-aspnetcore', 'posthog-elixir', 'posthog-rs', 'posthog-roblox', 'posthog-ios', 'posthog-android', 'posthog-react-native', 'posthog-flutter', 'posthog-kmp', 'posthog-unity')), ifNull(equals(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$raw_user_agent'), ''), 'null'), '^"|"$', ''), ''), ''), 0)), if(equals(multiIf(or(/* bot ip ranges */), 1, or(/* bot ip ranges */), 2, or(/* bot ip ranges */), 3, or(/* bot ip ranges */), 4, or(/* bot ip ranges */), 5, or(/* bot ip ranges */), 6, or(/* bot ip ranges */), 7, or(/* bot ip ranges */), 8, or(/* bot ip ranges */), 9, or(/* bot ip ranges */), 10, or(/* bot ip ranges */), 11, 0), 0), '', ['Googlebot', 'Google special crawler', 'Google fetcher', 'ChatGPT', 'OpenAI Search', 'GPTBot', 'Perplexity User', 'Perplexity', 'Bingbot', 'Applebot', 'Ahrefs'][multiIf(or(/* bot ip ranges */), 1, or(/* bot ip ranges */), 2, or(/* bot ip ranges */), 3, or(/* bot ip ranges */), 4, or(/* bot ip ranges */), 5, or(/* bot ip ranges */), 6, or(/* bot ip ranges */), 7, or(/* bot ip ranges */), 8, or(/* bot ip ranges */), 9, or(/* bot ip ranges */), 10, or(/* bot ip ranges */), 11, 0)]), if(ifNull(equals(multiMatchAnyIndex(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$raw_user_agent'), ''), 'null'), '^"|"$', ''), ''), [/* 344 bot literals */]), 0), 0), if(equals(multiIf(or(/* bot ip ranges */), 1, or(/* bot ip ranges */), 2, or(/* bot ip ranges */), 3, or(/* bot ip ranges */), 4, or(/* bot ip ranges */), 5, or(/* bot ip ranges */), 6, or(/* bot ip ranges */), 7, or(/* bot ip ranges */), 8, or(/* bot ip ranges */), 9, or(/* bot ip ranges */), 10, or(/* bot ip ranges */), 11, 0), 0), '', ['Googlebot', 'Google special crawler', 'Google fetcher', 'ChatGPT', 'OpenAI Search', 'GPTBot', 'Perplexity User', 'Perplexity', 'Bingbot', 'Applebot', 'Ahrefs'][multiIf(or(/* bot ip ranges */), 1, or(/* bot ip ranges */), 2, or(/* bot ip ranges */), 3, or(/* bot ip ranges */), 4, or(/* bot ip ranges */), 5, or(/* bot ip ranges */), 6, or(/* bot ip ranges */), 7, or(/* bot ip ranges */), 8, or(/* bot ip ranges */), 9, or(/* bot ip ranges */), 10, or(/* bot ip ranges */), 11, 0)]), [/* 344 bot literals */][multiMatchAnyIndex(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$raw_user_agent'), ''), 'null'), '^"|"$', ''), ''), [/* 344 bot literals */])])), ''), in(events.event, tuple('$pageview', '$screen', '$http_log')), isNotNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$pathname'), ''), 'null'), '^"|"$', '')), or(and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2026-01-01 00:00:00', 'UTC'))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2026-01-31 23:59:59', 'UTC')))), 0), 1))
GROUP BY Path
ORDER BY Requests DESC
LIMIT 51
diff --git a/products/web_analytics/backend/hogql_queries/test/__snapshots__/test_web_bots.new_events_schema.ambr b/products/web_analytics/backend/hogql_queries/test/__snapshots__/test_web_bots.new_events_schema.ambr
index 0684d9edac79..d94ebd37769e 100644
--- a/products/web_analytics/backend/hogql_queries/test/__snapshots__/test_web_bots.new_events_schema.ambr
+++ b/products/web_analytics/backend/hogql_queries/test/__snapshots__/test_web_bots.new_events_schema.ambr
@@ -1,12 +1,12 @@
# serializer version: 1
# name: TestWebBotsTableQueryRunner.test_date_range_excludes_outside_events[new_events_schema]
'''
- SELECT if(ifNull(equals(multiMatchAnyIndex(ifNull(if(notEquals(toJSONString(events.properties.^`$raw_user_agent`), '{}'), toJSONString(events.properties.^`$raw_user_agent`), if(isNull(nullIf(toString(events.properties.`$raw_user_agent`), '')), NULL, if(and(in(ascii(toString(events.properties.`$raw_user_agent`)), tuple(91, 123)), in(ascii(toJSONString(events.properties.`$raw_user_agent`)), tuple(91, 123))), nullIf(nullIf(toJSONString(events.properties.`$raw_user_agent`), '[]'), '{}'), toString(events.properties.`$raw_user_agent`)))), ''), [/* 344 bot literals */]), 0), 0), if(equals(multiIf(or(/* bot ip ranges */), 1, or(/* bot ip ranges */), 2, or(/* bot ip ranges */), 3, or(/* bot ip ranges */), 4, or(/* bot ip ranges */), 5, or(/* bot ip ranges */), 6, or(/* bot ip ranges */), 7, or(/* bot ip ranges */), 8, or(/* bot ip ranges */), 9, or(/* bot ip ranges */), 10, or(/* bot ip ranges */), 11, 0), 0), '', ['Googlebot', 'Google special crawler', 'Google fetcher', 'ChatGPT', 'OpenAI Search', 'GPTBot', 'Perplexity User', 'Perplexity', 'Bingbot', 'Applebot', 'Ahrefs'][multiIf(or(/* bot ip ranges */), 1, or(/* bot ip ranges */), 2, or(/* bot ip ranges */), 3, or(/* bot ip ranges */), 4, or(/* bot ip ranges */), 5, or(/* bot ip ranges */), 6, or(/* bot ip ranges */), 7, or(/* bot ip ranges */), 8, or(/* bot ip ranges */), 9, or(/* bot ip ranges */), 10, or(/* bot ip ranges */), 11, 0)]), [/* 344 bot literals */][multiMatchAnyIndex(ifNull(if(notEquals(toJSONString(events.properties.^`$raw_user_agent`), '{}'), toJSONString(events.properties.^`$raw_user_agent`), if(isNull(nullIf(toString(events.properties.`$raw_user_agent`), '')), NULL, if(and(in(ascii(toString(events.properties.`$raw_user_agent`)), tuple(91, 123)), in(ascii(toJSONString(events.properties.`$raw_user_agent`)), tuple(91, 123))), nullIf(nullIf(toJSONString(events.properties.`$raw_user_agent`), '[]'), '{}'), toString(events.properties.`$raw_user_agent`)))), ''), [/* 344 bot literals */])]) AS Crawler,
- if(ifNull(equals(multiMatchAnyIndex(ifNull(if(notEquals(toJSONString(events.properties.^`$raw_user_agent`), '{}'), toJSONString(events.properties.^`$raw_user_agent`), if(isNull(nullIf(toString(events.properties.`$raw_user_agent`), '')), NULL, if(and(in(ascii(toString(events.properties.`$raw_user_agent`)), tuple(91, 123)), in(ascii(toJSONString(events.properties.`$raw_user_agent`)), tuple(91, 123))), nullIf(nullIf(toJSONString(events.properties.`$raw_user_agent`), '[]'), '{}'), toString(events.properties.`$raw_user_agent`)))), ''), [/* 344 bot literals */]), 0), 0), if(equals(multiIf(or(/* bot ip ranges */), 1, or(/* bot ip ranges */), 2, or(/* bot ip ranges */), 3, or(/* bot ip ranges */), 4, or(/* bot ip ranges */), 5, or(/* bot ip ranges */), 6, or(/* bot ip ranges */), 7, or(/* bot ip ranges */), 8, or(/* bot ip ranges */), 9, or(/* bot ip ranges */), 10, or(/* bot ip ranges */), 11, 0), 0), 'regular', ['search_crawler', 'search_crawler', 'search_crawler', 'ai_assistant', 'ai_search', 'ai_crawler', 'ai_assistant', 'ai_search', 'search_crawler', 'ai_search', 'seo_crawler'][multiIf(or(/* bot ip ranges */), 1, or(/* bot ip ranges */), 2, or(/* bot ip ranges */), 3, or(/* bot ip ranges */), 4, or(/* bot ip ranges */), 5, or(/* bot ip ranges */), 6, or(/* bot ip ranges */), 7, or(/* bot ip ranges */), 8, or(/* bot ip ranges */), 9, or(/* bot ip ranges */), 10, or(/* bot ip ranges */), 11, 0)]), [/* 344 bot literals */][multiMatchAnyIndex(ifNull(if(notEquals(toJSONString(events.properties.^`$raw_user_agent`), '{}'), toJSONString(events.properties.^`$raw_user_agent`), if(isNull(nullIf(toString(events.properties.`$raw_user_agent`), '')), NULL, if(and(in(ascii(toString(events.properties.`$raw_user_agent`)), tuple(91, 123)), in(ascii(toJSONString(events.properties.`$raw_user_agent`)), tuple(91, 123))), nullIf(nullIf(toJSONString(events.properties.`$raw_user_agent`), '[]'), '{}'), toString(events.properties.`$raw_user_agent`)))), ''), [/* 344 bot literals */])]) AS Category,
+ SELECT if(and(in(ifNull(toString(if(notEquals(toJSONString(events.properties.^`$lib`), '{}'), toJSONString(events.properties.^`$lib`), if(isNull(nullIf(toString(events.properties.`$lib`), '')), NULL, if(and(in(ascii(toString(events.properties.`$lib`)), tuple(91, 123)), in(ascii(toJSONString(events.properties.`$lib`)), tuple(91, 123))), nullIf(nullIf(toJSONString(events.properties.`$lib`), '[]'), '{}'), toString(events.properties.`$lib`))))), ''), tuple('posthog-node', 'posthog-node-mcp', 'posthog-edge', 'posthog-convex', 'posthog-python', 'posthog-python-mcp', 'posthog-ruby', 'posthog-rails', 'posthog-go', 'posthog-php', 'posthog-java', 'posthog-server', 'posthog-dotnet', 'posthog-aspnetcore', 'posthog-elixir', 'posthog-rs', 'posthog-roblox', 'posthog-ios', 'posthog-android', 'posthog-react-native', 'posthog-flutter', 'posthog-kmp', 'posthog-unity')), ifNull(equals(ifNull(if(notEquals(toJSONString(events.properties.^`$raw_user_agent`), '{}'), toJSONString(events.properties.^`$raw_user_agent`), if(isNull(nullIf(toString(events.properties.`$raw_user_agent`), '')), NULL, if(and(in(ascii(toString(events.properties.`$raw_user_agent`)), tuple(91, 123)), in(ascii(toJSONString(events.properties.`$raw_user_agent`)), tuple(91, 123))), nullIf(nullIf(toJSONString(events.properties.`$raw_user_agent`), '[]'), '{}'), toString(events.properties.`$raw_user_agent`)))), ''), ''), 0)), if(equals(multiIf(or(/* bot ip ranges */), 1, or(/* bot ip ranges */), 2, or(/* bot ip ranges */), 3, or(/* bot ip ranges */), 4, or(/* bot ip ranges */), 5, or(/* bot ip ranges */), 6, or(/* bot ip ranges */), 7, or(/* bot ip ranges */), 8, or(/* bot ip ranges */), 9, or(/* bot ip ranges */), 10, or(/* bot ip ranges */), 11, 0), 0), '', ['Googlebot', 'Google special crawler', 'Google fetcher', 'ChatGPT', 'OpenAI Search', 'GPTBot', 'Perplexity User', 'Perplexity', 'Bingbot', 'Applebot', 'Ahrefs'][multiIf(or(/* bot ip ranges */), 1, or(/* bot ip ranges */), 2, or(/* bot ip ranges */), 3, or(/* bot ip ranges */), 4, or(/* bot ip ranges */), 5, or(/* bot ip ranges */), 6, or(/* bot ip ranges */), 7, or(/* bot ip ranges */), 8, or(/* bot ip ranges */), 9, or(/* bot ip ranges */), 10, or(/* bot ip ranges */), 11, 0)]), if(ifNull(equals(multiMatchAnyIndex(ifNull(if(notEquals(toJSONString(events.properties.^`$raw_user_agent`), '{}'), toJSONString(events.properties.^`$raw_user_agent`), if(isNull(nullIf(toString(events.properties.`$raw_user_agent`), '')), NULL, if(and(in(ascii(toString(events.properties.`$raw_user_agent`)), tuple(91, 123)), in(ascii(toJSONString(events.properties.`$raw_user_agent`)), tuple(91, 123))), nullIf(nullIf(toJSONString(events.properties.`$raw_user_agent`), '[]'), '{}'), toString(events.properties.`$raw_user_agent`)))), ''), [/* 344 bot literals */]), 0), 0), if(equals(multiIf(or(/* bot ip ranges */), 1, or(/* bot ip ranges */), 2, or(/* bot ip ranges */), 3, or(/* bot ip ranges */), 4, or(/* bot ip ranges */), 5, or(/* bot ip ranges */), 6, or(/* bot ip ranges */), 7, or(/* bot ip ranges */), 8, or(/* bot ip ranges */), 9, or(/* bot ip ranges */), 10, or(/* bot ip ranges */), 11, 0), 0), '', ['Googlebot', 'Google special crawler', 'Google fetcher', 'ChatGPT', 'OpenAI Search', 'GPTBot', 'Perplexity User', 'Perplexity', 'Bingbot', 'Applebot', 'Ahrefs'][multiIf(or(/* bot ip ranges */), 1, or(/* bot ip ranges */), 2, or(/* bot ip ranges */), 3, or(/* bot ip ranges */), 4, or(/* bot ip ranges */), 5, or(/* bot ip ranges */), 6, or(/* bot ip ranges */), 7, or(/* bot ip ranges */), 8, or(/* bot ip ranges */), 9, or(/* bot ip ranges */), 10, or(/* bot ip ranges */), 11, 0)]), [/* 344 bot literals */][multiMatchAnyIndex(ifNull(if(notEquals(toJSONString(events.properties.^`$raw_user_agent`), '{}'), toJSONString(events.properties.^`$raw_user_agent`), if(isNull(nullIf(toString(events.properties.`$raw_user_agent`), '')), NULL, if(and(in(ascii(toString(events.properties.`$raw_user_agent`)), tuple(91, 123)), in(ascii(toJSONString(events.properties.`$raw_user_agent`)), tuple(91, 123))), nullIf(nullIf(toJSONString(events.properties.`$raw_user_agent`), '[]'), '{}'), toString(events.properties.`$raw_user_agent`)))), ''), [/* 344 bot literals */])])) AS Crawler,
+ if(and(in(ifNull(toString(if(notEquals(toJSONString(events.properties.^`$lib`), '{}'), toJSONString(events.properties.^`$lib`), if(isNull(nullIf(toString(events.properties.`$lib`), '')), NULL, if(and(in(ascii(toString(events.properties.`$lib`)), tuple(91, 123)), in(ascii(toJSONString(events.properties.`$lib`)), tuple(91, 123))), nullIf(nullIf(toJSONString(events.properties.`$lib`), '[]'), '{}'), toString(events.properties.`$lib`))))), ''), tuple('posthog-node', 'posthog-node-mcp', 'posthog-edge', 'posthog-convex', 'posthog-python', 'posthog-python-mcp', 'posthog-ruby', 'posthog-rails', 'posthog-go', 'posthog-php', 'posthog-java', 'posthog-server', 'posthog-dotnet', 'posthog-aspnetcore', 'posthog-elixir', 'posthog-rs', 'posthog-roblox', 'posthog-ios', 'posthog-android', 'posthog-react-native', 'posthog-flutter', 'posthog-kmp', 'posthog-unity')), ifNull(equals(ifNull(if(notEquals(toJSONString(events.properties.^`$raw_user_agent`), '{}'), toJSONString(events.properties.^`$raw_user_agent`), if(isNull(nullIf(toString(events.properties.`$raw_user_agent`), '')), NULL, if(and(in(ascii(toString(events.properties.`$raw_user_agent`)), tuple(91, 123)), in(ascii(toJSONString(events.properties.`$raw_user_agent`)), tuple(91, 123))), nullIf(nullIf(toJSONString(events.properties.`$raw_user_agent`), '[]'), '{}'), toString(events.properties.`$raw_user_agent`)))), ''), ''), 0)), if(equals(multiIf(or(/* bot ip ranges */), 1, or(/* bot ip ranges */), 2, or(/* bot ip ranges */), 3, or(/* bot ip ranges */), 4, or(/* bot ip ranges */), 5, or(/* bot ip ranges */), 6, or(/* bot ip ranges */), 7, or(/* bot ip ranges */), 8, or(/* bot ip ranges */), 9, or(/* bot ip ranges */), 10, or(/* bot ip ranges */), 11, 0), 0), 'regular', ['search_crawler', 'search_crawler', 'search_crawler', 'ai_assistant', 'ai_search', 'ai_crawler', 'ai_assistant', 'ai_search', 'search_crawler', 'ai_search', 'seo_crawler'][multiIf(or(/* bot ip ranges */), 1, or(/* bot ip ranges */), 2, or(/* bot ip ranges */), 3, or(/* bot ip ranges */), 4, or(/* bot ip ranges */), 5, or(/* bot ip ranges */), 6, or(/* bot ip ranges */), 7, or(/* bot ip ranges */), 8, or(/* bot ip ranges */), 9, or(/* bot ip ranges */), 10, or(/* bot ip ranges */), 11, 0)]), if(ifNull(equals(multiMatchAnyIndex(ifNull(if(notEquals(toJSONString(events.properties.^`$raw_user_agent`), '{}'), toJSONString(events.properties.^`$raw_user_agent`), if(isNull(nullIf(toString(events.properties.`$raw_user_agent`), '')), NULL, if(and(in(ascii(toString(events.properties.`$raw_user_agent`)), tuple(91, 123)), in(ascii(toJSONString(events.properties.`$raw_user_agent`)), tuple(91, 123))), nullIf(nullIf(toJSONString(events.properties.`$raw_user_agent`), '[]'), '{}'), toString(events.properties.`$raw_user_agent`)))), ''), [/* 344 bot literals */]), 0), 0), if(equals(multiIf(or(/* bot ip ranges */), 1, or(/* bot ip ranges */), 2, or(/* bot ip ranges */), 3, or(/* bot ip ranges */), 4, or(/* bot ip ranges */), 5, or(/* bot ip ranges */), 6, or(/* bot ip ranges */), 7, or(/* bot ip ranges */), 8, or(/* bot ip ranges */), 9, or(/* bot ip ranges */), 10, or(/* bot ip ranges */), 11, 0), 0), 'regular', ['search_crawler', 'search_crawler', 'search_crawler', 'ai_assistant', 'ai_search', 'ai_crawler', 'ai_assistant', 'ai_search', 'search_crawler', 'ai_search', 'seo_crawler'][multiIf(or(/* bot ip ranges */), 1, or(/* bot ip ranges */), 2, or(/* bot ip ranges */), 3, or(/* bot ip ranges */), 4, or(/* bot ip ranges */), 5, or(/* bot ip ranges */), 6, or(/* bot ip ranges */), 7, or(/* bot ip ranges */), 8, or(/* bot ip ranges */), 9, or(/* bot ip ranges */), 10, or(/* bot ip ranges */), 11, 0)]), [/* 344 bot literals */][multiMatchAnyIndex(ifNull(if(notEquals(toJSONString(events.properties.^`$raw_user_agent`), '{}'), toJSONString(events.properties.^`$raw_user_agent`), if(isNull(nullIf(toString(events.properties.`$raw_user_agent`), '')), NULL, if(and(in(ascii(toString(events.properties.`$raw_user_agent`)), tuple(91, 123)), in(ascii(toJSONString(events.properties.`$raw_user_agent`)), tuple(91, 123))), nullIf(nullIf(toJSONString(events.properties.`$raw_user_agent`), '[]'), '{}'), toString(events.properties.`$raw_user_agent`)))), ''), [/* 344 bot literals */])])) AS Category,
count() AS Requests,
max(toTimeZone(events.timestamp, 'UTC')) AS `Last seen`
FROM events_json AS events
- WHERE and(equals(events.team_id, 99999), and(ifNull(equals(accurateCastOrNull(or(ifNull(notEquals(multiMatchAnyIndex(ifNull(if(notEquals(toJSONString(events.properties.^`$raw_user_agent`), '{}'), toJSONString(events.properties.^`$raw_user_agent`), if(isNull(nullIf(toString(events.properties.`$raw_user_agent`), '')), NULL, if(and(in(ascii(toString(events.properties.`$raw_user_agent`)), tuple(91, 123)), in(ascii(toJSONString(events.properties.`$raw_user_agent`)), tuple(91, 123))), nullIf(nullIf(toJSONString(events.properties.`$raw_user_agent`), '[]'), '{}'), toString(events.properties.`$raw_user_agent`)))), ''), [/* 344 bot literals */]), 0), 1), or(/* bot ip ranges */)), 'Bool'), 1), 0), notEquals(if(ifNull(equals(multiMatchAnyIndex(ifNull(if(notEquals(toJSONString(events.properties.^`$raw_user_agent`), '{}'), toJSONString(events.properties.^`$raw_user_agent`), if(isNull(nullIf(toString(events.properties.`$raw_user_agent`), '')), NULL, if(and(in(ascii(toString(events.properties.`$raw_user_agent`)), tuple(91, 123)), in(ascii(toJSONString(events.properties.`$raw_user_agent`)), tuple(91, 123))), nullIf(nullIf(toJSONString(events.properties.`$raw_user_agent`), '[]'), '{}'), toString(events.properties.`$raw_user_agent`)))), ''), [/* 344 bot literals */]), 0), 0), if(equals(multiIf(or(/* bot ip ranges */), 1, or(/* bot ip ranges */), 2, or(/* bot ip ranges */), 3, or(/* bot ip ranges */), 4, or(/* bot ip ranges */), 5, or(/* bot ip ranges */), 6, or(/* bot ip ranges */), 7, or(/* bot ip ranges */), 8, or(/* bot ip ranges */), 9, or(/* bot ip ranges */), 10, or(/* bot ip ranges */), 11, 0), 0), '', ['Googlebot', 'Google special crawler', 'Google fetcher', 'ChatGPT', 'OpenAI Search', 'GPTBot', 'Perplexity User', 'Perplexity', 'Bingbot', 'Applebot', 'Ahrefs'][multiIf(or(/* bot ip ranges */), 1, or(/* bot ip ranges */), 2, or(/* bot ip ranges */), 3, or(/* bot ip ranges */), 4, or(/* bot ip ranges */), 5, or(/* bot ip ranges */), 6, or(/* bot ip ranges */), 7, or(/* bot ip ranges */), 8, or(/* bot ip ranges */), 9, or(/* bot ip ranges */), 10, or(/* bot ip ranges */), 11, 0)]), [/* 344 bot literals */][multiMatchAnyIndex(ifNull(if(notEquals(toJSONString(events.properties.^`$raw_user_agent`), '{}'), toJSONString(events.properties.^`$raw_user_agent`), if(isNull(nullIf(toString(events.properties.`$raw_user_agent`), '')), NULL, if(and(in(ascii(toString(events.properties.`$raw_user_agent`)), tuple(91, 123)), in(ascii(toJSONString(events.properties.`$raw_user_agent`)), tuple(91, 123))), nullIf(nullIf(toJSONString(events.properties.`$raw_user_agent`), '[]'), '{}'), toString(events.properties.`$raw_user_agent`)))), ''), [/* 344 bot literals */])]), ''), in(events.event, tuple('$pageview', '$screen', '$http_log')), or(and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2026-03-01 00:00:00', 'UTC'))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2026-03-31 23:59:59', 'UTC')))), 0), 1))
+ WHERE and(equals(events.team_id, 99999), and(ifNull(equals(accurateCastOrNull(or(and(not(and(in(ifNull(toString(if(notEquals(toJSONString(events.properties.^`$lib`), '{}'), toJSONString(events.properties.^`$lib`), if(isNull(nullIf(toString(events.properties.`$lib`), '')), NULL, if(and(in(ascii(toString(events.properties.`$lib`)), tuple(91, 123)), in(ascii(toJSONString(events.properties.`$lib`)), tuple(91, 123))), nullIf(nullIf(toJSONString(events.properties.`$lib`), '[]'), '{}'), toString(events.properties.`$lib`))))), ''), tuple('posthog-node', 'posthog-node-mcp', 'posthog-edge', 'posthog-convex', 'posthog-python', 'posthog-python-mcp', 'posthog-ruby', 'posthog-rails', 'posthog-go', 'posthog-php', 'posthog-java', 'posthog-server', 'posthog-dotnet', 'posthog-aspnetcore', 'posthog-elixir', 'posthog-rs', 'posthog-roblox', 'posthog-ios', 'posthog-android', 'posthog-react-native', 'posthog-flutter', 'posthog-kmp', 'posthog-unity')), ifNull(equals(ifNull(if(notEquals(toJSONString(events.properties.^`$raw_user_agent`), '{}'), toJSONString(events.properties.^`$raw_user_agent`), if(isNull(nullIf(toString(events.properties.`$raw_user_agent`), '')), NULL, if(and(in(ascii(toString(events.properties.`$raw_user_agent`)), tuple(91, 123)), in(ascii(toJSONString(events.properties.`$raw_user_agent`)), tuple(91, 123))), nullIf(nullIf(toJSONString(events.properties.`$raw_user_agent`), '[]'), '{}'), toString(events.properties.`$raw_user_agent`)))), ''), ''), 0))), ifNull(notEquals(multiMatchAnyIndex(ifNull(if(notEquals(toJSONString(events.properties.^`$raw_user_agent`), '{}'), toJSONString(events.properties.^`$raw_user_agent`), if(isNull(nullIf(toString(events.properties.`$raw_user_agent`), '')), NULL, if(and(in(ascii(toString(events.properties.`$raw_user_agent`)), tuple(91, 123)), in(ascii(toJSONString(events.properties.`$raw_user_agent`)), tuple(91, 123))), nullIf(nullIf(toJSONString(events.properties.`$raw_user_agent`), '[]'), '{}'), toString(events.properties.`$raw_user_agent`)))), ''), [/* 344 bot literals */]), 0), 1)), or(/* bot ip ranges */)), 'Bool'), 1), 0), notEquals(if(and(in(ifNull(toString(if(notEquals(toJSONString(events.properties.^`$lib`), '{}'), toJSONString(events.properties.^`$lib`), if(isNull(nullIf(toString(events.properties.`$lib`), '')), NULL, if(and(in(ascii(toString(events.properties.`$lib`)), tuple(91, 123)), in(ascii(toJSONString(events.properties.`$lib`)), tuple(91, 123))), nullIf(nullIf(toJSONString(events.properties.`$lib`), '[]'), '{}'), toString(events.properties.`$lib`))))), ''), tuple('posthog-node', 'posthog-node-mcp', 'posthog-edge', 'posthog-convex', 'posthog-python', 'posthog-python-mcp', 'posthog-ruby', 'posthog-rails', 'posthog-go', 'posthog-php', 'posthog-java', 'posthog-server', 'posthog-dotnet', 'posthog-aspnetcore', 'posthog-elixir', 'posthog-rs', 'posthog-roblox', 'posthog-ios', 'posthog-android', 'posthog-react-native', 'posthog-flutter', 'posthog-kmp', 'posthog-unity')), ifNull(equals(ifNull(if(notEquals(toJSONString(events.properties.^`$raw_user_agent`), '{}'), toJSONString(events.properties.^`$raw_user_agent`), if(isNull(nullIf(toString(events.properties.`$raw_user_agent`), '')), NULL, if(and(in(ascii(toString(events.properties.`$raw_user_agent`)), tuple(91, 123)), in(ascii(toJSONString(events.properties.`$raw_user_agent`)), tuple(91, 123))), nullIf(nullIf(toJSONString(events.properties.`$raw_user_agent`), '[]'), '{}'), toString(events.properties.`$raw_user_agent`)))), ''), ''), 0)), if(equals(multiIf(or(/* bot ip ranges */), 1, or(/* bot ip ranges */), 2, or(/* bot ip ranges */), 3, or(/* bot ip ranges */), 4, or(/* bot ip ranges */), 5, or(/* bot ip ranges */), 6, or(/* bot ip ranges */), 7, or(/* bot ip ranges */), 8, or(/* bot ip ranges */), 9, or(/* bot ip ranges */), 10, or(/* bot ip ranges */), 11, 0), 0), '', ['Googlebot', 'Google special crawler', 'Google fetcher', 'ChatGPT', 'OpenAI Search', 'GPTBot', 'Perplexity User', 'Perplexity', 'Bingbot', 'Applebot', 'Ahrefs'][multiIf(or(/* bot ip ranges */), 1, or(/* bot ip ranges */), 2, or(/* bot ip ranges */), 3, or(/* bot ip ranges */), 4, or(/* bot ip ranges */), 5, or(/* bot ip ranges */), 6, or(/* bot ip ranges */), 7, or(/* bot ip ranges */), 8, or(/* bot ip ranges */), 9, or(/* bot ip ranges */), 10, or(/* bot ip ranges */), 11, 0)]), if(ifNull(equals(multiMatchAnyIndex(ifNull(if(notEquals(toJSONString(events.properties.^`$raw_user_agent`), '{}'), toJSONString(events.properties.^`$raw_user_agent`), if(isNull(nullIf(toString(events.properties.`$raw_user_agent`), '')), NULL, if(and(in(ascii(toString(events.properties.`$raw_user_agent`)), tuple(91, 123)), in(ascii(toJSONString(events.properties.`$raw_user_agent`)), tuple(91, 123))), nullIf(nullIf(toJSONString(events.properties.`$raw_user_agent`), '[]'), '{}'), toString(events.properties.`$raw_user_agent`)))), ''), [/* 344 bot literals */]), 0), 0), if(equals(multiIf(or(/* bot ip ranges */), 1, or(/* bot ip ranges */), 2, or(/* bot ip ranges */), 3, or(/* bot ip ranges */), 4, or(/* bot ip ranges */), 5, or(/* bot ip ranges */), 6, or(/* bot ip ranges */), 7, or(/* bot ip ranges */), 8, or(/* bot ip ranges */), 9, or(/* bot ip ranges */), 10, or(/* bot ip ranges */), 11, 0), 0), '', ['Googlebot', 'Google special crawler', 'Google fetcher', 'ChatGPT', 'OpenAI Search', 'GPTBot', 'Perplexity User', 'Perplexity', 'Bingbot', 'Applebot', 'Ahrefs'][multiIf(or(/* bot ip ranges */), 1, or(/* bot ip ranges */), 2, or(/* bot ip ranges */), 3, or(/* bot ip ranges */), 4, or(/* bot ip ranges */), 5, or(/* bot ip ranges */), 6, or(/* bot ip ranges */), 7, or(/* bot ip ranges */), 8, or(/* bot ip ranges */), 9, or(/* bot ip ranges */), 10, or(/* bot ip ranges */), 11, 0)]), [/* 344 bot literals */][multiMatchAnyIndex(ifNull(if(notEquals(toJSONString(events.properties.^`$raw_user_agent`), '{}'), toJSONString(events.properties.^`$raw_user_agent`), if(isNull(nullIf(toString(events.properties.`$raw_user_agent`), '')), NULL, if(and(in(ascii(toString(events.properties.`$raw_user_agent`)), tuple(91, 123)), in(ascii(toJSONString(events.properties.`$raw_user_agent`)), tuple(91, 123))), nullIf(nullIf(toJSONString(events.properties.`$raw_user_agent`), '[]'), '{}'), toString(events.properties.`$raw_user_agent`)))), ''), [/* 344 bot literals */])])), ''), in(events.event, tuple('$pageview', '$screen', '$http_log')), or(and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2026-03-01 00:00:00', 'UTC'))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2026-03-31 23:59:59', 'UTC')))), 0), 1))
GROUP BY Crawler,
Category
ORDER BY Requests DESC
@@ -29,12 +29,12 @@
# ---
# name: TestWebBotsTableQueryRunner.test_only_bot_traffic_grouped_by_breakdown_0_Crawler[new_events_schema]
'''
- SELECT if(ifNull(equals(multiMatchAnyIndex(ifNull(if(notEquals(toJSONString(events.properties.^`$raw_user_agent`), '{}'), toJSONString(events.properties.^`$raw_user_agent`), if(isNull(nullIf(toString(events.properties.`$raw_user_agent`), '')), NULL, if(and(in(ascii(toString(events.properties.`$raw_user_agent`)), tuple(91, 123)), in(ascii(toJSONString(events.properties.`$raw_user_agent`)), tuple(91, 123))), nullIf(nullIf(toJSONString(events.properties.`$raw_user_agent`), '[]'), '{}'), toString(events.properties.`$raw_user_agent`)))), ''), [/* 344 bot literals */]), 0), 0), if(equals(multiIf(or(/* bot ip ranges */), 1, or(/* bot ip ranges */), 2, or(/* bot ip ranges */), 3, or(/* bot ip ranges */), 4, or(/* bot ip ranges */), 5, or(/* bot ip ranges */), 6, or(/* bot ip ranges */), 7, or(/* bot ip ranges */), 8, or(/* bot ip ranges */), 9, or(/* bot ip ranges */), 10, or(/* bot ip ranges */), 11, 0), 0), '', ['Googlebot', 'Google special crawler', 'Google fetcher', 'ChatGPT', 'OpenAI Search', 'GPTBot', 'Perplexity User', 'Perplexity', 'Bingbot', 'Applebot', 'Ahrefs'][multiIf(or(/* bot ip ranges */), 1, or(/* bot ip ranges */), 2, or(/* bot ip ranges */), 3, or(/* bot ip ranges */), 4, or(/* bot ip ranges */), 5, or(/* bot ip ranges */), 6, or(/* bot ip ranges */), 7, or(/* bot ip ranges */), 8, or(/* bot ip ranges */), 9, or(/* bot ip ranges */), 10, or(/* bot ip ranges */), 11, 0)]), [/* 344 bot literals */][multiMatchAnyIndex(ifNull(if(notEquals(toJSONString(events.properties.^`$raw_user_agent`), '{}'), toJSONString(events.properties.^`$raw_user_agent`), if(isNull(nullIf(toString(events.properties.`$raw_user_agent`), '')), NULL, if(and(in(ascii(toString(events.properties.`$raw_user_agent`)), tuple(91, 123)), in(ascii(toJSONString(events.properties.`$raw_user_agent`)), tuple(91, 123))), nullIf(nullIf(toJSONString(events.properties.`$raw_user_agent`), '[]'), '{}'), toString(events.properties.`$raw_user_agent`)))), ''), [/* 344 bot literals */])]) AS Crawler,
- if(ifNull(equals(multiMatchAnyIndex(ifNull(if(notEquals(toJSONString(events.properties.^`$raw_user_agent`), '{}'), toJSONString(events.properties.^`$raw_user_agent`), if(isNull(nullIf(toString(events.properties.`$raw_user_agent`), '')), NULL, if(and(in(ascii(toString(events.properties.`$raw_user_agent`)), tuple(91, 123)), in(ascii(toJSONString(events.properties.`$raw_user_agent`)), tuple(91, 123))), nullIf(nullIf(toJSONString(events.properties.`$raw_user_agent`), '[]'), '{}'), toString(events.properties.`$raw_user_agent`)))), ''), [/* 344 bot literals */]), 0), 0), if(equals(multiIf(or(/* bot ip ranges */), 1, or(/* bot ip ranges */), 2, or(/* bot ip ranges */), 3, or(/* bot ip ranges */), 4, or(/* bot ip ranges */), 5, or(/* bot ip ranges */), 6, or(/* bot ip ranges */), 7, or(/* bot ip ranges */), 8, or(/* bot ip ranges */), 9, or(/* bot ip ranges */), 10, or(/* bot ip ranges */), 11, 0), 0), 'regular', ['search_crawler', 'search_crawler', 'search_crawler', 'ai_assistant', 'ai_search', 'ai_crawler', 'ai_assistant', 'ai_search', 'search_crawler', 'ai_search', 'seo_crawler'][multiIf(or(/* bot ip ranges */), 1, or(/* bot ip ranges */), 2, or(/* bot ip ranges */), 3, or(/* bot ip ranges */), 4, or(/* bot ip ranges */), 5, or(/* bot ip ranges */), 6, or(/* bot ip ranges */), 7, or(/* bot ip ranges */), 8, or(/* bot ip ranges */), 9, or(/* bot ip ranges */), 10, or(/* bot ip ranges */), 11, 0)]), [/* 344 bot literals */][multiMatchAnyIndex(ifNull(if(notEquals(toJSONString(events.properties.^`$raw_user_agent`), '{}'), toJSONString(events.properties.^`$raw_user_agent`), if(isNull(nullIf(toString(events.properties.`$raw_user_agent`), '')), NULL, if(and(in(ascii(toString(events.properties.`$raw_user_agent`)), tuple(91, 123)), in(ascii(toJSONString(events.properties.`$raw_user_agent`)), tuple(91, 123))), nullIf(nullIf(toJSONString(events.properties.`$raw_user_agent`), '[]'), '{}'), toString(events.properties.`$raw_user_agent`)))), ''), [/* 344 bot literals */])]) AS Category,
+ SELECT if(and(in(ifNull(toString(if(notEquals(toJSONString(events.properties.^`$lib`), '{}'), toJSONString(events.properties.^`$lib`), if(isNull(nullIf(toString(events.properties.`$lib`), '')), NULL, if(and(in(ascii(toString(events.properties.`$lib`)), tuple(91, 123)), in(ascii(toJSONString(events.properties.`$lib`)), tuple(91, 123))), nullIf(nullIf(toJSONString(events.properties.`$lib`), '[]'), '{}'), toString(events.properties.`$lib`))))), ''), tuple('posthog-node', 'posthog-node-mcp', 'posthog-edge', 'posthog-convex', 'posthog-python', 'posthog-python-mcp', 'posthog-ruby', 'posthog-rails', 'posthog-go', 'posthog-php', 'posthog-java', 'posthog-server', 'posthog-dotnet', 'posthog-aspnetcore', 'posthog-elixir', 'posthog-rs', 'posthog-roblox', 'posthog-ios', 'posthog-android', 'posthog-react-native', 'posthog-flutter', 'posthog-kmp', 'posthog-unity')), ifNull(equals(ifNull(if(notEquals(toJSONString(events.properties.^`$raw_user_agent`), '{}'), toJSONString(events.properties.^`$raw_user_agent`), if(isNull(nullIf(toString(events.properties.`$raw_user_agent`), '')), NULL, if(and(in(ascii(toString(events.properties.`$raw_user_agent`)), tuple(91, 123)), in(ascii(toJSONString(events.properties.`$raw_user_agent`)), tuple(91, 123))), nullIf(nullIf(toJSONString(events.properties.`$raw_user_agent`), '[]'), '{}'), toString(events.properties.`$raw_user_agent`)))), ''), ''), 0)), if(equals(multiIf(or(/* bot ip ranges */), 1, or(/* bot ip ranges */), 2, or(/* bot ip ranges */), 3, or(/* bot ip ranges */), 4, or(/* bot ip ranges */), 5, or(/* bot ip ranges */), 6, or(/* bot ip ranges */), 7, or(/* bot ip ranges */), 8, or(/* bot ip ranges */), 9, or(/* bot ip ranges */), 10, or(/* bot ip ranges */), 11, 0), 0), '', ['Googlebot', 'Google special crawler', 'Google fetcher', 'ChatGPT', 'OpenAI Search', 'GPTBot', 'Perplexity User', 'Perplexity', 'Bingbot', 'Applebot', 'Ahrefs'][multiIf(or(/* bot ip ranges */), 1, or(/* bot ip ranges */), 2, or(/* bot ip ranges */), 3, or(/* bot ip ranges */), 4, or(/* bot ip ranges */), 5, or(/* bot ip ranges */), 6, or(/* bot ip ranges */), 7, or(/* bot ip ranges */), 8, or(/* bot ip ranges */), 9, or(/* bot ip ranges */), 10, or(/* bot ip ranges */), 11, 0)]), if(ifNull(equals(multiMatchAnyIndex(ifNull(if(notEquals(toJSONString(events.properties.^`$raw_user_agent`), '{}'), toJSONString(events.properties.^`$raw_user_agent`), if(isNull(nullIf(toString(events.properties.`$raw_user_agent`), '')), NULL, if(and(in(ascii(toString(events.properties.`$raw_user_agent`)), tuple(91, 123)), in(ascii(toJSONString(events.properties.`$raw_user_agent`)), tuple(91, 123))), nullIf(nullIf(toJSONString(events.properties.`$raw_user_agent`), '[]'), '{}'), toString(events.properties.`$raw_user_agent`)))), ''), [/* 344 bot literals */]), 0), 0), if(equals(multiIf(or(/* bot ip ranges */), 1, or(/* bot ip ranges */), 2, or(/* bot ip ranges */), 3, or(/* bot ip ranges */), 4, or(/* bot ip ranges */), 5, or(/* bot ip ranges */), 6, or(/* bot ip ranges */), 7, or(/* bot ip ranges */), 8, or(/* bot ip ranges */), 9, or(/* bot ip ranges */), 10, or(/* bot ip ranges */), 11, 0), 0), '', ['Googlebot', 'Google special crawler', 'Google fetcher', 'ChatGPT', 'OpenAI Search', 'GPTBot', 'Perplexity User', 'Perplexity', 'Bingbot', 'Applebot', 'Ahrefs'][multiIf(or(/* bot ip ranges */), 1, or(/* bot ip ranges */), 2, or(/* bot ip ranges */), 3, or(/* bot ip ranges */), 4, or(/* bot ip ranges */), 5, or(/* bot ip ranges */), 6, or(/* bot ip ranges */), 7, or(/* bot ip ranges */), 8, or(/* bot ip ranges */), 9, or(/* bot ip ranges */), 10, or(/* bot ip ranges */), 11, 0)]), [/* 344 bot literals */][multiMatchAnyIndex(ifNull(if(notEquals(toJSONString(events.properties.^`$raw_user_agent`), '{}'), toJSONString(events.properties.^`$raw_user_agent`), if(isNull(nullIf(toString(events.properties.`$raw_user_agent`), '')), NULL, if(and(in(ascii(toString(events.properties.`$raw_user_agent`)), tuple(91, 123)), in(ascii(toJSONString(events.properties.`$raw_user_agent`)), tuple(91, 123))), nullIf(nullIf(toJSONString(events.properties.`$raw_user_agent`), '[]'), '{}'), toString(events.properties.`$raw_user_agent`)))), ''), [/* 344 bot literals */])])) AS Crawler,
+ if(and(in(ifNull(toString(if(notEquals(toJSONString(events.properties.^`$lib`), '{}'), toJSONString(events.properties.^`$lib`), if(isNull(nullIf(toString(events.properties.`$lib`), '')), NULL, if(and(in(ascii(toString(events.properties.`$lib`)), tuple(91, 123)), in(ascii(toJSONString(events.properties.`$lib`)), tuple(91, 123))), nullIf(nullIf(toJSONString(events.properties.`$lib`), '[]'), '{}'), toString(events.properties.`$lib`))))), ''), tuple('posthog-node', 'posthog-node-mcp', 'posthog-edge', 'posthog-convex', 'posthog-python', 'posthog-python-mcp', 'posthog-ruby', 'posthog-rails', 'posthog-go', 'posthog-php', 'posthog-java', 'posthog-server', 'posthog-dotnet', 'posthog-aspnetcore', 'posthog-elixir', 'posthog-rs', 'posthog-roblox', 'posthog-ios', 'posthog-android', 'posthog-react-native', 'posthog-flutter', 'posthog-kmp', 'posthog-unity')), ifNull(equals(ifNull(if(notEquals(toJSONString(events.properties.^`$raw_user_agent`), '{}'), toJSONString(events.properties.^`$raw_user_agent`), if(isNull(nullIf(toString(events.properties.`$raw_user_agent`), '')), NULL, if(and(in(ascii(toString(events.properties.`$raw_user_agent`)), tuple(91, 123)), in(ascii(toJSONString(events.properties.`$raw_user_agent`)), tuple(91, 123))), nullIf(nullIf(toJSONString(events.properties.`$raw_user_agent`), '[]'), '{}'), toString(events.properties.`$raw_user_agent`)))), ''), ''), 0)), if(equals(multiIf(or(/* bot ip ranges */), 1, or(/* bot ip ranges */), 2, or(/* bot ip ranges */), 3, or(/* bot ip ranges */), 4, or(/* bot ip ranges */), 5, or(/* bot ip ranges */), 6, or(/* bot ip ranges */), 7, or(/* bot ip ranges */), 8, or(/* bot ip ranges */), 9, or(/* bot ip ranges */), 10, or(/* bot ip ranges */), 11, 0), 0), 'regular', ['search_crawler', 'search_crawler', 'search_crawler', 'ai_assistant', 'ai_search', 'ai_crawler', 'ai_assistant', 'ai_search', 'search_crawler', 'ai_search', 'seo_crawler'][multiIf(or(/* bot ip ranges */), 1, or(/* bot ip ranges */), 2, or(/* bot ip ranges */), 3, or(/* bot ip ranges */), 4, or(/* bot ip ranges */), 5, or(/* bot ip ranges */), 6, or(/* bot ip ranges */), 7, or(/* bot ip ranges */), 8, or(/* bot ip ranges */), 9, or(/* bot ip ranges */), 10, or(/* bot ip ranges */), 11, 0)]), if(ifNull(equals(multiMatchAnyIndex(ifNull(if(notEquals(toJSONString(events.properties.^`$raw_user_agent`), '{}'), toJSONString(events.properties.^`$raw_user_agent`), if(isNull(nullIf(toString(events.properties.`$raw_user_agent`), '')), NULL, if(and(in(ascii(toString(events.properties.`$raw_user_agent`)), tuple(91, 123)), in(ascii(toJSONString(events.properties.`$raw_user_agent`)), tuple(91, 123))), nullIf(nullIf(toJSONString(events.properties.`$raw_user_agent`), '[]'), '{}'), toString(events.properties.`$raw_user_agent`)))), ''), [/* 344 bot literals */]), 0), 0), if(equals(multiIf(or(/* bot ip ranges */), 1, or(/* bot ip ranges */), 2, or(/* bot ip ranges */), 3, or(/* bot ip ranges */), 4, or(/* bot ip ranges */), 5, or(/* bot ip ranges */), 6, or(/* bot ip ranges */), 7, or(/* bot ip ranges */), 8, or(/* bot ip ranges */), 9, or(/* bot ip ranges */), 10, or(/* bot ip ranges */), 11, 0), 0), 'regular', ['search_crawler', 'search_crawler', 'search_crawler', 'ai_assistant', 'ai_search', 'ai_crawler', 'ai_assistant', 'ai_search', 'search_crawler', 'ai_search', 'seo_crawler'][multiIf(or(/* bot ip ranges */), 1, or(/* bot ip ranges */), 2, or(/* bot ip ranges */), 3, or(/* bot ip ranges */), 4, or(/* bot ip ranges */), 5, or(/* bot ip ranges */), 6, or(/* bot ip ranges */), 7, or(/* bot ip ranges */), 8, or(/* bot ip ranges */), 9, or(/* bot ip ranges */), 10, or(/* bot ip ranges */), 11, 0)]), [/* 344 bot literals */][multiMatchAnyIndex(ifNull(if(notEquals(toJSONString(events.properties.^`$raw_user_agent`), '{}'), toJSONString(events.properties.^`$raw_user_agent`), if(isNull(nullIf(toString(events.properties.`$raw_user_agent`), '')), NULL, if(and(in(ascii(toString(events.properties.`$raw_user_agent`)), tuple(91, 123)), in(ascii(toJSONString(events.properties.`$raw_user_agent`)), tuple(91, 123))), nullIf(nullIf(toJSONString(events.properties.`$raw_user_agent`), '[]'), '{}'), toString(events.properties.`$raw_user_agent`)))), ''), [/* 344 bot literals */])])) AS Category,
count() AS Requests,
max(toTimeZone(events.timestamp, 'UTC')) AS `Last seen`
FROM events_json AS events
- WHERE and(equals(events.team_id, 99999), and(ifNull(equals(accurateCastOrNull(or(ifNull(notEquals(multiMatchAnyIndex(ifNull(if(notEquals(toJSONString(events.properties.^`$raw_user_agent`), '{}'), toJSONString(events.properties.^`$raw_user_agent`), if(isNull(nullIf(toString(events.properties.`$raw_user_agent`), '')), NULL, if(and(in(ascii(toString(events.properties.`$raw_user_agent`)), tuple(91, 123)), in(ascii(toJSONString(events.properties.`$raw_user_agent`)), tuple(91, 123))), nullIf(nullIf(toJSONString(events.properties.`$raw_user_agent`), '[]'), '{}'), toString(events.properties.`$raw_user_agent`)))), ''), [/* 344 bot literals */]), 0), 1), or(/* bot ip ranges */)), 'Bool'), 1), 0), notEquals(if(ifNull(equals(multiMatchAnyIndex(ifNull(if(notEquals(toJSONString(events.properties.^`$raw_user_agent`), '{}'), toJSONString(events.properties.^`$raw_user_agent`), if(isNull(nullIf(toString(events.properties.`$raw_user_agent`), '')), NULL, if(and(in(ascii(toString(events.properties.`$raw_user_agent`)), tuple(91, 123)), in(ascii(toJSONString(events.properties.`$raw_user_agent`)), tuple(91, 123))), nullIf(nullIf(toJSONString(events.properties.`$raw_user_agent`), '[]'), '{}'), toString(events.properties.`$raw_user_agent`)))), ''), [/* 344 bot literals */]), 0), 0), if(equals(multiIf(or(/* bot ip ranges */), 1, or(/* bot ip ranges */), 2, or(/* bot ip ranges */), 3, or(/* bot ip ranges */), 4, or(/* bot ip ranges */), 5, or(/* bot ip ranges */), 6, or(/* bot ip ranges */), 7, or(/* bot ip ranges */), 8, or(/* bot ip ranges */), 9, or(/* bot ip ranges */), 10, or(/* bot ip ranges */), 11, 0), 0), '', ['Googlebot', 'Google special crawler', 'Google fetcher', 'ChatGPT', 'OpenAI Search', 'GPTBot', 'Perplexity User', 'Perplexity', 'Bingbot', 'Applebot', 'Ahrefs'][multiIf(or(/* bot ip ranges */), 1, or(/* bot ip ranges */), 2, or(/* bot ip ranges */), 3, or(/* bot ip ranges */), 4, or(/* bot ip ranges */), 5, or(/* bot ip ranges */), 6, or(/* bot ip ranges */), 7, or(/* bot ip ranges */), 8, or(/* bot ip ranges */), 9, or(/* bot ip ranges */), 10, or(/* bot ip ranges */), 11, 0)]), [/* 344 bot literals */][multiMatchAnyIndex(ifNull(if(notEquals(toJSONString(events.properties.^`$raw_user_agent`), '{}'), toJSONString(events.properties.^`$raw_user_agent`), if(isNull(nullIf(toString(events.properties.`$raw_user_agent`), '')), NULL, if(and(in(ascii(toString(events.properties.`$raw_user_agent`)), tuple(91, 123)), in(ascii(toJSONString(events.properties.`$raw_user_agent`)), tuple(91, 123))), nullIf(nullIf(toJSONString(events.properties.`$raw_user_agent`), '[]'), '{}'), toString(events.properties.`$raw_user_agent`)))), ''), [/* 344 bot literals */])]), ''), in(events.event, tuple('$pageview', '$screen', '$http_log')), or(and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2026-01-01 00:00:00', 'UTC'))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2026-01-31 23:59:59', 'UTC')))), 0), 1))
+ WHERE and(equals(events.team_id, 99999), and(ifNull(equals(accurateCastOrNull(or(and(not(and(in(ifNull(toString(if(notEquals(toJSONString(events.properties.^`$lib`), '{}'), toJSONString(events.properties.^`$lib`), if(isNull(nullIf(toString(events.properties.`$lib`), '')), NULL, if(and(in(ascii(toString(events.properties.`$lib`)), tuple(91, 123)), in(ascii(toJSONString(events.properties.`$lib`)), tuple(91, 123))), nullIf(nullIf(toJSONString(events.properties.`$lib`), '[]'), '{}'), toString(events.properties.`$lib`))))), ''), tuple('posthog-node', 'posthog-node-mcp', 'posthog-edge', 'posthog-convex', 'posthog-python', 'posthog-python-mcp', 'posthog-ruby', 'posthog-rails', 'posthog-go', 'posthog-php', 'posthog-java', 'posthog-server', 'posthog-dotnet', 'posthog-aspnetcore', 'posthog-elixir', 'posthog-rs', 'posthog-roblox', 'posthog-ios', 'posthog-android', 'posthog-react-native', 'posthog-flutter', 'posthog-kmp', 'posthog-unity')), ifNull(equals(ifNull(if(notEquals(toJSONString(events.properties.^`$raw_user_agent`), '{}'), toJSONString(events.properties.^`$raw_user_agent`), if(isNull(nullIf(toString(events.properties.`$raw_user_agent`), '')), NULL, if(and(in(ascii(toString(events.properties.`$raw_user_agent`)), tuple(91, 123)), in(ascii(toJSONString(events.properties.`$raw_user_agent`)), tuple(91, 123))), nullIf(nullIf(toJSONString(events.properties.`$raw_user_agent`), '[]'), '{}'), toString(events.properties.`$raw_user_agent`)))), ''), ''), 0))), ifNull(notEquals(multiMatchAnyIndex(ifNull(if(notEquals(toJSONString(events.properties.^`$raw_user_agent`), '{}'), toJSONString(events.properties.^`$raw_user_agent`), if(isNull(nullIf(toString(events.properties.`$raw_user_agent`), '')), NULL, if(and(in(ascii(toString(events.properties.`$raw_user_agent`)), tuple(91, 123)), in(ascii(toJSONString(events.properties.`$raw_user_agent`)), tuple(91, 123))), nullIf(nullIf(toJSONString(events.properties.`$raw_user_agent`), '[]'), '{}'), toString(events.properties.`$raw_user_agent`)))), ''), [/* 344 bot literals */]), 0), 1)), or(/* bot ip ranges */)), 'Bool'), 1), 0), notEquals(if(and(in(ifNull(toString(if(notEquals(toJSONString(events.properties.^`$lib`), '{}'), toJSONString(events.properties.^`$lib`), if(isNull(nullIf(toString(events.properties.`$lib`), '')), NULL, if(and(in(ascii(toString(events.properties.`$lib`)), tuple(91, 123)), in(ascii(toJSONString(events.properties.`$lib`)), tuple(91, 123))), nullIf(nullIf(toJSONString(events.properties.`$lib`), '[]'), '{}'), toString(events.properties.`$lib`))))), ''), tuple('posthog-node', 'posthog-node-mcp', 'posthog-edge', 'posthog-convex', 'posthog-python', 'posthog-python-mcp', 'posthog-ruby', 'posthog-rails', 'posthog-go', 'posthog-php', 'posthog-java', 'posthog-server', 'posthog-dotnet', 'posthog-aspnetcore', 'posthog-elixir', 'posthog-rs', 'posthog-roblox', 'posthog-ios', 'posthog-android', 'posthog-react-native', 'posthog-flutter', 'posthog-kmp', 'posthog-unity')), ifNull(equals(ifNull(if(notEquals(toJSONString(events.properties.^`$raw_user_agent`), '{}'), toJSONString(events.properties.^`$raw_user_agent`), if(isNull(nullIf(toString(events.properties.`$raw_user_agent`), '')), NULL, if(and(in(ascii(toString(events.properties.`$raw_user_agent`)), tuple(91, 123)), in(ascii(toJSONString(events.properties.`$raw_user_agent`)), tuple(91, 123))), nullIf(nullIf(toJSONString(events.properties.`$raw_user_agent`), '[]'), '{}'), toString(events.properties.`$raw_user_agent`)))), ''), ''), 0)), if(equals(multiIf(or(/* bot ip ranges */), 1, or(/* bot ip ranges */), 2, or(/* bot ip ranges */), 3, or(/* bot ip ranges */), 4, or(/* bot ip ranges */), 5, or(/* bot ip ranges */), 6, or(/* bot ip ranges */), 7, or(/* bot ip ranges */), 8, or(/* bot ip ranges */), 9, or(/* bot ip ranges */), 10, or(/* bot ip ranges */), 11, 0), 0), '', ['Googlebot', 'Google special crawler', 'Google fetcher', 'ChatGPT', 'OpenAI Search', 'GPTBot', 'Perplexity User', 'Perplexity', 'Bingbot', 'Applebot', 'Ahrefs'][multiIf(or(/* bot ip ranges */), 1, or(/* bot ip ranges */), 2, or(/* bot ip ranges */), 3, or(/* bot ip ranges */), 4, or(/* bot ip ranges */), 5, or(/* bot ip ranges */), 6, or(/* bot ip ranges */), 7, or(/* bot ip ranges */), 8, or(/* bot ip ranges */), 9, or(/* bot ip ranges */), 10, or(/* bot ip ranges */), 11, 0)]), if(ifNull(equals(multiMatchAnyIndex(ifNull(if(notEquals(toJSONString(events.properties.^`$raw_user_agent`), '{}'), toJSONString(events.properties.^`$raw_user_agent`), if(isNull(nullIf(toString(events.properties.`$raw_user_agent`), '')), NULL, if(and(in(ascii(toString(events.properties.`$raw_user_agent`)), tuple(91, 123)), in(ascii(toJSONString(events.properties.`$raw_user_agent`)), tuple(91, 123))), nullIf(nullIf(toJSONString(events.properties.`$raw_user_agent`), '[]'), '{}'), toString(events.properties.`$raw_user_agent`)))), ''), [/* 344 bot literals */]), 0), 0), if(equals(multiIf(or(/* bot ip ranges */), 1, or(/* bot ip ranges */), 2, or(/* bot ip ranges */), 3, or(/* bot ip ranges */), 4, or(/* bot ip ranges */), 5, or(/* bot ip ranges */), 6, or(/* bot ip ranges */), 7, or(/* bot ip ranges */), 8, or(/* bot ip ranges */), 9, or(/* bot ip ranges */), 10, or(/* bot ip ranges */), 11, 0), 0), '', ['Googlebot', 'Google special crawler', 'Google fetcher', 'ChatGPT', 'OpenAI Search', 'GPTBot', 'Perplexity User', 'Perplexity', 'Bingbot', 'Applebot', 'Ahrefs'][multiIf(or(/* bot ip ranges */), 1, or(/* bot ip ranges */), 2, or(/* bot ip ranges */), 3, or(/* bot ip ranges */), 4, or(/* bot ip ranges */), 5, or(/* bot ip ranges */), 6, or(/* bot ip ranges */), 7, or(/* bot ip ranges */), 8, or(/* bot ip ranges */), 9, or(/* bot ip ranges */), 10, or(/* bot ip ranges */), 11, 0)]), [/* 344 bot literals */][multiMatchAnyIndex(ifNull(if(notEquals(toJSONString(events.properties.^`$raw_user_agent`), '{}'), toJSONString(events.properties.^`$raw_user_agent`), if(isNull(nullIf(toString(events.properties.`$raw_user_agent`), '')), NULL, if(and(in(ascii(toString(events.properties.`$raw_user_agent`)), tuple(91, 123)), in(ascii(toJSONString(events.properties.`$raw_user_agent`)), tuple(91, 123))), nullIf(nullIf(toJSONString(events.properties.`$raw_user_agent`), '[]'), '{}'), toString(events.properties.`$raw_user_agent`)))), ''), [/* 344 bot literals */])])), ''), in(events.event, tuple('$pageview', '$screen', '$http_log')), or(and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2026-01-01 00:00:00', 'UTC'))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2026-01-31 23:59:59', 'UTC')))), 0), 1))
GROUP BY Crawler,
Category
ORDER BY Requests DESC
@@ -58,11 +58,11 @@
# name: TestWebBotsTableQueryRunner.test_only_bot_traffic_grouped_by_breakdown_1_Path[new_events_schema]
'''
SELECT if(notEquals(toJSONString(events.properties.^`$pathname`), '{}'), toJSONString(events.properties.^`$pathname`), if(isNull(nullIf(toString(events.properties.`$pathname`), '')), NULL, if(and(in(ascii(toString(events.properties.`$pathname`)), tuple(91, 123)), in(ascii(toJSONString(events.properties.`$pathname`)), tuple(91, 123))), nullIf(nullIf(toJSONString(events.properties.`$pathname`), '[]'), '{}'), toString(events.properties.`$pathname`)))) AS Path,
- count(DISTINCT if(ifNull(equals(multiMatchAnyIndex(ifNull(if(notEquals(toJSONString(events.properties.^`$raw_user_agent`), '{}'), toJSONString(events.properties.^`$raw_user_agent`), if(isNull(nullIf(toString(events.properties.`$raw_user_agent`), '')), NULL, if(and(in(ascii(toString(events.properties.`$raw_user_agent`)), tuple(91, 123)), in(ascii(toJSONString(events.properties.`$raw_user_agent`)), tuple(91, 123))), nullIf(nullIf(toJSONString(events.properties.`$raw_user_agent`), '[]'), '{}'), toString(events.properties.`$raw_user_agent`)))), ''), [/* 344 bot literals */]), 0), 0), if(equals(multiIf(or(/* bot ip ranges */), 1, or(/* bot ip ranges */), 2, or(/* bot ip ranges */), 3, or(/* bot ip ranges */), 4, or(/* bot ip ranges */), 5, or(/* bot ip ranges */), 6, or(/* bot ip ranges */), 7, or(/* bot ip ranges */), 8, or(/* bot ip ranges */), 9, or(/* bot ip ranges */), 10, or(/* bot ip ranges */), 11, 0), 0), '', ['Googlebot', 'Google special crawler', 'Google fetcher', 'ChatGPT', 'OpenAI Search', 'GPTBot', 'Perplexity User', 'Perplexity', 'Bingbot', 'Applebot', 'Ahrefs'][multiIf(or(/* bot ip ranges */), 1, or(/* bot ip ranges */), 2, or(/* bot ip ranges */), 3, or(/* bot ip ranges */), 4, or(/* bot ip ranges */), 5, or(/* bot ip ranges */), 6, or(/* bot ip ranges */), 7, or(/* bot ip ranges */), 8, or(/* bot ip ranges */), 9, or(/* bot ip ranges */), 10, or(/* bot ip ranges */), 11, 0)]), [/* 344 bot literals */][multiMatchAnyIndex(ifNull(if(notEquals(toJSONString(events.properties.^`$raw_user_agent`), '{}'), toJSONString(events.properties.^`$raw_user_agent`), if(isNull(nullIf(toString(events.properties.`$raw_user_agent`), '')), NULL, if(and(in(ascii(toString(events.properties.`$raw_user_agent`)), tuple(91, 123)), in(ascii(toJSONString(events.properties.`$raw_user_agent`)), tuple(91, 123))), nullIf(nullIf(toJSONString(events.properties.`$raw_user_agent`), '[]'), '{}'), toString(events.properties.`$raw_user_agent`)))), ''), [/* 344 bot literals */])])) AS Crawlers,
+ count(DISTINCT if(and(in(ifNull(toString(if(notEquals(toJSONString(events.properties.^`$lib`), '{}'), toJSONString(events.properties.^`$lib`), if(isNull(nullIf(toString(events.properties.`$lib`), '')), NULL, if(and(in(ascii(toString(events.properties.`$lib`)), tuple(91, 123)), in(ascii(toJSONString(events.properties.`$lib`)), tuple(91, 123))), nullIf(nullIf(toJSONString(events.properties.`$lib`), '[]'), '{}'), toString(events.properties.`$lib`))))), ''), tuple('posthog-node', 'posthog-node-mcp', 'posthog-edge', 'posthog-convex', 'posthog-python', 'posthog-python-mcp', 'posthog-ruby', 'posthog-rails', 'posthog-go', 'posthog-php', 'posthog-java', 'posthog-server', 'posthog-dotnet', 'posthog-aspnetcore', 'posthog-elixir', 'posthog-rs', 'posthog-roblox', 'posthog-ios', 'posthog-android', 'posthog-react-native', 'posthog-flutter', 'posthog-kmp', 'posthog-unity')), ifNull(equals(ifNull(if(notEquals(toJSONString(events.properties.^`$raw_user_agent`), '{}'), toJSONString(events.properties.^`$raw_user_agent`), if(isNull(nullIf(toString(events.properties.`$raw_user_agent`), '')), NULL, if(and(in(ascii(toString(events.properties.`$raw_user_agent`)), tuple(91, 123)), in(ascii(toJSONString(events.properties.`$raw_user_agent`)), tuple(91, 123))), nullIf(nullIf(toJSONString(events.properties.`$raw_user_agent`), '[]'), '{}'), toString(events.properties.`$raw_user_agent`)))), ''), ''), 0)), if(equals(multiIf(or(/* bot ip ranges */), 1, or(/* bot ip ranges */), 2, or(/* bot ip ranges */), 3, or(/* bot ip ranges */), 4, or(/* bot ip ranges */), 5, or(/* bot ip ranges */), 6, or(/* bot ip ranges */), 7, or(/* bot ip ranges */), 8, or(/* bot ip ranges */), 9, or(/* bot ip ranges */), 10, or(/* bot ip ranges */), 11, 0), 0), '', ['Googlebot', 'Google special crawler', 'Google fetcher', 'ChatGPT', 'OpenAI Search', 'GPTBot', 'Perplexity User', 'Perplexity', 'Bingbot', 'Applebot', 'Ahrefs'][multiIf(or(/* bot ip ranges */), 1, or(/* bot ip ranges */), 2, or(/* bot ip ranges */), 3, or(/* bot ip ranges */), 4, or(/* bot ip ranges */), 5, or(/* bot ip ranges */), 6, or(/* bot ip ranges */), 7, or(/* bot ip ranges */), 8, or(/* bot ip ranges */), 9, or(/* bot ip ranges */), 10, or(/* bot ip ranges */), 11, 0)]), if(ifNull(equals(multiMatchAnyIndex(ifNull(if(notEquals(toJSONString(events.properties.^`$raw_user_agent`), '{}'), toJSONString(events.properties.^`$raw_user_agent`), if(isNull(nullIf(toString(events.properties.`$raw_user_agent`), '')), NULL, if(and(in(ascii(toString(events.properties.`$raw_user_agent`)), tuple(91, 123)), in(ascii(toJSONString(events.properties.`$raw_user_agent`)), tuple(91, 123))), nullIf(nullIf(toJSONString(events.properties.`$raw_user_agent`), '[]'), '{}'), toString(events.properties.`$raw_user_agent`)))), ''), [/* 344 bot literals */]), 0), 0), if(equals(multiIf(or(/* bot ip ranges */), 1, or(/* bot ip ranges */), 2, or(/* bot ip ranges */), 3, or(/* bot ip ranges */), 4, or(/* bot ip ranges */), 5, or(/* bot ip ranges */), 6, or(/* bot ip ranges */), 7, or(/* bot ip ranges */), 8, or(/* bot ip ranges */), 9, or(/* bot ip ranges */), 10, or(/* bot ip ranges */), 11, 0), 0), '', ['Googlebot', 'Google special crawler', 'Google fetcher', 'ChatGPT', 'OpenAI Search', 'GPTBot', 'Perplexity User', 'Perplexity', 'Bingbot', 'Applebot', 'Ahrefs'][multiIf(or(/* bot ip ranges */), 1, or(/* bot ip ranges */), 2, or(/* bot ip ranges */), 3, or(/* bot ip ranges */), 4, or(/* bot ip ranges */), 5, or(/* bot ip ranges */), 6, or(/* bot ip ranges */), 7, or(/* bot ip ranges */), 8, or(/* bot ip ranges */), 9, or(/* bot ip ranges */), 10, or(/* bot ip ranges */), 11, 0)]), [/* 344 bot literals */][multiMatchAnyIndex(ifNull(if(notEquals(toJSONString(events.properties.^`$raw_user_agent`), '{}'), toJSONString(events.properties.^`$raw_user_agent`), if(isNull(nullIf(toString(events.properties.`$raw_user_agent`), '')), NULL, if(and(in(ascii(toString(events.properties.`$raw_user_agent`)), tuple(91, 123)), in(ascii(toJSONString(events.properties.`$raw_user_agent`)), tuple(91, 123))), nullIf(nullIf(toJSONString(events.properties.`$raw_user_agent`), '[]'), '{}'), toString(events.properties.`$raw_user_agent`)))), ''), [/* 344 bot literals */])]))) AS Crawlers,
count() AS Requests,
max(toTimeZone(events.timestamp, 'UTC')) AS `Last seen`
FROM events_json AS events
- WHERE and(equals(events.team_id, 99999), and(ifNull(equals(accurateCastOrNull(or(ifNull(notEquals(multiMatchAnyIndex(ifNull(if(notEquals(toJSONString(events.properties.^`$raw_user_agent`), '{}'), toJSONString(events.properties.^`$raw_user_agent`), if(isNull(nullIf(toString(events.properties.`$raw_user_agent`), '')), NULL, if(and(in(ascii(toString(events.properties.`$raw_user_agent`)), tuple(91, 123)), in(ascii(toJSONString(events.properties.`$raw_user_agent`)), tuple(91, 123))), nullIf(nullIf(toJSONString(events.properties.`$raw_user_agent`), '[]'), '{}'), toString(events.properties.`$raw_user_agent`)))), ''), [/* 344 bot literals */]), 0), 1), or(/* bot ip ranges */)), 'Bool'), 1), 0), notEquals(if(ifNull(equals(multiMatchAnyIndex(ifNull(if(notEquals(toJSONString(events.properties.^`$raw_user_agent`), '{}'), toJSONString(events.properties.^`$raw_user_agent`), if(isNull(nullIf(toString(events.properties.`$raw_user_agent`), '')), NULL, if(and(in(ascii(toString(events.properties.`$raw_user_agent`)), tuple(91, 123)), in(ascii(toJSONString(events.properties.`$raw_user_agent`)), tuple(91, 123))), nullIf(nullIf(toJSONString(events.properties.`$raw_user_agent`), '[]'), '{}'), toString(events.properties.`$raw_user_agent`)))), ''), [/* 344 bot literals */]), 0), 0), if(equals(multiIf(or(/* bot ip ranges */), 1, or(/* bot ip ranges */), 2, or(/* bot ip ranges */), 3, or(/* bot ip ranges */), 4, or(/* bot ip ranges */), 5, or(/* bot ip ranges */), 6, or(/* bot ip ranges */), 7, or(/* bot ip ranges */), 8, or(/* bot ip ranges */), 9, or(/* bot ip ranges */), 10, or(/* bot ip ranges */), 11, 0), 0), '', ['Googlebot', 'Google special crawler', 'Google fetcher', 'ChatGPT', 'OpenAI Search', 'GPTBot', 'Perplexity User', 'Perplexity', 'Bingbot', 'Applebot', 'Ahrefs'][multiIf(or(/* bot ip ranges */), 1, or(/* bot ip ranges */), 2, or(/* bot ip ranges */), 3, or(/* bot ip ranges */), 4, or(/* bot ip ranges */), 5, or(/* bot ip ranges */), 6, or(/* bot ip ranges */), 7, or(/* bot ip ranges */), 8, or(/* bot ip ranges */), 9, or(/* bot ip ranges */), 10, or(/* bot ip ranges */), 11, 0)]), [/* 344 bot literals */][multiMatchAnyIndex(ifNull(if(notEquals(toJSONString(events.properties.^`$raw_user_agent`), '{}'), toJSONString(events.properties.^`$raw_user_agent`), if(isNull(nullIf(toString(events.properties.`$raw_user_agent`), '')), NULL, if(and(in(ascii(toString(events.properties.`$raw_user_agent`)), tuple(91, 123)), in(ascii(toJSONString(events.properties.`$raw_user_agent`)), tuple(91, 123))), nullIf(nullIf(toJSONString(events.properties.`$raw_user_agent`), '[]'), '{}'), toString(events.properties.`$raw_user_agent`)))), ''), [/* 344 bot literals */])]), ''), in(events.event, tuple('$pageview', '$screen', '$http_log')), isNotNull(if(notEquals(toJSONString(events.properties.^`$pathname`), '{}'), toJSONString(events.properties.^`$pathname`), if(isNull(nullIf(toString(events.properties.`$pathname`), '')), NULL, if(and(in(ascii(toString(events.properties.`$pathname`)), tuple(91, 123)), in(ascii(toJSONString(events.properties.`$pathname`)), tuple(91, 123))), nullIf(nullIf(toJSONString(events.properties.`$pathname`), '[]'), '{}'), toString(events.properties.`$pathname`))))), or(and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2026-01-01 00:00:00', 'UTC'))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2026-01-31 23:59:59', 'UTC')))), 0), 1))
+ WHERE and(equals(events.team_id, 99999), and(ifNull(equals(accurateCastOrNull(or(and(not(and(in(ifNull(toString(if(notEquals(toJSONString(events.properties.^`$lib`), '{}'), toJSONString(events.properties.^`$lib`), if(isNull(nullIf(toString(events.properties.`$lib`), '')), NULL, if(and(in(ascii(toString(events.properties.`$lib`)), tuple(91, 123)), in(ascii(toJSONString(events.properties.`$lib`)), tuple(91, 123))), nullIf(nullIf(toJSONString(events.properties.`$lib`), '[]'), '{}'), toString(events.properties.`$lib`))))), ''), tuple('posthog-node', 'posthog-node-mcp', 'posthog-edge', 'posthog-convex', 'posthog-python', 'posthog-python-mcp', 'posthog-ruby', 'posthog-rails', 'posthog-go', 'posthog-php', 'posthog-java', 'posthog-server', 'posthog-dotnet', 'posthog-aspnetcore', 'posthog-elixir', 'posthog-rs', 'posthog-roblox', 'posthog-ios', 'posthog-android', 'posthog-react-native', 'posthog-flutter', 'posthog-kmp', 'posthog-unity')), ifNull(equals(ifNull(if(notEquals(toJSONString(events.properties.^`$raw_user_agent`), '{}'), toJSONString(events.properties.^`$raw_user_agent`), if(isNull(nullIf(toString(events.properties.`$raw_user_agent`), '')), NULL, if(and(in(ascii(toString(events.properties.`$raw_user_agent`)), tuple(91, 123)), in(ascii(toJSONString(events.properties.`$raw_user_agent`)), tuple(91, 123))), nullIf(nullIf(toJSONString(events.properties.`$raw_user_agent`), '[]'), '{}'), toString(events.properties.`$raw_user_agent`)))), ''), ''), 0))), ifNull(notEquals(multiMatchAnyIndex(ifNull(if(notEquals(toJSONString(events.properties.^`$raw_user_agent`), '{}'), toJSONString(events.properties.^`$raw_user_agent`), if(isNull(nullIf(toString(events.properties.`$raw_user_agent`), '')), NULL, if(and(in(ascii(toString(events.properties.`$raw_user_agent`)), tuple(91, 123)), in(ascii(toJSONString(events.properties.`$raw_user_agent`)), tuple(91, 123))), nullIf(nullIf(toJSONString(events.properties.`$raw_user_agent`), '[]'), '{}'), toString(events.properties.`$raw_user_agent`)))), ''), [/* 344 bot literals */]), 0), 1)), or(/* bot ip ranges */)), 'Bool'), 1), 0), notEquals(if(and(in(ifNull(toString(if(notEquals(toJSONString(events.properties.^`$lib`), '{}'), toJSONString(events.properties.^`$lib`), if(isNull(nullIf(toString(events.properties.`$lib`), '')), NULL, if(and(in(ascii(toString(events.properties.`$lib`)), tuple(91, 123)), in(ascii(toJSONString(events.properties.`$lib`)), tuple(91, 123))), nullIf(nullIf(toJSONString(events.properties.`$lib`), '[]'), '{}'), toString(events.properties.`$lib`))))), ''), tuple('posthog-node', 'posthog-node-mcp', 'posthog-edge', 'posthog-convex', 'posthog-python', 'posthog-python-mcp', 'posthog-ruby', 'posthog-rails', 'posthog-go', 'posthog-php', 'posthog-java', 'posthog-server', 'posthog-dotnet', 'posthog-aspnetcore', 'posthog-elixir', 'posthog-rs', 'posthog-roblox', 'posthog-ios', 'posthog-android', 'posthog-react-native', 'posthog-flutter', 'posthog-kmp', 'posthog-unity')), ifNull(equals(ifNull(if(notEquals(toJSONString(events.properties.^`$raw_user_agent`), '{}'), toJSONString(events.properties.^`$raw_user_agent`), if(isNull(nullIf(toString(events.properties.`$raw_user_agent`), '')), NULL, if(and(in(ascii(toString(events.properties.`$raw_user_agent`)), tuple(91, 123)), in(ascii(toJSONString(events.properties.`$raw_user_agent`)), tuple(91, 123))), nullIf(nullIf(toJSONString(events.properties.`$raw_user_agent`), '[]'), '{}'), toString(events.properties.`$raw_user_agent`)))), ''), ''), 0)), if(equals(multiIf(or(/* bot ip ranges */), 1, or(/* bot ip ranges */), 2, or(/* bot ip ranges */), 3, or(/* bot ip ranges */), 4, or(/* bot ip ranges */), 5, or(/* bot ip ranges */), 6, or(/* bot ip ranges */), 7, or(/* bot ip ranges */), 8, or(/* bot ip ranges */), 9, or(/* bot ip ranges */), 10, or(/* bot ip ranges */), 11, 0), 0), '', ['Googlebot', 'Google special crawler', 'Google fetcher', 'ChatGPT', 'OpenAI Search', 'GPTBot', 'Perplexity User', 'Perplexity', 'Bingbot', 'Applebot', 'Ahrefs'][multiIf(or(/* bot ip ranges */), 1, or(/* bot ip ranges */), 2, or(/* bot ip ranges */), 3, or(/* bot ip ranges */), 4, or(/* bot ip ranges */), 5, or(/* bot ip ranges */), 6, or(/* bot ip ranges */), 7, or(/* bot ip ranges */), 8, or(/* bot ip ranges */), 9, or(/* bot ip ranges */), 10, or(/* bot ip ranges */), 11, 0)]), if(ifNull(equals(multiMatchAnyIndex(ifNull(if(notEquals(toJSONString(events.properties.^`$raw_user_agent`), '{}'), toJSONString(events.properties.^`$raw_user_agent`), if(isNull(nullIf(toString(events.properties.`$raw_user_agent`), '')), NULL, if(and(in(ascii(toString(events.properties.`$raw_user_agent`)), tuple(91, 123)), in(ascii(toJSONString(events.properties.`$raw_user_agent`)), tuple(91, 123))), nullIf(nullIf(toJSONString(events.properties.`$raw_user_agent`), '[]'), '{}'), toString(events.properties.`$raw_user_agent`)))), ''), [/* 344 bot literals */]), 0), 0), if(equals(multiIf(or(/* bot ip ranges */), 1, or(/* bot ip ranges */), 2, or(/* bot ip ranges */), 3, or(/* bot ip ranges */), 4, or(/* bot ip ranges */), 5, or(/* bot ip ranges */), 6, or(/* bot ip ranges */), 7, or(/* bot ip ranges */), 8, or(/* bot ip ranges */), 9, or(/* bot ip ranges */), 10, or(/* bot ip ranges */), 11, 0), 0), '', ['Googlebot', 'Google special crawler', 'Google fetcher', 'ChatGPT', 'OpenAI Search', 'GPTBot', 'Perplexity User', 'Perplexity', 'Bingbot', 'Applebot', 'Ahrefs'][multiIf(or(/* bot ip ranges */), 1, or(/* bot ip ranges */), 2, or(/* bot ip ranges */), 3, or(/* bot ip ranges */), 4, or(/* bot ip ranges */), 5, or(/* bot ip ranges */), 6, or(/* bot ip ranges */), 7, or(/* bot ip ranges */), 8, or(/* bot ip ranges */), 9, or(/* bot ip ranges */), 10, or(/* bot ip ranges */), 11, 0)]), [/* 344 bot literals */][multiMatchAnyIndex(ifNull(if(notEquals(toJSONString(events.properties.^`$raw_user_agent`), '{}'), toJSONString(events.properties.^`$raw_user_agent`), if(isNull(nullIf(toString(events.properties.`$raw_user_agent`), '')), NULL, if(and(in(ascii(toString(events.properties.`$raw_user_agent`)), tuple(91, 123)), in(ascii(toJSONString(events.properties.`$raw_user_agent`)), tuple(91, 123))), nullIf(nullIf(toJSONString(events.properties.`$raw_user_agent`), '[]'), '{}'), toString(events.properties.`$raw_user_agent`)))), ''), [/* 344 bot literals */])])), ''), in(events.event, tuple('$pageview', '$screen', '$http_log')), isNotNull(if(notEquals(toJSONString(events.properties.^`$pathname`), '{}'), toJSONString(events.properties.^`$pathname`), if(isNull(nullIf(toString(events.properties.`$pathname`), '')), NULL, if(and(in(ascii(toString(events.properties.`$pathname`)), tuple(91, 123)), in(ascii(toJSONString(events.properties.`$pathname`)), tuple(91, 123))), nullIf(nullIf(toJSONString(events.properties.`$pathname`), '[]'), '{}'), toString(events.properties.`$pathname`))))), or(and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2026-01-01 00:00:00', 'UTC'))), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), assumeNotNull(toDateTime('2026-01-31 23:59:59', 'UTC')))), 0), 1))
GROUP BY Path
ORDER BY Requests DESC
LIMIT 51
diff --git a/products/web_analytics/backend/hogql_queries/test/test_web_lazy_precompute_common.py b/products/web_analytics/backend/hogql_queries/test/test_web_lazy_precompute_common.py
index b228023f8592..bfe281226b2b 100644
--- a/products/web_analytics/backend/hogql_queries/test/test_web_lazy_precompute_common.py
+++ b/products/web_analytics/backend/hogql_queries/test/test_web_lazy_precompute_common.py
@@ -41,6 +41,7 @@ from products.analytics_platform.backend.lazy_computation.lazy_computation_execu
LazyComputationResult,
TtlSchedule,
)
+from products.cohorts.backend.models.cohort import Cohort
from products.web_analytics.backend.hogql_queries.stats_table import WebStatsTableQueryRunner
from products.web_analytics.backend.hogql_queries.web_analytics_lazy_precompute import can_use_lazy_precompute
from products.web_analytics.backend.hogql_queries.web_lazy_precompute_common import (
@@ -82,6 +83,7 @@ from products.web_analytics.backend.hogql_queries.web_lazy_precompute_common imp
web_ensure_precomputed,
)
from products.web_analytics.backend.hogql_queries.web_overview import WebOverviewQueryRunner
+from products.web_analytics.backend.hogql_queries.web_overview_lazy_precompute import ensure_web_overview_precomputed
from products.web_analytics.backend.hogql_queries.web_stats_lazy_precompute import (
can_use_lazy_precompute as can_use_stats_lazy_precompute,
)
@@ -713,6 +715,54 @@ class TestWebEnsurePrecomputed(BaseTest):
{"traffic_classification": "cookieless-missing-ua-v1"} if enabled else None
)
+ @parameterized.expand(
+ [
+ ("no_bot_filter", [], {"traffic_classification": "cookieless-missing-ua-v1"}),
+ (
+ "bot_filter",
+ [EventPropertyFilter(key="$virt_is_bot", operator=PropertyOperator.EXACT, value=["false"])],
+ {"traffic_classification": "cookieless-missing-ua-v1+sdk-missing-ua-v1"},
+ ),
+ ]
+ )
+ @mock.patch(f"{_COMMON}.ensure_precomputed")
+ def test_only_queries_that_classify_traffic_get_a_new_hash(
+ self, _name: str, properties: list, expected: dict, mock_ensure: mock.Mock
+ ) -> None:
+ mock_ensure.return_value = LazyComputationResult(ready=True, job_ids=[])
+ runner = WebOverviewQueryRunner(
+ team=self.team,
+ query=_overview(properties=properties),
+ modifiers=HogQLQueryModifiers(cookielessTrafficIsRegular=True),
+ )
+ ensure_web_overview_precomputed(runner, datetime(2026, 1, 1, tzinfo=UTC), datetime(2026, 1, 8, tzinfo=UTC))
+ assert mock_ensure.call_args.kwargs["cache_key_context"] == expected
+
+ @mock.patch(f"{_COMMON}.ensure_precomputed")
+ def test_test_account_cohort_that_classifies_traffic_gets_a_new_hash(self, mock_ensure: mock.Mock) -> None:
+ mock_ensure.return_value = LazyComputationResult(ready=True, job_ids=[])
+ bot_leaf = {
+ "type": "behavioral",
+ "key": "$pageview",
+ "event_type": "events",
+ "value": "performed_event",
+ "event_filters": [{"key": "$virt_is_bot", "type": "event", "value": ["true"], "operator": "exact"}],
+ }
+ cohort = Cohort.objects.create(
+ team=self.team, name="bots", filters={"properties": {"type": "AND", "values": [bot_leaf]}}
+ )
+ self.team.test_account_filters = [{"key": "id", "type": "cohort", "value": cohort.pk, "operator": "not_in"}]
+ self.team.save()
+ runner = WebOverviewQueryRunner(
+ team=self.team,
+ query=_overview().model_copy(update={"filterTestAccounts": True}),
+ modifiers=HogQLQueryModifiers(cookielessTrafficIsRegular=True),
+ )
+ ensure_web_overview_precomputed(runner, datetime(2026, 1, 1, tzinfo=UTC), datetime(2026, 1, 8, tzinfo=UTC))
+ assert mock_ensure.call_args.kwargs["cache_key_context"] == {
+ "traffic_classification": "cookieless-missing-ua-v1+sdk-missing-ua-v1"
+ }
+
def tearDown(self):
redis.get_client().delete(_oom_pin_key(self.team.pk))
super().tearDown()
diff --git a/products/web_analytics/backend/hogql_queries/web_lazy_precompute_common.py b/products/web_analytics/backend/hogql_queries/web_lazy_precompute_common.py
index 9d733e662272..4cf8b923fe67 100644
--- a/products/web_analytics/backend/hogql_queries/web_lazy_precompute_common.py
+++ b/products/web_analytics/backend/hogql_queries/web_lazy_precompute_common.py
@@ -607,6 +607,16 @@ def handle_stale_served(*, runner: Any, family: str) -> None:
enqueue_stale_revalidation(team=runner.team, query=runner.query, family=family, debounce_extra=debounce_extra)
+# "InCohort" also matches NotInCohort. A cohort's criteria are expanded after this check and can
+# classify traffic, so any cohort filter counts, such as a cohort in the test-account filters.
+_TRAFFIC_CLASSIFICATION_NAMES = ("$virt_", "isLikelyBot", "getBot", "getTraffic", "__preview_", "InCohort")
+
+
+def _classifies_traffic(insert_query: Any, placeholders: Optional[dict[str, Any]]) -> bool:
+ text = repr(insert_query) + repr(placeholders)
+ return any(name in text for name in _TRAFFIC_CLASSIFICATION_NAMES)
+
+
def web_ensure_precomputed(
*, team: Team, shape_key_extra: Optional[str] = None, **kwargs: Any
) -> LazyComputationResult:
@@ -630,10 +640,17 @@ def web_ensure_precomputed(
# Use the runner's value, which can carry a per-query override, so the INSERT and the job hash match the read.
modifiers.cookielessTrafficIsRegular = runner.modifiers.cookielessTrafficIsRegular
kwargs["modifiers"] = modifiers
+ # The job hash covers the HogQL text, not what `$virt_*` expands to, so a classification change
+ # needs a new marker. Only queries that classify traffic get it, so other jobs keep their hash.
+ markers = []
if modifiers.cookielessTrafficIsRegular:
+ markers.append("cookieless-missing-ua-v1")
+ if _classifies_traffic(kwargs.get("insert_query"), kwargs.get("placeholders")):
+ markers.append("sdk-missing-ua-v1")
+ if markers:
kwargs["cache_key_context"] = {
**(kwargs.get("cache_key_context") or {}),
- "traffic_classification": "cookieless-missing-ua-v1",
+ "traffic_classification": "+".join(markers),
}
background = is_background_warming_request()
forced = is_forced_refresh_request()
diff --git a/products/web_analytics/skills/filtering-bot-traffic/SKILL.md b/products/web_analytics/skills/filtering-bot-traffic/SKILL.md
index 0903f00c74ff..a1dddb430399 100644
--- a/products/web_analytics/skills/filtering-bot-traffic/SKILL.md
+++ b/products/web_analytics/skills/filtering-bot-traffic/SKILL.md
@@ -52,19 +52,18 @@ so you don't pass anything in. Available wherever you pick an event property.
### HogQL functions (raw SQL)
-Pass the user agent explicitly. Use `coalesce(nullIf(properties.$raw_user_agent, ''), properties.$user_agent)`
-to cover both server-side (`$raw_user_agent`) and JS SDK (`$user_agent`) captures. The `nullIf`
-keeps an empty `$raw_user_agent` from shadowing a real `$user_agent` and being misread as a bot —
-this mirrors the expression the virtual properties use internally.
-
-| Function | Returns |
-| ------------------------ | ---------------------------------------------------------------------------- |
-| `isLikelyBot(ua)` | `true` if the UA matches a bot/automation pattern (empty UA counts as a bot) |
-| `getTrafficType(ua)` | `AI Agent` / `Bot` / `Automation` / `Regular` |
-| `getTrafficCategory(ua)` | subcategory; `regular` for humans |
-| `getBotType(ua)` | same subcategory but empty string for humans — handy for filtering |
-| `getBotName(ua)` | bot name; empty for humans |
-| `getBotOperator(ua)` | operator/company; empty for humans |
+Pass `properties.$raw_user_agent` (and optionally `properties.$ip`) as is, the same arguments the
+virtual properties use. Don't wrap it, e.g. in `coalesce(...)`: server and mobile SDK events (and
+cookieless events) are exempt from the empty-UA rule only when the argument is that plain field.
+
+| Function | Returns |
+| ------------------------ | --------------------------------------------------------------------- |
+| `isLikelyBot(ua)` | `true` on a bot pattern or empty UA (server/mobile SDK events exempt) |
+| `getTrafficType(ua)` | `AI Agent` / `Bot` / `Automation` / `Regular` |
+| `getTrafficCategory(ua)` | subcategory; `regular` for humans |
+| `getBotType(ua)` | same subcategory but empty string for humans — handy for filtering |
+| `getBotName(ua)` | bot name; empty for humans |
+| `getBotOperator(ua)` | operator/company; empty for humans |
## Traffic types — what to keep vs drop
@@ -135,16 +134,16 @@ which tools (OpenAI, Anthropic, Perplexity, …) read your site and which pages
SELECT count() AS human_pageviews
FROM events
WHERE event = '$pageview'
- AND NOT isLikelyBot(coalesce(nullIf(properties.$raw_user_agent, ''), properties.$user_agent))
+ AND NOT isLikelyBot(properties.$raw_user_agent)
-- top bots by hits
SELECT
- getBotName(coalesce(nullIf(properties.$raw_user_agent, ''), properties.$user_agent)) AS bot,
- getBotOperator(coalesce(nullIf(properties.$raw_user_agent, ''), properties.$user_agent)) AS operator,
+ getBotName(properties.$raw_user_agent) AS bot,
+ getBotOperator(properties.$raw_user_agent) AS operator,
count() AS hits
FROM events
WHERE event = '$pageview'
- AND isLikelyBot(coalesce(nullIf(properties.$raw_user_agent, ''), properties.$user_agent))
+ AND isLikelyBot(properties.$raw_user_agent)
GROUP BY bot, operator
ORDER BY hits DESC
```
@@ -196,8 +195,9 @@ the capture API) before building bot insights.
- **`isLikelyBot` is "likely".** Detection is a user-agent heuristic — some bots spoof
real browser UAs, and some legit tools use bot-like ones. Treat it as best-effort, not
ground truth.
-- **Empty user agent = bot.** Requests with no UA (server-to-server, misconfigured SDKs)
- classify as `Automation` / `no_user_agent`, so `isLikelyBot` returns `true`.
+- **Empty user agent = bot, except from server and mobile SDKs.** Events with no UA classify as
+ `Automation` / `no_user_agent`, unless `$lib` is a server or mobile SDK, which only sends a UA
+ when the app forwards one.
- **Don't silently drop the host filter.** If the user is scoped to one domain, inherit
`$host` in `properties` — leaving it out changes the answer.
- **Bot definitions evolve.** The detected-bot list changes over time, so re-running the