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.

feat(web-analytics): graduate bot detection hogql functions to GA (#64127)

Lucas Ricoy3f347df82842
diff --git a/frontend/src/lib/utils/botDetection.ts b/frontend/src/lib/utils/botDetection.ts
index 539cb4b8bc14..86255b657da7 100644
--- a/frontend/src/lib/utils/botDetection.ts
+++ b/frontend/src/lib/utils/botDetection.ts
@@ -1,6 +1,6 @@
/**
* Client-side bot detection — mirrors `posthog.hogql_queries.web_analytics.bot_definitions`
- * and the `__preview_getBotName` / `__preview_isBot` / `__preview_getTrafficCategory`
+ * and the `getBotName` / `isLikelyBot` / `getTrafficCategory`
* HogQL functions. Used by real-time dashboards where events arrive via the
* livestream SSE feed and therefore cannot be classified server-side.
*
diff --git a/posthog/hogql/database/schema/test/test_traffic_type.py b/posthog/hogql/database/schema/test/test_traffic_type.py
index 8980d83fc3fd..c3bce17e5f06 100644
--- a/posthog/hogql/database/schema/test/test_traffic_type.py
+++ b/posthog/hogql/database/schema/test/test_traffic_type.py
@@ -72,28 +72,36 @@ class TestExpressionFieldFactories:
class TestIsBotField:
- def test_returns_compare_operation(self):
+ def test_returns_bool_cast(self):
field = create_is_bot_field(name="$virt_is_bot")
- assert isinstance(field.expr, ast.CompareOperation)
- assert field.expr.op == ast.CompareOperationOp.NotEq
+ assert isinstance(field.expr, ast.Call)
+ assert field.expr.name == "toBool"
+ comparison = field.expr.args[0]
+ assert isinstance(comparison, ast.CompareOperation)
+ assert comparison.op == ast.CompareOperationOp.NotEq
def test_uses_multiMatchAnyIndex(self):
field = create_is_bot_field(name="$virt_is_bot")
- assert isinstance(field.expr, ast.CompareOperation)
- assert isinstance(field.expr.left, ast.Call)
- assert field.expr.left.name == "multiMatchAnyIndex"
+ assert isinstance(field.expr, ast.Call)
+ comparison = field.expr.args[0]
+ assert isinstance(comparison, ast.CompareOperation)
+ assert isinstance(comparison.left, ast.Call)
+ assert comparison.left.name == "multiMatchAnyIndex"
def test_compares_against_zero(self):
field = create_is_bot_field(name="$virt_is_bot")
- assert isinstance(field.expr, ast.CompareOperation)
- assert isinstance(field.expr.right, ast.Constant)
- assert field.expr.right.value == 0
+ assert isinstance(field.expr, ast.Call)
+ comparison = field.expr.args[0]
+ assert isinstance(comparison, ast.CompareOperation)
+ assert isinstance(comparison.right, ast.Constant)
+ assert comparison.right.value == 0
def test_wraps_user_agent_in_ifnull(self):
field = create_is_bot_field(name="$virt_is_bot")
- expr = field.expr
- assert isinstance(expr, ast.CompareOperation)
- index_call = expr.left
+ assert isinstance(field.expr, ast.Call)
+ comparison = field.expr.args[0]
+ assert isinstance(comparison, ast.CompareOperation)
+ index_call = comparison.left
assert isinstance(index_call, ast.Call)
safe_ua = index_call.args[0]
assert isinstance(safe_ua, ast.Call)
diff --git a/posthog/hogql/functions/posthog.py b/posthog/hogql/functions/posthog.py
index 824a192051d0..7397f12decb3 100644
--- a/posthog/hogql/functions/posthog.py
+++ b/posthog/hogql/functions/posthog.py
@@ -89,7 +89,14 @@ HOGQL_POSTHOG_FUNCTIONS: dict[str, HogQLFunctionMeta] = {
((StringType(), DateTimeType(), DateTimeType()), StringType()),
],
),
- # traffic type classification functions (experimental)
+ # Bot / traffic-type classification functions.
+ "getTrafficType": HogQLFunctionMeta("getTrafficType", 1, 1, signatures=[((StringType(),), StringType())]),
+ "getTrafficCategory": HogQLFunctionMeta("getTrafficCategory", 1, 1, signatures=[((StringType(),), StringType())]),
+ "isLikelyBot": HogQLFunctionMeta("isLikelyBot", 1, 1, signatures=[((StringType(),), BooleanType())]),
+ "getBotType": HogQLFunctionMeta("getBotType", 1, 1, signatures=[((StringType(),), StringType())]),
+ "getBotName": HogQLFunctionMeta("getBotName", 1, 1, signatures=[((StringType(),), StringType())]),
+ "getBotOperator": HogQLFunctionMeta("getBotOperator", 1, 1, signatures=[((StringType(),), StringType())]),
+ # Deprecated __preview_* aliases — kept so ad-hoc queries written against the preview names keep working.
"__preview_getTrafficType": HogQLFunctionMeta(
"__preview_getTrafficType", 1, 1, signatures=[((StringType(),), StringType())]
),
diff --git a/posthog/hogql/functions/test/test_traffic_type_functions.py b/posthog/hogql/functions/test/test_traffic_type_functions.py
index aaec26684433..fed5978d55c4 100644
--- a/posthog/hogql/functions/test/test_traffic_type_functions.py
+++ b/posthog/hogql/functions/test/test_traffic_type_functions.py
@@ -22,7 +22,7 @@ from products.web_analytics.backend.hogql_queries.bot_definitions import BOT_DEF
class TestTrafficTypeFunctions:
def test_get_traffic_type_returns_if_with_array_lookup(self):
- node = ast.Call(name="__preview_getTrafficType", args=[])
+ node = ast.Call(name="getTrafficType", args=[])
user_agent_arg = ast.Field(chain=["properties", "$user_agent"])
result = get_traffic_type(node=node, args=[user_agent_arg])
@@ -39,7 +39,7 @@ class TestTrafficTypeFunctions:
assert isinstance(result.args[2], ast.ArrayAccess)
def test_get_traffic_type_uses_multiMatchAnyIndex(self):
- node = ast.Call(name="__preview_getTrafficType", args=[])
+ node = ast.Call(name="getTrafficType", args=[])
user_agent_arg = ast.Field(chain=["properties", "$user_agent"])
result = get_traffic_type(node=node, args=[user_agent_arg])
@@ -52,7 +52,7 @@ class TestTrafficTypeFunctions:
assert comparison.left.name == "multiMatchAnyIndex"
def test_get_traffic_type_has_correct_patterns_and_labels(self):
- node = ast.Call(name="__preview_getTrafficType", args=[])
+ node = ast.Call(name="getTrafficType", args=[])
user_agent_arg = ast.Field(chain=["properties", "$user_agent"])
result = get_traffic_type(node=node, args=[user_agent_arg])
@@ -83,7 +83,7 @@ class TestTrafficTypeFunctions:
assert "Automation" in label_values # For empty UA
def test_get_traffic_category_returns_if_with_array_lookup(self):
- node = ast.Call(name="__preview_getTrafficCategory", args=[])
+ node = ast.Call(name="getTrafficCategory", args=[])
user_agent_arg = ast.Field(chain=["properties", "$user_agent"])
result = get_traffic_category(node=node, args=[user_agent_arg])
@@ -97,7 +97,7 @@ class TestTrafficTypeFunctions:
assert default_arg.value == "regular"
def test_get_traffic_category_returns_expected_values(self):
- node = ast.Call(name="__preview_getTrafficCategory", args=[])
+ node = ast.Call(name="getTrafficCategory", args=[])
user_agent_arg = ast.Field(chain=["properties", "$user_agent"])
result = get_traffic_category(node=node, args=[user_agent_arg])
@@ -120,37 +120,44 @@ class TestTrafficTypeFunctions:
class TestIsBotFunction:
- def test_is_bot_returns_compare_operation(self):
- node = ast.Call(name="__preview_isBot", args=[])
+ def test_is_bot_returns_bool_cast(self):
+ node = ast.Call(name="isLikelyBot", args=[])
user_agent_arg = ast.Field(chain=["properties", "$user_agent"])
result = is_bot(node=node, args=[user_agent_arg])
- assert isinstance(result, ast.CompareOperation)
- assert result.op == ast.CompareOperationOp.NotEq
+ assert isinstance(result, ast.Call)
+ assert result.name == "toBool"
+ comparison = result.args[0]
+ assert isinstance(comparison, ast.CompareOperation)
+ assert comparison.op == ast.CompareOperationOp.NotEq
def test_is_bot_uses_multiMatchAnyIndex(self):
- node = ast.Call(name="__preview_isBot", args=[])
+ node = ast.Call(name="isLikelyBot", args=[])
user_agent_arg = ast.Field(chain=["properties", "$user_agent"])
result = is_bot(node=node, args=[user_agent_arg])
- assert isinstance(result, ast.CompareOperation)
- assert isinstance(result.left, ast.Call)
- assert result.left.name == "multiMatchAnyIndex"
+ assert isinstance(result, ast.Call)
+ comparison = result.args[0]
+ assert isinstance(comparison, ast.CompareOperation)
+ assert isinstance(comparison.left, ast.Call)
+ assert comparison.left.name == "multiMatchAnyIndex"
def test_is_bot_compares_against_zero(self):
- node = ast.Call(name="__preview_isBot", args=[])
+ node = ast.Call(name="isLikelyBot", args=[])
user_agent_arg = ast.Field(chain=["properties", "$user_agent"])
result = is_bot(node=node, args=[user_agent_arg])
- assert isinstance(result, ast.CompareOperation)
- assert isinstance(result.right, ast.Constant)
- assert result.right.value == 0
+ assert isinstance(result, ast.Call)
+ comparison = result.args[0]
+ assert isinstance(comparison, ast.CompareOperation)
+ assert isinstance(comparison.right, ast.Constant)
+ assert comparison.right.value == 0
class TestGetBotTypeFunction:
def test_get_bot_type_returns_if_with_array_lookup(self):
- node = ast.Call(name="__preview_getBotType", args=[])
+ node = ast.Call(name="getBotType", args=[])
user_agent_arg = ast.Field(chain=["properties", "$user_agent"])
result = get_bot_type(node=node, args=[user_agent_arg])
@@ -164,7 +171,7 @@ class TestGetBotTypeFunction:
assert default_arg.value == ""
def test_get_bot_type_returns_expected_values(self):
- node = ast.Call(name="__preview_getBotType", args=[])
+ node = ast.Call(name="getBotType", args=[])
user_agent_arg = ast.Field(chain=["properties", "$user_agent"])
result = get_bot_type(node=node, args=[user_agent_arg])
@@ -192,7 +199,7 @@ class TestGetBotTypeFunction:
class TestGetBotNameFunction:
def test_get_bot_name_returns_if_with_array_lookup(self):
- node = ast.Call(name="__preview_getBotName", args=[])
+ node = ast.Call(name="getBotName", args=[])
user_agent_arg = ast.Field(chain=["properties", "$user_agent"])
result = get_bot_name(node=node, args=[user_agent_arg])
@@ -206,7 +213,7 @@ class TestGetBotNameFunction:
assert default_arg.value == ""
def test_get_bot_name_returns_expected_values(self):
- node = ast.Call(name="__preview_getBotName", args=[])
+ node = ast.Call(name="getBotName", args=[])
user_agent_arg = ast.Field(chain=["properties", "$user_agent"])
result = get_bot_name(node=node, args=[user_agent_arg])
@@ -283,12 +290,14 @@ class TestTrafficTypeFunctionPatterns:
assert safe_user_agent.args[0] == user_agent_arg
def test_is_bot_preserves_user_agent_expression(self):
- node = ast.Call(name="__preview_isBot", args=[])
+ node = ast.Call(name="isLikelyBot", args=[])
user_agent_arg = ast.Field(chain=["custom", "user_agent_field"])
result = is_bot(node=node, args=[user_agent_arg])
- assert isinstance(result, ast.CompareOperation)
- index_call = result.left
+ assert isinstance(result, ast.Call)
+ comparison = result.args[0]
+ assert isinstance(comparison, ast.CompareOperation)
+ index_call = comparison.left
assert isinstance(index_call, ast.Call)
assert index_call.name == "multiMatchAnyIndex"
safe_user_agent = index_call.args[0]
@@ -299,7 +308,7 @@ class TestTrafficTypeFunctionPatterns:
class TestNullHandling:
def test_build_bot_array_lookup_wraps_user_agent_in_ifnull(self):
- node = ast.Call(name="__preview_getTrafficType", args=[])
+ node = ast.Call(name="getTrafficType", args=[])
user_agent_arg = ast.Field(chain=["properties", "$user_agent"])
result = get_traffic_type(node=node, args=[user_agent_arg])
@@ -321,13 +330,15 @@ class TestNullHandling:
assert empty_string_arg.value == ""
def test_is_bot_wraps_user_agent_in_ifnull(self):
- node = ast.Call(name="__preview_isBot", args=[])
+ node = ast.Call(name="isLikelyBot", args=[])
user_agent_arg = ast.Field(chain=["properties", "$user_agent"])
result = is_bot(node=node, args=[user_agent_arg])
- assert isinstance(result, ast.CompareOperation)
+ assert isinstance(result, ast.Call)
+ comparison = result.args[0]
+ assert isinstance(comparison, ast.CompareOperation)
- index_call = result.left
+ index_call = comparison.left
assert isinstance(index_call, ast.Call)
safe_user_agent = index_call.args[0]
assert isinstance(safe_user_agent, ast.Call)
diff --git a/posthog/hogql/functions/test/test_traffic_type_real_ua.py b/posthog/hogql/functions/test/test_traffic_type_real_ua.py
index deeb0894a0a0..3f7d9bb4c493 100644
--- a/posthog/hogql/functions/test/test_traffic_type_real_ua.py
+++ b/posthog/hogql/functions/test/test_traffic_type_real_ua.py
@@ -122,10 +122,10 @@ class TestTrafficTypeIntegration(BaseTest):
response = self._query_tagged(
"""
properties.$user_agent as ua,
- __preview_isBot(properties.$user_agent) as is_bot,
- __preview_getTrafficType(properties.$user_agent) as traffic_type,
- __preview_getTrafficCategory(properties.$user_agent) as category,
- __preview_getBotName(properties.$user_agent) as bot_name
+ isLikelyBot(properties.$user_agent) as is_bot,
+ getTrafficType(properties.$user_agent) as traffic_type,
+ getTrafficCategory(properties.$user_agent) as category,
+ getBotName(properties.$user_agent) as bot_name
""",
tag,
)
diff --git a/posthog/hogql/functions/traffic_type.py b/posthog/hogql/functions/traffic_type.py
index 7940da25127b..71962dec80a8 100644
--- a/posthog/hogql/functions/traffic_type.py
+++ b/posthog/hogql/functions/traffic_type.py
@@ -1,16 +1,13 @@
"""
Traffic type classification functions for HogQL.
-EXPERIMENTAL: These functions are prefixed with __preview_ to indicate they are
-experimental and may change without notice. The patterns and return values may
-be adjusted as we gather more data on real-world traffic classification accuracy.
-
-These are implemented as HogQL functions (rather than hardcoded in specific query
-runners) to provide maximum flexibility during development. This allows usage in:
+Implemented as HogQL functions (rather than hardcoded in specific query runners) so they
+can be used anywhere HogQL runs:
- SQL editor for ad-hoc analysis and exploration
- HogQLQuery runner for custom dashboards and insights
- Trends and other query runners when filtering/grouping by traffic type
-- Any future features that leverage HogQL expressions
+
+The legacy __preview_* names still resolve as deprecated aliases.
Bot definitions (patterns, categories, names) live in
products.web_analytics.backend.hogql_queries.bot_definitions so that changes to
@@ -67,9 +64,7 @@ def _build_bot_array_lookup(
def get_bot_name(node: ast.Call, args: list[ast.Expr]) -> ast.Expr:
"""
- HogQL function: __preview_getBotName(user_agent)
-
- EXPERIMENTAL: This function may change without notice.
+ HogQL function: getBotName(user_agent)
Returns bot name: "Googlebot", "ChatGPT", etc. Empty string for regular traffic.
"""
@@ -78,9 +73,7 @@ def get_bot_name(node: ast.Call, args: list[ast.Expr]) -> ast.Expr:
def get_bot_operator(node: ast.Call, args: list[ast.Expr]) -> ast.Expr:
"""
- HogQL function: __preview_getBotOperator(user_agent)
-
- EXPERIMENTAL: This function may change without notice.
+ HogQL function: getBotOperator(user_agent)
Returns operator/company name: "Google", "OpenAI", "Anthropic", etc. Empty string for regular traffic.
"""
@@ -89,9 +82,7 @@ def get_bot_operator(node: ast.Call, args: list[ast.Expr]) -> ast.Expr:
def get_traffic_type(node: ast.Call, args: list[ast.Expr]) -> ast.Expr:
"""
- HogQL function: __preview_getTrafficType(user_agent)
-
- EXPERIMENTAL: This function may change without notice.
+ HogQL function: getTrafficType(user_agent)
Returns one of: 'AI Agent', 'Bot', 'Automation', 'Regular'
"""
@@ -100,9 +91,7 @@ def get_traffic_type(node: ast.Call, args: list[ast.Expr]) -> ast.Expr:
def get_traffic_category(node: ast.Call, args: list[ast.Expr]) -> ast.Expr:
"""
- HogQL function: __preview_getTrafficCategory(user_agent)
-
- EXPERIMENTAL: This function may change without notice.
+ HogQL function: getTrafficCategory(user_agent)
Returns subcategory: 'ai_crawler', 'ai_search', 'ai_assistant', 'search_crawler', 'seo_crawler', etc.
For regular traffic, returns 'regular'.
@@ -112,9 +101,7 @@ def get_traffic_category(node: ast.Call, args: list[ast.Expr]) -> ast.Expr:
def is_bot(node: ast.Call, args: list[ast.Expr]) -> ast.Expr:
"""
- HogQL function: __preview_isBot(user_agent)
-
- EXPERIMENTAL: This function may change without notice.
+ HogQL function: isLikelyBot(user_agent)
Returns true if the user agent matches bot/automation patterns, false otherwise.
NULL user agents are treated as bots (empty UA is considered automation).
@@ -130,18 +117,22 @@ def is_bot(node: ast.Call, args: list[ast.Expr]) -> ast.Expr:
index_call = ast.Call(name="multiMatchAnyIndex", args=[safe_user_agent, patterns_array])
- return ast.CompareOperation(
- op=ast.CompareOperationOp.NotEq,
- left=index_call,
- right=ast.Constant(value=0),
+ # Cast to Bool so results render as true/false (not 0/1) in insights breakdowns.
+ return ast.Call(
+ name="toBool",
+ args=[
+ ast.CompareOperation(
+ op=ast.CompareOperationOp.NotEq,
+ left=index_call,
+ right=ast.Constant(value=0),
+ )
+ ],
)
def get_bot_type(node: ast.Call, args: list[ast.Expr]) -> ast.Expr:
"""
- HogQL function: __preview_getBotType(user_agent)
-
- EXPERIMENTAL: This function may change without notice.
+ HogQL function: getBotType(user_agent)
Returns the bot category or empty string for regular traffic.
Categories: 'ai_crawler', 'ai_search', 'ai_assistant', 'search_crawler', 'seo_crawler',
diff --git a/posthog/hogql/resolver.py b/posthog/hogql/resolver.py
index f65d2a24c0f3..7b3a3dc914c1 100644
--- a/posthog/hogql/resolver.py
+++ b/posthog/hogql/resolver.py
@@ -1575,19 +1575,19 @@ class Resolver(CloningVisitor):
return self.visit(
unique_survey_submissions_filter(node=node, args=node.args, team_id=self.context.team_id)
)
- if node.name == "__preview_isBot":
+ if node.name in ("isLikelyBot", "__preview_isBot"):
return self.visit(is_bot(node=node, args=node.args))
# The bot-lookup builders below duplicate their argument, so they must expand under the
# re-entrancy guard to bound nested expansion (see _expand_duplicating_macro).
- if node.name == "__preview_getTrafficType":
+ if node.name in ("getTrafficType", "__preview_getTrafficType"):
return self._expand_duplicating_macro(node, lambda: get_traffic_type(node=node, args=node.args))
- if node.name == "__preview_getTrafficCategory":
+ if node.name in ("getTrafficCategory", "__preview_getTrafficCategory"):
return self._expand_duplicating_macro(node, lambda: get_traffic_category(node=node, args=node.args))
- if node.name == "__preview_getBotType":
+ if node.name in ("getBotType", "__preview_getBotType"):
return self._expand_duplicating_macro(node, lambda: get_bot_type(node=node, args=node.args))
- if node.name == "__preview_getBotName":
+ if node.name in ("getBotName", "__preview_getBotName"):
return self._expand_duplicating_macro(node, lambda: get_bot_name(node=node, args=node.args))
- if node.name == "__preview_getBotOperator":
+ if node.name in ("getBotOperator", "__preview_getBotOperator"):
return self._expand_duplicating_macro(node, lambda: get_bot_operator(node=node, args=node.args))
if self._is_higher_order_array_call(node):
diff --git a/posthog/management/commands/generate_bot_demo_data.py b/posthog/management/commands/generate_bot_demo_data.py
index b79a5af1ba62..ad69fdfae2c0 100644
--- a/posthog/management/commands/generate_bot_demo_data.py
+++ b/posthog/management/commands/generate_bot_demo_data.py
@@ -217,13 +217,13 @@ class Command(BaseCommand):
self.stdout.write("\nTo verify, run these queries in the SQL editor:")
self.stdout.write(
"""
-SELECT __preview_getTrafficType(properties.$user_agent) as traffic_type, count()
+SELECT getTrafficType(properties.$user_agent) as traffic_type, count()
FROM events
WHERE properties.$lib = 'bot-demo-generator'
GROUP BY traffic_type
ORDER BY count() DESC
-SELECT __preview_getTrafficCategory(properties.$user_agent) as category, count()
+SELECT getTrafficCategory(properties.$user_agent) as category, count()
FROM events
WHERE properties.$lib = 'bot-demo-generator'
GROUP BY category
diff --git a/products/data_warehouse/backend/test/__snapshots__/test_hogql_fixer_ai.ambr b/products/data_warehouse/backend/test/__snapshots__/test_hogql_fixer_ai.ambr
index 083cd45384a4..f52f411cb6a9 100644
--- a/products/data_warehouse/backend/test/__snapshots__/test_hogql_fixer_ai.ambr
+++ b/products/data_warehouse/backend/test/__snapshots__/test_hogql_fixer_ai.ambr
@@ -75,7 +75,7 @@
And lastly these are some HogQL specific functions:
```
- ['matchesAction', 'sparkline', 'recordingButton', 'explainCSPReport', 'sortablesemver', 'embedText', 'lookupDomainType', 'lookupPaidSourceType', 'lookupPaidMediumType', 'lookupOrganicSourceType', 'lookupOrganicMediumType', 'convertCurrency', 'getSurveyResponse', 'uniqueSurveySubmissionsFilter']
+ ['matchesAction', 'sparkline', 'recordingButton', 'explainCSPReport', 'sortablesemver', 'embedText', 'lookupDomainType', 'lookupPaidSourceType', 'lookupPaidMediumType', 'lookupOrganicSourceType', 'lookupOrganicMediumType', 'convertCurrency', 'getSurveyResponse', 'uniqueSurveySubmissionsFilter', 'getTrafficType', 'getTrafficCategory', 'isLikelyBot', 'getBotType', 'getBotName', 'getBotOperator']
```
You fix HogQL errors that may come from either HogQL resolver errors or clickhouse execution errors. You don't help with other knowledge.
diff --git a/products/web_analytics/backend/hogql_queries/test/__snapshots__/test_traffic_type_snapshot.ambr b/products/web_analytics/backend/hogql_queries/test/__snapshots__/test_traffic_type_snapshot.ambr
index 4d90da159186..ceea93a6b39e 100644
--- a/products/web_analytics/backend/hogql_queries/test/__snapshots__/test_traffic_type_snapshot.ambr
+++ b/products/web_analytics/backend/hogql_queries/test/__snapshots__/test_traffic_type_snapshot.ambr
@@ -8,7 +8,7 @@
FROM
events
WHERE
- and(equals(events.team_id, 99999), equals(events.event, %(hogql_val_1)s), not(ifNull(notEquals(multiMatchAnyIndex(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, %(hogql_val_2)s), ''), 'null'), '^"|"$', ''), %(hogql_val_3)s), [%(hogql_val_4)s, %(hogql_val_5)s, %(hogql_val_6)s, %(hogql_val_7)s, %(hogql_val_8)s, %(hogql_val_9)s, %(hogql_val_10)s, %(hogql_val_11)s, %(hogql_val_12)s, %(hogql_val_13)s, %(hogql_val_14)s, %(hogql_val_15)s, %(hogql_val_16)s, %(hogql_val_17)s, %(hogql_val_18)s, %(hogql_val_19)s, %(hogql_val_20)s, %(hogql_val_21)s, %(hogql_val_22)s, %(hogql_val_23)s, %(hogql_val_24)s, %(hogql_val_25)s, %(hogql_val_26)s, %(hogql_val_27)s, %(hogql_val_28)s, %(hogql_val_29)s, %(hogql_val_30)s, %(hogql_val_31)s, %(hogql_val_32)s, %(hogql_val_33)s, %(hogql_val_34)s, %(hogql_val_35)s, %(hogql_val_36)s, %(hogql_val_37)s, %(hogql_val_38)s, %(hogql_val_39)s, %(hogql_val_40)s, %(hogql_val_41)s, %(hogql_val_42)s, %(hogql_val_43)s, %(hogql_val_44)s, %(hogql_val_45)s, %(hogql_val_46)s, %(hogql_val_47)s, %(hogql_val_48)s, %(hogql_val_49)s, %(hogql_val_50)s, %(hogql_val_51)s, %(hogql_val_52)s, %(hogql_val_53)s, %(hogql_val_54)s, %(hogql_val_55)s, %(hogql_val_56)s, %(hogql_val_57)s, %(hogql_val_58)s, %(hogql_val_59)s, %(hogql_val_60)s, %(hogql_val_61)s, %(hogql_val_62)s, %(hogql_val_63)s, %(hogql_val_64)s, %(hogql_val_65)s, %(hogql_val_66)s, %(hogql_val_67)s, %(hogql_val_68)s, %(hogql_val_69)s, %(hogql_val_70)s, %(hogql_val_71)s, %(hogql_val_72)s, %(hogql_val_73)s, %(hogql_val_74)s, %(hogql_val_75)s, %(hogql_val_76)s, %(hogql_val_77)s, %(hogql_val_78)s, %(hogql_val_79)s, %(hogql_val_80)s, %(hogql_val_81)s, %(hogql_val_82)s, %(hogql_val_83)s, %(hogql_val_84)s, %(hogql_val_85)s, %(hogql_val_86)s, %(hogql_val_87)s, %(hogql_val_88)s, %(hogql_val_89)s, %(hogql_val_90)s, %(hogql_val_91)s, %(hogql_val_92)s, %(hogql_val_93)s, %(hogql_val_94)s, %(hogql_val_95)s, %(hogql_val_96)s, %(hogql_val_97)s, %(hogql_val_98)s, %(hogql_val_99)s, %(hogql_val_100)s, %(hogql_val_101)s, %(hogql_val_102)s, %(hogql_val_103)s, %(hogql_val_104)s, %(hogql_val_105)s, %(hogql_val_106)s, %(hogql_val_107)s, %(hogql_val_108)s, %(hogql_val_109)s, %(hogql_val_110)s, %(hogql_val_111)s, %(hogql_val_112)s, %(hogql_val_113)s, %(hogql_val_114)s, %(hogql_val_115)s, %(hogql_val_116)s, %(hogql_val_117)s, %(hogql_val_118)s, %(hogql_val_119)s, %(hogql_val_120)s, %(hogql_val_121)s, %(hogql_val_122)s, %(hogql_val_123)s, %(hogql_val_124)s, %(hogql_val_125)s, %(hogql_val_126)s, %(hogql_val_127)s, %(hogql_val_128)s, %(hogql_val_129)s, %(hogql_val_130)s, %(hogql_val_131)s, %(hogql_val_132)s, %(hogql_val_133)s, %(hogql_val_134)s, %(hogql_val_135)s, %(hogql_val_136)s, %(hogql_val_137)s, %(hogql_val_138)s, %(hogql_val_139)s, %(hogql_val_140)s, %(hogql_val_141)s, %(hogql_val_142)s, %(hogql_val_143)s, %(hogql_val_144)s, %(hogql_val_145)s, %(hogql_val_146)s, %(hogql_val_147)s, %(hogql_val_148)s, %(hogql_val_149)s, %(hogql_val_150)s, %(hogql_val_151)s, %(hogql_val_152)s, %(hogql_val_153)s, %(hogql_val_154)s, %(hogql_val_155)s, %(hogql_val_156)s, %(hogql_val_157)s, %(hogql_val_158)s, %(hogql_val_159)s, %(hogql_val_160)s, %(hogql_val_161)s, %(hogql_val_162)s, %(hogql_val_163)s, %(hogql_val_164)s, %(hogql_val_165)s, %(hogql_val_166)s, %(hogql_val_167)s, %(hogql_val_168)s, %(hogql_val_169)s, %(hogql_val_170)s, %(hogql_val_171)s, %(hogql_val_172)s, %(hogql_val_173)s, %(hogql_val_174)s, %(hogql_val_175)s, %(hogql_val_176)s, %(hogql_val_177)s, %(hogql_val_178)s, %(hogql_val_179)s, %(hogql_val_180)s, %(hogql_val_181)s, %(hogql_val_182)s, %(hogql_val_183)s, %(hogql_val_184)s, %(hogql_val_185)s, %(hogql_val_186)s, %(hogql_val_187)s, %(hogql_val_188)s, %(hogql_val_189)s, %(hogql_val_190)s, %(hogql_val_191)s, %(hogql_val_192)s, %(hogql_val_193)s, %(hogql_val_194)s, %(hogql_val_195)s, %(hogql_val_196)s, %(hogql_val_197)s, %(hogql_val_198)s, %(hogql_val_199)s, %(hogql_val_200)s, %(hogql_val_201)s, %(hogql_val_202)s]), 0), 1)))
+ and(equals(events.team_id, 99999), equals(events.event, %(hogql_val_1)s), not(accurateCastOrNull(ifNull(notEquals(multiMatchAnyIndex(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, %(hogql_val_2)s), ''), 'null'), '^"|"$', ''), %(hogql_val_3)s), [%(hogql_val_4)s, %(hogql_val_5)s, %(hogql_val_6)s, %(hogql_val_7)s, %(hogql_val_8)s, %(hogql_val_9)s, %(hogql_val_10)s, %(hogql_val_11)s, %(hogql_val_12)s, %(hogql_val_13)s, %(hogql_val_14)s, %(hogql_val_15)s, %(hogql_val_16)s, %(hogql_val_17)s, %(hogql_val_18)s, %(hogql_val_19)s, %(hogql_val_20)s, %(hogql_val_21)s, %(hogql_val_22)s, %(hogql_val_23)s, %(hogql_val_24)s, %(hogql_val_25)s, %(hogql_val_26)s, %(hogql_val_27)s, %(hogql_val_28)s, %(hogql_val_29)s, %(hogql_val_30)s, %(hogql_val_31)s, %(hogql_val_32)s, %(hogql_val_33)s, %(hogql_val_34)s, %(hogql_val_35)s, %(hogql_val_36)s, %(hogql_val_37)s, %(hogql_val_38)s, %(hogql_val_39)s, %(hogql_val_40)s, %(hogql_val_41)s, %(hogql_val_42)s, %(hogql_val_43)s, %(hogql_val_44)s, %(hogql_val_45)s, %(hogql_val_46)s, %(hogql_val_47)s, %(hogql_val_48)s, %(hogql_val_49)s, %(hogql_val_50)s, %(hogql_val_51)s, %(hogql_val_52)s, %(hogql_val_53)s, %(hogql_val_54)s, %(hogql_val_55)s, %(hogql_val_56)s, %(hogql_val_57)s, %(hogql_val_58)s, %(hogql_val_59)s, %(hogql_val_60)s, %(hogql_val_61)s, %(hogql_val_62)s, %(hogql_val_63)s, %(hogql_val_64)s, %(hogql_val_65)s, %(hogql_val_66)s, %(hogql_val_67)s, %(hogql_val_68)s, %(hogql_val_69)s, %(hogql_val_70)s, %(hogql_val_71)s, %(hogql_val_72)s, %(hogql_val_73)s, %(hogql_val_74)s, %(hogql_val_75)s, %(hogql_val_76)s, %(hogql_val_77)s, %(hogql_val_78)s, %(hogql_val_79)s, %(hogql_val_80)s, %(hogql_val_81)s, %(hogql_val_82)s, %(hogql_val_83)s, %(hogql_val_84)s, %(hogql_val_85)s, %(hogql_val_86)s, %(hogql_val_87)s, %(hogql_val_88)s, %(hogql_val_89)s, %(hogql_val_90)s, %(hogql_val_91)s, %(hogql_val_92)s, %(hogql_val_93)s, %(hogql_val_94)s, %(hogql_val_95)s, %(hogql_val_96)s, %(hogql_val_97)s, %(hogql_val_98)s, %(hogql_val_99)s, %(hogql_val_100)s, %(hogql_val_101)s, %(hogql_val_102)s, %(hogql_val_103)s, %(hogql_val_104)s, %(hogql_val_105)s, %(hogql_val_106)s, %(hogql_val_107)s, %(hogql_val_108)s, %(hogql_val_109)s, %(hogql_val_110)s, %(hogql_val_111)s, %(hogql_val_112)s, %(hogql_val_113)s, %(hogql_val_114)s, %(hogql_val_115)s, %(hogql_val_116)s, %(hogql_val_117)s, %(hogql_val_118)s, %(hogql_val_119)s, %(hogql_val_120)s, %(hogql_val_121)s, %(hogql_val_122)s, %(hogql_val_123)s, %(hogql_val_124)s, %(hogql_val_125)s, %(hogql_val_126)s, %(hogql_val_127)s, %(hogql_val_128)s, %(hogql_val_129)s, %(hogql_val_130)s, %(hogql_val_131)s, %(hogql_val_132)s, %(hogql_val_133)s, %(hogql_val_134)s, %(hogql_val_135)s, %(hogql_val_136)s, %(hogql_val_137)s, %(hogql_val_138)s, %(hogql_val_139)s, %(hogql_val_140)s, %(hogql_val_141)s, %(hogql_val_142)s, %(hogql_val_143)s, %(hogql_val_144)s, %(hogql_val_145)s, %(hogql_val_146)s, %(hogql_val_147)s, %(hogql_val_148)s, %(hogql_val_149)s, %(hogql_val_150)s, %(hogql_val_151)s, %(hogql_val_152)s, %(hogql_val_153)s, %(hogql_val_154)s, %(hogql_val_155)s, %(hogql_val_156)s, %(hogql_val_157)s, %(hogql_val_158)s, %(hogql_val_159)s, %(hogql_val_160)s, %(hogql_val_161)s, %(hogql_val_162)s, %(hogql_val_163)s, %(hogql_val_164)s, %(hogql_val_165)s, %(hogql_val_166)s, %(hogql_val_167)s, %(hogql_val_168)s, %(hogql_val_169)s, %(hogql_val_170)s, %(hogql_val_171)s, %(hogql_val_172)s, %(hogql_val_173)s, %(hogql_val_174)s, %(hogql_val_175)s, %(hogql_val_176)s, %(hogql_val_177)s, %(hogql_val_178)s, %(hogql_val_179)s, %(hogql_val_180)s, %(hogql_val_181)s, %(hogql_val_182)s, %(hogql_val_183)s, %(hogql_val_184)s, %(hogql_val_185)s, %(hogql_val_186)s, %(hogql_val_187)s, %(hogql_val_188)s, %(hogql_val_189)s, %(hogql_val_190)s, %(hogql_val_191)s, %(hogql_val_192)s, %(hogql_val_193)s, %(hogql_val_194)s, %(hogql_val_195)s, %(hogql_val_196)s, %(hogql_val_197)s, %(hogql_val_198)s, %(hogql_val_199)s, %(hogql_val_200)s, %(hogql_val_201)s, %(hogql_val_202)s]), 0), 1), %(hogql_val_203)s)))
ORDER BY
user_agent ASC
LIMIT 100
@@ -21,7 +21,7 @@
FROM
events
WHERE
- and(equals(event, '$pageview'), not(notEquals(multiMatchAnyIndex(ifNull(properties.$user_agent, ''), ['GPTBot', 'Google-CloudVertexBot', 'Google-Extended', 'GoogleOther', 'Claude-SearchBot', 'Claude-User', 'ClaudeBot', 'Claude-Web', 'anthropic-ai', 'Perplexity-User', 'PerplexityBot', 'CCBot', 'meta-externalagent', 'Bytespider', 'TikTokSpider', 'cohere-ai', 'Diffbot', 'omgili', 'Webzio-Extended', 'Timpibot', 'Amazonbot', 'PetalBot', 'Brightbot', 'amazon-kendra', 'OAI-SearchBot', 'Applebot-Extended', 'ChatGPT-User', 'meta-externalfetcher', 'Meta-ExternalFetcher', 'DuckAssistBot', 'MistralAI-User', 'Manus-User', 'Google-NotebookLM', 'Shap-User', 'desktop\\.hog\\.dev', 'mobile\\.hog\\.dev', 'agent\\.hog\\.dev', 'cloud\\.hog\\.dev', 'Applebot/', 'Googlebot', 'bingbot', 'Bingbot', 'YandexBot', 'Baiduspider', 'DuckDuckBot', 'Slurp', 'Yeti/', 'YisouSpider', 'Sogou web spider', 'pageburst', '360Spider', 'Qwantbot', 'YouBot', 'DataForSeoBot', 'AwarioBot', 'ArchiveTeam ArchiveBot', 'AdsBot-Google', 'Google-InspectionTool', 'Google-Food', 'Google-Adwords', 'AhrefsSiteAudit', 'AhrefsBot', 'Barkrowler', 'SemrushBot', 'SERankingBacklinksBot', 'MJ12bot', 'DotBot', 'Lighthouse', 'MeltwaterNews', 'SiteAuditBot', 'Screaming Frog SEO Spider', 'PTST', 'FacebookBot', 'facebookexternalhit', 'Twitterbot', 'LinkedInBot', 'Pinterest', 'Slackbot', 'Slack-ImgProxy', 'TelegramBot', 'WhatsApp', 'GoogleImageProxy', 'Iframely', 'SkypeUriPreview', 'Pingdom', 'UptimeRobot', 'Site24x7', 'StatusCake', 'Datadog', 'GrafanaSyntheticMonitoring', 'DMBrowser', 'DigitalOcean Uptime Probe', 'HubSpot', 'curl/', 'Wget', 'python-requests', 'axios', 'node-fetch', 'Go-http-client', 'okhttp', 'Apache-HttpClient', 'libwww-perl', 'Scrapy', 'httpx', 'Google-Apps-Script', 'PlayStore-Google', 'Amazon CloudFront', 'AmazonProductDiscovery', 'Google-BusinessLinkVerification', 'Storebot-Google', 'Google-Read-Aloud', 'Google-Appointments', 'Google-Actions', 'OneTrust', 'Checkly', 'RuxitSynthetic', 'Google-AdWords-Express', 'meta-externalads', 'Google-Safety', 'GTmetrix', 'TwilioKnowledge', 'Google-Agent', 'Google-Structured-Data-Testing', 'google-structured-data-testing-tool', 'adbeat', 'SEBot-WA', 'Ads-Naver', 'Better Uptime Bot', 'woorankreview', 'Viber', 'Taboolabot', 'Archive-It', 'seo4ajax.com', 'CookieHubScan', 'BitSightBot', 'ArchiveBox', 'Dataprovider', 'BingPreview', 'Convertify', 'GoogleAgent-Mariner', 'DareBoost', 'AccessibleWebBot', 'Stripebot', 'Bluesky', 'TagInspector', 'oast', 'CookieScript', 'Mediapartners', 'OhDear', 'Siteimprove', 'SnapchatAds', 'MarketGoo', 'oncrawl', 'kinsta-bot', 'CensysInspect', 'SeznamBot', 'WPMU DEV', 'Google Web Preview', 'Catchpoint', 'Snap URL Preview Service', 'Blackboard', 'Foregenix', 'FirecrawlAgent', 'Seekport', 'ev-crawler', 'bitdiscovery', 'SecurityHeaders', 'vercel-screenshot', 'AppEngine-Google', 'InternetMeasurement', 'GoogleDocs', 'linkchecker.pro', 'zgrab', 'amazon-QBusiness', 'aiohttp', 'WellKnownBot', 'OKX-dolphin-crawler', 'BrightEdge Crawler', 'Asana', 'Google-PageRenderer', 'charlotte', 'AmazonSellerInitiatedListing', 'Splunk Synthetics', 'Detectify', 'Ghost Inspector', 'Monsidobot', 'SearchAtlas Bot', 'VelenPublicWebCrawler', 'Cookiebot', 'nmap', 'MicrosoftPreview', 'Chrome Privacy Preserving Prefetch Proxy', 'Mozlila/', 'HeadlessChrome', 'PhantomJS', 'Puppeteer', 'Playwright', 'Selenium', '^$']), 0)))
+ and(equals(event, '$pageview'), not(toBool(notEquals(multiMatchAnyIndex(ifNull(properties.$user_agent, ''), ['GPTBot', 'Google-CloudVertexBot', 'Google-Extended', 'GoogleOther', 'Claude-SearchBot', 'Claude-User', 'ClaudeBot', 'Claude-Web', 'anthropic-ai', 'Perplexity-User', 'PerplexityBot', 'CCBot', 'meta-externalagent', 'Bytespider', 'TikTokSpider', 'cohere-ai', 'Diffbot', 'omgili', 'Webzio-Extended', 'Timpibot', 'Amazonbot', 'PetalBot', 'Brightbot', 'amazon-kendra', 'OAI-SearchBot', 'Applebot-Extended', 'ChatGPT-User', 'meta-externalfetcher', 'Meta-ExternalFetcher', 'DuckAssistBot', 'MistralAI-User', 'Manus-User', 'Google-NotebookLM', 'Shap-User', 'desktop\\.hog\\.dev', 'mobile\\.hog\\.dev', 'agent\\.hog\\.dev', 'cloud\\.hog\\.dev', 'Applebot/', 'Googlebot', 'bingbot', 'Bingbot', 'YandexBot', 'Baiduspider', 'DuckDuckBot', 'Slurp', 'Yeti/', 'YisouSpider', 'Sogou web spider', 'pageburst', '360Spider', 'Qwantbot', 'YouBot', 'DataForSeoBot', 'AwarioBot', 'ArchiveTeam ArchiveBot', 'AdsBot-Google', 'Google-InspectionTool', 'Google-Food', 'Google-Adwords', 'AhrefsSiteAudit', 'AhrefsBot', 'Barkrowler', 'SemrushBot', 'SERankingBacklinksBot', 'MJ12bot', 'DotBot', 'Lighthouse', 'MeltwaterNews', 'SiteAuditBot', 'Screaming Frog SEO Spider', 'PTST', 'FacebookBot', 'facebookexternalhit', 'Twitterbot', 'LinkedInBot', 'Pinterest', 'Slackbot', 'Slack-ImgProxy', 'TelegramBot', 'WhatsApp', 'GoogleImageProxy', 'Iframely', 'SkypeUriPreview', 'Pingdom', 'UptimeRobot', 'Site24x7', 'StatusCake', 'Datadog', 'GrafanaSyntheticMonitoring', 'DMBrowser', 'DigitalOcean Uptime Probe', 'HubSpot', 'curl/', 'Wget', 'python-requests', 'axios', 'node-fetch', 'Go-http-client', 'okhttp', 'Apache-HttpClient', 'libwww-perl', 'Scrapy', 'httpx', 'Google-Apps-Script', 'PlayStore-Google', 'Amazon CloudFront', 'AmazonProductDiscovery', 'Google-BusinessLinkVerification', 'Storebot-Google', 'Google-Read-Aloud', 'Google-Appointments', 'Google-Actions', 'OneTrust', 'Checkly', 'RuxitSynthetic', 'Google-AdWords-Express', 'meta-externalads', 'Google-Safety', 'GTmetrix', 'TwilioKnowledge', 'Google-Agent', 'Google-Structured-Data-Testing', 'google-structured-data-testing-tool', 'adbeat', 'SEBot-WA', 'Ads-Naver', 'Better Uptime Bot', 'woorankreview', 'Viber', 'Taboolabot', 'Archive-It', 'seo4ajax.com', 'CookieHubScan', 'BitSightBot', 'ArchiveBox', 'Dataprovider', 'BingPreview', 'Convertify', 'GoogleAgent-Mariner', 'DareBoost', 'AccessibleWebBot', 'Stripebot', 'Bluesky', 'TagInspector', 'oast', 'CookieScript', 'Mediapartners', 'OhDear', 'Siteimprove', 'SnapchatAds', 'MarketGoo', 'oncrawl', 'kinsta-bot', 'CensysInspect', 'SeznamBot', 'WPMU DEV', 'Google Web Preview', 'Catchpoint', 'Snap URL Preview Service', 'Blackboard', 'Foregenix', 'FirecrawlAgent', 'Seekport', 'ev-crawler', 'bitdiscovery', 'SecurityHeaders', 'vercel-screenshot', 'AppEngine-Google', 'InternetMeasurement', 'GoogleDocs', 'linkchecker.pro', 'zgrab', 'amazon-QBusiness', 'aiohttp', 'WellKnownBot', 'OKX-dolphin-crawler', 'BrightEdge Crawler', 'Asana', 'Google-PageRenderer', 'charlotte', 'AmazonSellerInitiatedListing', 'Splunk Synthetics', 'Detectify', 'Ghost Inspector', 'Monsidobot', 'SearchAtlas Bot', 'VelenPublicWebCrawler', 'Cookiebot', 'nmap', 'MicrosoftPreview', 'Chrome Privacy Preserving Prefetch Proxy', 'Mozlila/', 'HeadlessChrome', 'PhantomJS', 'Puppeteer', 'Playwright', 'Selenium', '^$']), 0))))
ORDER BY
user_agent ASC
LIMIT 100
@@ -159,12 +159,12 @@
'''
-- ClickHouse
SELECT
- ifNull(notEquals(multiMatchAnyIndex(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, %(hogql_val_0)s), ''), 'null'), '^"|"$', ''), %(hogql_val_1)s), [%(hogql_val_2)s, %(hogql_val_3)s, %(hogql_val_4)s, %(hogql_val_5)s, %(hogql_val_6)s, %(hogql_val_7)s, %(hogql_val_8)s, %(hogql_val_9)s, %(hogql_val_10)s, %(hogql_val_11)s, %(hogql_val_12)s, %(hogql_val_13)s, %(hogql_val_14)s, %(hogql_val_15)s, %(hogql_val_16)s, %(hogql_val_17)s, %(hogql_val_18)s, %(hogql_val_19)s, %(hogql_val_20)s, %(hogql_val_21)s, %(hogql_val_22)s, %(hogql_val_23)s, %(hogql_val_24)s, %(hogql_val_25)s, %(hogql_val_26)s, %(hogql_val_27)s, %(hogql_val_28)s, %(hogql_val_29)s, %(hogql_val_30)s, %(hogql_val_31)s, %(hogql_val_32)s, %(hogql_val_33)s, %(hogql_val_34)s, %(hogql_val_35)s, %(hogql_val_36)s, %(hogql_val_37)s, %(hogql_val_38)s, %(hogql_val_39)s, %(hogql_val_40)s, %(hogql_val_41)s, %(hogql_val_42)s, %(hogql_val_43)s, %(hogql_val_44)s, %(hogql_val_45)s, %(hogql_val_46)s, %(hogql_val_47)s, %(hogql_val_48)s, %(hogql_val_49)s, %(hogql_val_50)s, %(hogql_val_51)s, %(hogql_val_52)s, %(hogql_val_53)s, %(hogql_val_54)s, %(hogql_val_55)s, %(hogql_val_56)s, %(hogql_val_57)s, %(hogql_val_58)s, %(hogql_val_59)s, %(hogql_val_60)s, %(hogql_val_61)s, %(hogql_val_62)s, %(hogql_val_63)s, %(hogql_val_64)s, %(hogql_val_65)s, %(hogql_val_66)s, %(hogql_val_67)s, %(hogql_val_68)s, %(hogql_val_69)s, %(hogql_val_70)s, %(hogql_val_71)s, %(hogql_val_72)s, %(hogql_val_73)s, %(hogql_val_74)s, %(hogql_val_75)s, %(hogql_val_76)s, %(hogql_val_77)s, %(hogql_val_78)s, %(hogql_val_79)s, %(hogql_val_80)s, %(hogql_val_81)s, %(hogql_val_82)s, %(hogql_val_83)s, %(hogql_val_84)s, %(hogql_val_85)s, %(hogql_val_86)s, %(hogql_val_87)s, %(hogql_val_88)s, %(hogql_val_89)s, %(hogql_val_90)s, %(hogql_val_91)s, %(hogql_val_92)s, %(hogql_val_93)s, %(hogql_val_94)s, %(hogql_val_95)s, %(hogql_val_96)s, %(hogql_val_97)s, %(hogql_val_98)s, %(hogql_val_99)s, %(hogql_val_100)s, %(hogql_val_101)s, %(hogql_val_102)s, %(hogql_val_103)s, %(hogql_val_104)s, %(hogql_val_105)s, %(hogql_val_106)s, %(hogql_val_107)s, %(hogql_val_108)s, %(hogql_val_109)s, %(hogql_val_110)s, %(hogql_val_111)s, %(hogql_val_112)s, %(hogql_val_113)s, %(hogql_val_114)s, %(hogql_val_115)s, %(hogql_val_116)s, %(hogql_val_117)s, %(hogql_val_118)s, %(hogql_val_119)s, %(hogql_val_120)s, %(hogql_val_121)s, %(hogql_val_122)s, %(hogql_val_123)s, %(hogql_val_124)s, %(hogql_val_125)s, %(hogql_val_126)s, %(hogql_val_127)s, %(hogql_val_128)s, %(hogql_val_129)s, %(hogql_val_130)s, %(hogql_val_131)s, %(hogql_val_132)s, %(hogql_val_133)s, %(hogql_val_134)s, %(hogql_val_135)s, %(hogql_val_136)s, %(hogql_val_137)s, %(hogql_val_138)s, %(hogql_val_139)s, %(hogql_val_140)s, %(hogql_val_141)s, %(hogql_val_142)s, %(hogql_val_143)s, %(hogql_val_144)s, %(hogql_val_145)s, %(hogql_val_146)s, %(hogql_val_147)s, %(hogql_val_148)s, %(hogql_val_149)s, %(hogql_val_150)s, %(hogql_val_151)s, %(hogql_val_152)s, %(hogql_val_153)s, %(hogql_val_154)s, %(hogql_val_155)s, %(hogql_val_156)s, %(hogql_val_157)s, %(hogql_val_158)s, %(hogql_val_159)s, %(hogql_val_160)s, %(hogql_val_161)s, %(hogql_val_162)s, %(hogql_val_163)s, %(hogql_val_164)s, %(hogql_val_165)s, %(hogql_val_166)s, %(hogql_val_167)s, %(hogql_val_168)s, %(hogql_val_169)s, %(hogql_val_170)s, %(hogql_val_171)s, %(hogql_val_172)s, %(hogql_val_173)s, %(hogql_val_174)s, %(hogql_val_175)s, %(hogql_val_176)s, %(hogql_val_177)s, %(hogql_val_178)s, %(hogql_val_179)s, %(hogql_val_180)s, %(hogql_val_181)s, %(hogql_val_182)s, %(hogql_val_183)s, %(hogql_val_184)s, %(hogql_val_185)s, %(hogql_val_186)s, %(hogql_val_187)s, %(hogql_val_188)s, %(hogql_val_189)s, %(hogql_val_190)s, %(hogql_val_191)s, %(hogql_val_192)s, %(hogql_val_193)s, %(hogql_val_194)s, %(hogql_val_195)s, %(hogql_val_196)s, %(hogql_val_197)s, %(hogql_val_198)s, %(hogql_val_199)s, %(hogql_val_200)s]), 0), 1) AS is_bot,
+ accurateCastOrNull(ifNull(notEquals(multiMatchAnyIndex(ifNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, %(hogql_val_0)s), ''), 'null'), '^"|"$', ''), %(hogql_val_1)s), [%(hogql_val_2)s, %(hogql_val_3)s, %(hogql_val_4)s, %(hogql_val_5)s, %(hogql_val_6)s, %(hogql_val_7)s, %(hogql_val_8)s, %(hogql_val_9)s, %(hogql_val_10)s, %(hogql_val_11)s, %(hogql_val_12)s, %(hogql_val_13)s, %(hogql_val_14)s, %(hogql_val_15)s, %(hogql_val_16)s, %(hogql_val_17)s, %(hogql_val_18)s, %(hogql_val_19)s, %(hogql_val_20)s, %(hogql_val_21)s, %(hogql_val_22)s, %(hogql_val_23)s, %(hogql_val_24)s, %(hogql_val_25)s, %(hogql_val_26)s, %(hogql_val_27)s, %(hogql_val_28)s, %(hogql_val_29)s, %(hogql_val_30)s, %(hogql_val_31)s, %(hogql_val_32)s, %(hogql_val_33)s, %(hogql_val_34)s, %(hogql_val_35)s, %(hogql_val_36)s, %(hogql_val_37)s, %(hogql_val_38)s, %(hogql_val_39)s, %(hogql_val_40)s, %(hogql_val_41)s, %(hogql_val_42)s, %(hogql_val_43)s, %(hogql_val_44)s, %(hogql_val_45)s, %(hogql_val_46)s, %(hogql_val_47)s, %(hogql_val_48)s, %(hogql_val_49)s, %(hogql_val_50)s, %(hogql_val_51)s, %(hogql_val_52)s, %(hogql_val_53)s, %(hogql_val_54)s, %(hogql_val_55)s, %(hogql_val_56)s, %(hogql_val_57)s, %(hogql_val_58)s, %(hogql_val_59)s, %(hogql_val_60)s, %(hogql_val_61)s, %(hogql_val_62)s, %(hogql_val_63)s, %(hogql_val_64)s, %(hogql_val_65)s, %(hogql_val_66)s, %(hogql_val_67)s, %(hogql_val_68)s, %(hogql_val_69)s, %(hogql_val_70)s, %(hogql_val_71)s, %(hogql_val_72)s, %(hogql_val_73)s, %(hogql_val_74)s, %(hogql_val_75)s, %(hogql_val_76)s, %(hogql_val_77)s, %(hogql_val_78)s, %(hogql_val_79)s, %(hogql_val_80)s, %(hogql_val_81)s, %(hogql_val_82)s, %(hogql_val_83)s, %(hogql_val_84)s, %(hogql_val_85)s, %(hogql_val_86)s, %(hogql_val_87)s, %(hogql_val_88)s, %(hogql_val_89)s, %(hogql_val_90)s, %(hogql_val_91)s, %(hogql_val_92)s, %(hogql_val_93)s, %(hogql_val_94)s, %(hogql_val_95)s, %(hogql_val_96)s, %(hogql_val_97)s, %(hogql_val_98)s, %(hogql_val_99)s, %(hogql_val_100)s, %(hogql_val_101)s, %(hogql_val_102)s, %(hogql_val_103)s, %(hogql_val_104)s, %(hogql_val_105)s, %(hogql_val_106)s, %(hogql_val_107)s, %(hogql_val_108)s, %(hogql_val_109)s, %(hogql_val_110)s, %(hogql_val_111)s, %(hogql_val_112)s, %(hogql_val_113)s, %(hogql_val_114)s, %(hogql_val_115)s, %(hogql_val_116)s, %(hogql_val_117)s, %(hogql_val_118)s, %(hogql_val_119)s, %(hogql_val_120)s, %(hogql_val_121)s, %(hogql_val_122)s, %(hogql_val_123)s, %(hogql_val_124)s, %(hogql_val_125)s, %(hogql_val_126)s, %(hogql_val_127)s, %(hogql_val_128)s, %(hogql_val_129)s, %(hogql_val_130)s, %(hogql_val_131)s, %(hogql_val_132)s, %(hogql_val_133)s, %(hogql_val_134)s, %(hogql_val_135)s, %(hogql_val_136)s, %(hogql_val_137)s, %(hogql_val_138)s, %(hogql_val_139)s, %(hogql_val_140)s, %(hogql_val_141)s, %(hogql_val_142)s, %(hogql_val_143)s, %(hogql_val_144)s, %(hogql_val_145)s, %(hogql_val_146)s, %(hogql_val_147)s, %(hogql_val_148)s, %(hogql_val_149)s, %(hogql_val_150)s, %(hogql_val_151)s, %(hogql_val_152)s, %(hogql_val_153)s, %(hogql_val_154)s, %(hogql_val_155)s, %(hogql_val_156)s, %(hogql_val_157)s, %(hogql_val_158)s, %(hogql_val_159)s, %(hogql_val_160)s, %(hogql_val_161)s, %(hogql_val_162)s, %(hogql_val_163)s, %(hogql_val_164)s, %(hogql_val_165)s, %(hogql_val_166)s, %(hogql_val_167)s, %(hogql_val_168)s, %(hogql_val_169)s, %(hogql_val_170)s, %(hogql_val_171)s, %(hogql_val_172)s, %(hogql_val_173)s, %(hogql_val_174)s, %(hogql_val_175)s, %(hogql_val_176)s, %(hogql_val_177)s, %(hogql_val_178)s, %(hogql_val_179)s, %(hogql_val_180)s, %(hogql_val_181)s, %(hogql_val_182)s, %(hogql_val_183)s, %(hogql_val_184)s, %(hogql_val_185)s, %(hogql_val_186)s, %(hogql_val_187)s, %(hogql_val_188)s, %(hogql_val_189)s, %(hogql_val_190)s, %(hogql_val_191)s, %(hogql_val_192)s, %(hogql_val_193)s, %(hogql_val_194)s, %(hogql_val_195)s, %(hogql_val_196)s, %(hogql_val_197)s, %(hogql_val_198)s, %(hogql_val_199)s, %(hogql_val_200)s]), 0), 1), %(hogql_val_201)s) AS is_bot,
count() AS count
FROM
events
WHERE
- and(equals(events.team_id, 99999), equals(events.event, %(hogql_val_201)s))
+ and(equals(events.team_id, 99999), equals(events.event, %(hogql_val_202)s))
GROUP BY
is_bot
ORDER BY
@@ -174,7 +174,7 @@
-- HogQL
SELECT
- notEquals(multiMatchAnyIndex(ifNull(properties.$user_agent, ''), ['GPTBot', 'Google-CloudVertexBot', 'Google-Extended', 'GoogleOther', 'Claude-SearchBot', 'Claude-User', 'ClaudeBot', 'Claude-Web', 'anthropic-ai', 'Perplexity-User', 'PerplexityBot', 'CCBot', 'meta-externalagent', 'Bytespider', 'TikTokSpider', 'cohere-ai', 'Diffbot', 'omgili', 'Webzio-Extended', 'Timpibot', 'Amazonbot', 'PetalBot', 'Brightbot', 'amazon-kendra', 'OAI-SearchBot', 'Applebot-Extended', 'ChatGPT-User', 'meta-externalfetcher', 'Meta-ExternalFetcher', 'DuckAssistBot', 'MistralAI-User', 'Manus-User', 'Google-NotebookLM', 'Shap-User', 'desktop\\.hog\\.dev', 'mobile\\.hog\\.dev', 'agent\\.hog\\.dev', 'cloud\\.hog\\.dev', 'Applebot/', 'Googlebot', 'bingbot', 'Bingbot', 'YandexBot', 'Baiduspider', 'DuckDuckBot', 'Slurp', 'Yeti/', 'YisouSpider', 'Sogou web spider', 'pageburst', '360Spider', 'Qwantbot', 'YouBot', 'DataForSeoBot', 'AwarioBot', 'ArchiveTeam ArchiveBot', 'AdsBot-Google', 'Google-InspectionTool', 'Google-Food', 'Google-Adwords', 'AhrefsSiteAudit', 'AhrefsBot', 'Barkrowler', 'SemrushBot', 'SERankingBacklinksBot', 'MJ12bot', 'DotBot', 'Lighthouse', 'MeltwaterNews', 'SiteAuditBot', 'Screaming Frog SEO Spider', 'PTST', 'FacebookBot', 'facebookexternalhit', 'Twitterbot', 'LinkedInBot', 'Pinterest', 'Slackbot', 'Slack-ImgProxy', 'TelegramBot', 'WhatsApp', 'GoogleImageProxy', 'Iframely', 'SkypeUriPreview', 'Pingdom', 'UptimeRobot', 'Site24x7', 'StatusCake', 'Datadog', 'GrafanaSyntheticMonitoring', 'DMBrowser', 'DigitalOcean Uptime Probe', 'HubSpot', 'curl/', 'Wget', 'python-requests', 'axios', 'node-fetch', 'Go-http-client', 'okhttp', 'Apache-HttpClient', 'libwww-perl', 'Scrapy', 'httpx', 'Google-Apps-Script', 'PlayStore-Google', 'Amazon CloudFront', 'AmazonProductDiscovery', 'Google-BusinessLinkVerification', 'Storebot-Google', 'Google-Read-Aloud', 'Google-Appointments', 'Google-Actions', 'OneTrust', 'Checkly', 'RuxitSynthetic', 'Google-AdWords-Express', 'meta-externalads', 'Google-Safety', 'GTmetrix', 'TwilioKnowledge', 'Google-Agent', 'Google-Structured-Data-Testing', 'google-structured-data-testing-tool', 'adbeat', 'SEBot-WA', 'Ads-Naver', 'Better Uptime Bot', 'woorankreview', 'Viber', 'Taboolabot', 'Archive-It', 'seo4ajax.com', 'CookieHubScan', 'BitSightBot', 'ArchiveBox', 'Dataprovider', 'BingPreview', 'Convertify', 'GoogleAgent-Mariner', 'DareBoost', 'AccessibleWebBot', 'Stripebot', 'Bluesky', 'TagInspector', 'oast', 'CookieScript', 'Mediapartners', 'OhDear', 'Siteimprove', 'SnapchatAds', 'MarketGoo', 'oncrawl', 'kinsta-bot', 'CensysInspect', 'SeznamBot', 'WPMU DEV', 'Google Web Preview', 'Catchpoint', 'Snap URL Preview Service', 'Blackboard', 'Foregenix', 'FirecrawlAgent', 'Seekport', 'ev-crawler', 'bitdiscovery', 'SecurityHeaders', 'vercel-screenshot', 'AppEngine-Google', 'InternetMeasurement', 'GoogleDocs', 'linkchecker.pro', 'zgrab', 'amazon-QBusiness', 'aiohttp', 'WellKnownBot', 'OKX-dolphin-crawler', 'BrightEdge Crawler', 'Asana', 'Google-PageRenderer', 'charlotte', 'AmazonSellerInitiatedListing', 'Splunk Synthetics', 'Detectify', 'Ghost Inspector', 'Monsidobot', 'SearchAtlas Bot', 'VelenPublicWebCrawler', 'Cookiebot', 'nmap', 'MicrosoftPreview', 'Chrome Privacy Preserving Prefetch Proxy', 'Mozlila/', 'HeadlessChrome', 'PhantomJS', 'Puppeteer', 'Playwright', 'Selenium', '^$']), 0) AS is_bot,
+ toBool(notEquals(multiMatchAnyIndex(ifNull(properties.$user_agent, ''), ['GPTBot', 'Google-CloudVertexBot', 'Google-Extended', 'GoogleOther', 'Claude-SearchBot', 'Claude-User', 'ClaudeBot', 'Claude-Web', 'anthropic-ai', 'Perplexity-User', 'PerplexityBot', 'CCBot', 'meta-externalagent', 'Bytespider', 'TikTokSpider', 'cohere-ai', 'Diffbot', 'omgili', 'Webzio-Extended', 'Timpibot', 'Amazonbot', 'PetalBot', 'Brightbot', 'amazon-kendra', 'OAI-SearchBot', 'Applebot-Extended', 'ChatGPT-User', 'meta-externalfetcher', 'Meta-ExternalFetcher', 'DuckAssistBot', 'MistralAI-User', 'Manus-User', 'Google-NotebookLM', 'Shap-User', 'desktop\\.hog\\.dev', 'mobile\\.hog\\.dev', 'agent\\.hog\\.dev', 'cloud\\.hog\\.dev', 'Applebot/', 'Googlebot', 'bingbot', 'Bingbot', 'YandexBot', 'Baiduspider', 'DuckDuckBot', 'Slurp', 'Yeti/', 'YisouSpider', 'Sogou web spider', 'pageburst', '360Spider', 'Qwantbot', 'YouBot', 'DataForSeoBot', 'AwarioBot', 'ArchiveTeam ArchiveBot', 'AdsBot-Google', 'Google-InspectionTool', 'Google-Food', 'Google-Adwords', 'AhrefsSiteAudit', 'AhrefsBot', 'Barkrowler', 'SemrushBot', 'SERankingBacklinksBot', 'MJ12bot', 'DotBot', 'Lighthouse', 'MeltwaterNews', 'SiteAuditBot', 'Screaming Frog SEO Spider', 'PTST', 'FacebookBot', 'facebookexternalhit', 'Twitterbot', 'LinkedInBot', 'Pinterest', 'Slackbot', 'Slack-ImgProxy', 'TelegramBot', 'WhatsApp', 'GoogleImageProxy', 'Iframely', 'SkypeUriPreview', 'Pingdom', 'UptimeRobot', 'Site24x7', 'StatusCake', 'Datadog', 'GrafanaSyntheticMonitoring', 'DMBrowser', 'DigitalOcean Uptime Probe', 'HubSpot', 'curl/', 'Wget', 'python-requests', 'axios', 'node-fetch', 'Go-http-client', 'okhttp', 'Apache-HttpClient', 'libwww-perl', 'Scrapy', 'httpx', 'Google-Apps-Script', 'PlayStore-Google', 'Amazon CloudFront', 'AmazonProductDiscovery', 'Google-BusinessLinkVerification', 'Storebot-Google', 'Google-Read-Aloud', 'Google-Appointments', 'Google-Actions', 'OneTrust', 'Checkly', 'RuxitSynthetic', 'Google-AdWords-Express', 'meta-externalads', 'Google-Safety', 'GTmetrix', 'TwilioKnowledge', 'Google-Agent', 'Google-Structured-Data-Testing', 'google-structured-data-testing-tool', 'adbeat', 'SEBot-WA', 'Ads-Naver', 'Better Uptime Bot', 'woorankreview', 'Viber', 'Taboolabot', 'Archive-It', 'seo4ajax.com', 'CookieHubScan', 'BitSightBot', 'ArchiveBox', 'Dataprovider', 'BingPreview', 'Convertify', 'GoogleAgent-Mariner', 'DareBoost', 'AccessibleWebBot', 'Stripebot', 'Bluesky', 'TagInspector', 'oast', 'CookieScript', 'Mediapartners', 'OhDear', 'Siteimprove', 'SnapchatAds', 'MarketGoo', 'oncrawl', 'kinsta-bot', 'CensysInspect', 'SeznamBot', 'WPMU DEV', 'Google Web Preview', 'Catchpoint', 'Snap URL Preview Service', 'Blackboard', 'Foregenix', 'FirecrawlAgent', 'Seekport', 'ev-crawler', 'bitdiscovery', 'SecurityHeaders', 'vercel-screenshot', 'AppEngine-Google', 'InternetMeasurement', 'GoogleDocs', 'linkchecker.pro', 'zgrab', 'amazon-QBusiness', 'aiohttp', 'WellKnownBot', 'OKX-dolphin-crawler', 'BrightEdge Crawler', 'Asana', 'Google-PageRenderer', 'charlotte', 'AmazonSellerInitiatedListing', 'Splunk Synthetics', 'Detectify', 'Ghost Inspector', 'Monsidobot', 'SearchAtlas Bot', 'VelenPublicWebCrawler', 'Cookiebot', 'nmap', 'MicrosoftPreview', 'Chrome Privacy Preserving Prefetch Proxy', 'Mozlila/', 'HeadlessChrome', 'PhantomJS', 'Puppeteer', 'Playwright', 'Selenium', '^$']), 0)) AS is_bot,
count() AS count
FROM
events
diff --git a/products/web_analytics/backend/hogql_queries/test/test_traffic_type_snapshot.py b/products/web_analytics/backend/hogql_queries/test/test_traffic_type_snapshot.py
index b9d8b537d33e..f75bece1eb0a 100644
--- a/products/web_analytics/backend/hogql_queries/test/test_traffic_type_snapshot.py
+++ b/products/web_analytics/backend/hogql_queries/test/test_traffic_type_snapshot.py
@@ -3,6 +3,8 @@ from typing import Any
import pytest
from posthog.test.base import BaseTest, _create_event, flush_persons_and_events
+from parameterized import parameterized
+
from posthog.hogql.query import execute_hogql_query
from posthog.hogql.test.utils import pretty_print_response_in_tests
@@ -44,19 +46,19 @@ class TestTrafficTypeSnapshot(BaseTest):
assert pretty_print_response_in_tests(response, self.team.pk) == self.snapshot
def test_get_traffic_type(self):
- self._run_function_query("__preview_getTrafficType", "traffic_type")
+ self._run_function_query("getTrafficType", "traffic_type")
def test_get_traffic_category(self):
- self._run_function_query("__preview_getTrafficCategory", "category")
+ self._run_function_query("getTrafficCategory", "category")
def test_is_bot(self):
- self._run_function_query("__preview_isBot", "is_bot")
+ self._run_function_query("isLikelyBot", "is_bot")
def test_get_bot_type(self):
- self._run_function_query("__preview_getBotType", "bot_type")
+ self._run_function_query("getBotType", "bot_type")
def test_get_bot_name(self):
- self._run_function_query("__preview_getBotName", "bot_name")
+ self._run_function_query("getBotName", "bot_name")
def test_filter_bots_sql_query(self):
self._create_test_events()
@@ -64,9 +66,30 @@ class TestTrafficTypeSnapshot(BaseTest):
"""
SELECT event, properties.$user_agent as user_agent
FROM events
- WHERE event = '$pageview' AND NOT __preview_isBot(properties.$user_agent)
+ WHERE event = '$pageview' AND NOT isLikelyBot(properties.$user_agent)
ORDER BY user_agent
""",
self.team,
)
assert pretty_print_response_in_tests(response, self.team.pk) == self.snapshot
+
+ @parameterized.expand(
+ [
+ ("getTrafficType", "__preview_getTrafficType"),
+ ("getTrafficCategory", "__preview_getTrafficCategory"),
+ ("isLikelyBot", "__preview_isBot"),
+ ("getBotType", "__preview_getBotType"),
+ ("getBotName", "__preview_getBotName"),
+ ("getBotOperator", "__preview_getBotOperator"),
+ ]
+ )
+ def test_legacy_preview_alias_matches_ga(self, ga_name: str, preview_name: str):
+ self._create_test_events()
+
+ def _results(function_name: str):
+ return execute_hogql_query(
+ f"SELECT {function_name}(properties.$user_agent) AS v FROM events WHERE event = '$pageview' ORDER BY v",
+ self.team,
+ ).results
+
+ assert _results(preview_name) == _results(ga_name)
diff --git a/products/web_analytics/backend/hogql_queries/test/test_web_traffic_type.py b/products/web_analytics/backend/hogql_queries/test/test_web_traffic_type.py
index 4c91e47ae0ac..550dc79a74a1 100644
--- a/products/web_analytics/backend/hogql_queries/test/test_web_traffic_type.py
+++ b/products/web_analytics/backend/hogql_queries/test/test_web_traffic_type.py
@@ -89,13 +89,16 @@ class TestTrafficTypeExpressions:
user_agent_expr = ast.Field(chain=["properties", "$user_agent"])
expr = is_bot_expr(user_agent_expr)
- # Uses multiMatchAnyIndex(...) != 0 pattern
- assert isinstance(expr, ast.CompareOperation)
- assert expr.op == ast.CompareOperationOp.NotEq
- assert isinstance(expr.left, ast.Call)
- assert expr.left.name == "multiMatchAnyIndex"
- assert isinstance(expr.right, ast.Constant)
- assert expr.right.value == 0
+ # toBool(multiMatchAnyIndex(...) != 0) so results render as true/false
+ assert isinstance(expr, ast.Call)
+ assert expr.name == "toBool"
+ comparison = expr.args[0]
+ assert isinstance(comparison, ast.CompareOperation)
+ assert comparison.op == ast.CompareOperationOp.NotEq
+ assert isinstance(comparison.left, ast.Call)
+ assert comparison.left.name == "multiMatchAnyIndex"
+ assert isinstance(comparison.right, ast.Constant)
+ assert comparison.right.value == 0
def test_get_bot_type_expr_structure(self):
user_agent_expr = ast.Field(chain=["properties", "$user_agent"])
diff --git a/products/web_analytics/backend/hogql_queries/traffic_type.py b/products/web_analytics/backend/hogql_queries/traffic_type.py
index d8cbe8966ea7..80466609be01 100644
--- a/products/web_analytics/backend/hogql_queries/traffic_type.py
+++ b/products/web_analytics/backend/hogql_queries/traffic_type.py
@@ -1,15 +1,12 @@
"""
Traffic type classification helper functions for web analytics.
-EXPERIMENTAL: These functions use __preview_ prefixed HogQL functions to indicate
-they are experimental and may change without notice. The patterns and return values
-may be adjusted as we gather more data on real-world traffic classification accuracy.
-
-The underlying HogQL functions provide maximum flexibility during development:
-- SQL editor: Direct usage for ad-hoc analysis (e.g., SELECT __preview_isBot(properties.$raw_user_agent))
-- HogQLQuery: Custom dashboards and insights with traffic type filtering
-- Trends: Group or filter by traffic type when analyzing patterns
-- Web analytics: These helper functions wrap the HogQL functions for use in query runners
+These wrap the HogQL classification functions, usable anywhere HogQL runs:
+- SQL editor: ad-hoc analysis (e.g. SELECT isLikelyBot(properties.$raw_user_agent))
+- HogQLQuery / Trends: filter or group by traffic type
+- Web analytics query runners
+
+The legacy __preview_* names still resolve as deprecated aliases.
"""
from posthog.hogql import ast
@@ -37,56 +34,46 @@ def get_traffic_type_expr(user_agent_expr: ast.Expr) -> ast.Expr:
"""
Classifies user agent into traffic type.
- EXPERIMENTAL: This function may change without notice.
-
Returns an expression that evaluates to one of:
- "AI Agent" - AI crawlers, search, and assistants (GPTBot, ClaudeBot, ChatGPT-User, etc.)
- "Bot" - Search engines, SEO tools, social crawlers, monitoring
- "Automation" - HTTP clients, headless browsers, empty UA
- "Regular" - Default for unmatched user agents
"""
- return _get_traffic_type(node=ast.Call(name="__preview_getTrafficType", args=[]), args=[user_agent_expr])
+ return _get_traffic_type(node=ast.Call(name="getTrafficType", args=[]), args=[user_agent_expr])
def get_traffic_category_expr(user_agent_expr: ast.Expr) -> ast.Expr:
"""
Returns subcategory expression for more granular classification.
- EXPERIMENTAL: This function may change without notice.
-
Categories: ai_crawler, ai_search, ai_assistant, search_crawler, seo_crawler,
social_crawler, monitoring, http_client, headless_browser, no_user_agent, regular
"""
- return _get_traffic_category(node=ast.Call(name="__preview_getTrafficCategory", args=[]), args=[user_agent_expr])
+ return _get_traffic_category(node=ast.Call(name="getTrafficCategory", args=[]), args=[user_agent_expr])
def is_bot_expr(user_agent_expr: ast.Expr) -> ast.Expr:
"""
Returns a boolean expression: true if bot/automation, false for regular traffic.
-
- EXPERIMENTAL: This function may change without notice.
"""
- return _is_bot(node=ast.Call(name="__preview_isBot", args=[]), args=[user_agent_expr])
+ return _is_bot(node=ast.Call(name="isLikelyBot", args=[]), args=[user_agent_expr])
def get_bot_type_expr(user_agent_expr: ast.Expr) -> ast.Expr:
"""
Returns the bot category or empty string for regular traffic.
- EXPERIMENTAL: This function may change without notice.
-
Categories: ai_crawler, ai_search, ai_assistant, search_crawler, seo_crawler,
social_crawler, monitoring, http_client, headless_browser, no_user_agent, "" (regular)
"""
- return _get_bot_type(node=ast.Call(name="__preview_getBotType", args=[]), args=[user_agent_expr])
+ return _get_bot_type(node=ast.Call(name="getBotType", args=[]), args=[user_agent_expr])
def get_bot_name_expr(user_agent_expr: ast.Expr) -> ast.Expr:
"""
Returns the bot name or empty string for regular traffic.
- EXPERIMENTAL: This function may change without notice.
-
Examples: "Googlebot", "ChatGPT", "Claude", "curl", ""
"""
- return _get_bot_name(node=ast.Call(name="__preview_getBotName", args=[]), args=[user_agent_expr])
+ return _get_bot_name(node=ast.Call(name="getBotName", args=[]), args=[user_agent_expr])