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(signals): expose revenue analytics config to hogql and gate its scout (#115176)

posthog[bot]a8798d8fe0c0
diff --git a/posthog/hogql/database/schema/system.py b/posthog/hogql/database/schema/system.py
index f16eebf08d1f..cd1215020beb 100644
--- a/posthog/hogql/database/schema/system.py
+++ b/posthog/hogql/database/schema/system.py
@@ -1525,6 +1525,29 @@ survey_response_archives: PostgresTable = PostgresTable(
},
)
+revenue_analytics_config: PostgresTable = PostgresTable(
+ name="revenue_analytics_config",
+ postgres_table_name="posthog_teamrevenueanalyticsconfig",
+ access_scope="revenue_analytics",
+ description="Revenue analytics settings for the project; at most one row. "
+ "No row means revenue analytics was never configured.",
+ fields={
+ "id": IntegerDatabaseField(name="team_id", description="Alias of team_id."),
+ "team_id": IntegerDatabaseField(name="team_id"),
+ "events": StringJSONDatabaseField(
+ name="events",
+ description="JSON array of configured revenue events, one object per event with its eventName and "
+ "revenue, currency, subscription, product and coupon property mapping. '[]' when none are configured.",
+ ),
+ "_filter_test_accounts": BooleanDatabaseField(name="filter_test_accounts", hidden=True),
+ "filter_test_accounts": ExpressionField(
+ name="filter_test_accounts",
+ expr=ast.Call(name="toInt", args=[ast.Field(chain=["_filter_test_accounts"])]),
+ description="1 if event-based revenue views exclude test accounts, 0 otherwise.",
+ ),
+ },
+)
+
teams: PostgresTable = PostgresTable(
name="teams",
postgres_table_name="posthog_team",
@@ -3299,6 +3322,7 @@ class SystemTables(TableNode):
"score_definitions": TableNode(name="score_definitions", table=score_definitions),
"session_recording_playlists": TableNode(name="session_recording_playlists", table=session_recording_playlists),
"replay_scanners": TableNode(name="replay_scanners", table=replay_scanners),
+ "revenue_analytics_config": TableNode(name="revenue_analytics_config", table=revenue_analytics_config),
"session_recordings": TableNode(name="session_recordings", table=session_recordings),
"source_schemas": TableNode(name="source_schemas", table=source_schemas),
"source_sync_jobs": TableNode(name="source_sync_jobs", table=source_sync_jobs),
diff --git a/posthog/hogql/database/schema/test/test_system_tables.py b/posthog/hogql/database/schema/test/test_system_tables.py
index ec1eecedc3a6..3f0f78b275f3 100644
--- a/posthog/hogql/database/schema/test/test_system_tables.py
+++ b/posthog/hogql/database/schema/test/test_system_tables.py
@@ -31,6 +31,7 @@ from posthog.models.activity_logging.activity_log import ActivityLog
from posthog.models.data_deletion_request import ExecutionMode, RequestStatus, RequestType
from posthog.models.project import Project
from posthog.models.scoping import team_scope
+from posthog.models.team.team_revenue_analytics_config import TeamRevenueAnalyticsConfig
from posthog.persons_db import persons_db_connection
from posthog.persons_seed import insert_seed_group, insert_seed_group_type_mapping
@@ -893,6 +894,10 @@ def _create_tag(team: Team, label: str) -> Tag:
return Tag.objects.create(team=team, name=f"tag_{label}")
+def _create_revenue_analytics_config(team: Team, label: str) -> TeamRevenueAnalyticsConfig:
+ return team.revenue_analytics_config
+
+
def _create_team(team: Team, label: str) -> Team:
return team
@@ -1019,6 +1024,7 @@ SYSTEM_TABLE_FACTORIES = [
("integration_repository_cache", _create_integration_repository_cache_entry),
("logs_alerts", _create_logs_alert),
("replay_scanners", _create_replay_scanner),
+ ("revenue_analytics_config", _create_revenue_analytics_config),
("logs_views", _create_logs_view),
("message_categories", _create_message_category),
("message_recipient_preferences", _create_message_recipient_preference),
diff --git a/posthog/hogql/database/test/__snapshots__/test_database.ambr b/posthog/hogql/database/test/__snapshots__/test_database.ambr
index 2232c18cef30..009cdb4d5a13 100644
--- a/posthog/hogql/database/test/__snapshots__/test_database.ambr
+++ b/posthog/hogql/database/test/__snapshots__/test_database.ambr
@@ -10911,6 +10911,45 @@
"row_count": null,
"type": "system"
},
+ "system.revenue_analytics_config": {
+ "certification": null,
+ "fields": {
+ "id": {
+ "chain": null,
+ "fields": null,
+ "hogql_value": "id",
+ "id": null,
+ "name": "id",
+ "schema_valid": true,
+ "table": null,
+ "type": "integer"
+ },
+ "events": {
+ "chain": null,
+ "fields": null,
+ "hogql_value": "events",
+ "id": null,
+ "name": "events",
+ "schema_valid": true,
+ "table": null,
+ "type": "json"
+ },
+ "filter_test_accounts": {
+ "chain": null,
+ "fields": null,
+ "hogql_value": "filter_test_accounts",
+ "id": null,
+ "name": "filter_test_accounts",
+ "schema_valid": true,
+ "table": null,
+ "type": "integer"
+ }
+ },
+ "id": "system.revenue_analytics_config",
+ "name": "system.revenue_analytics_config",
+ "row_count": null,
+ "type": "system"
+ },
"system.session_recordings": {
"certification": null,
"fields": {
@@ -23554,6 +23593,45 @@
"row_count": null,
"type": "system"
},
+ "system.revenue_analytics_config": {
+ "certification": null,
+ "fields": {
+ "id": {
+ "chain": null,
+ "fields": null,
+ "hogql_value": "id",
+ "id": null,
+ "name": "id",
+ "schema_valid": true,
+ "table": null,
+ "type": "integer"
+ },
+ "events": {
+ "chain": null,
+ "fields": null,
+ "hogql_value": "events",
+ "id": null,
+ "name": "events",
+ "schema_valid": true,
+ "table": null,
+ "type": "json"
+ },
+ "filter_test_accounts": {
+ "chain": null,
+ "fields": null,
+ "hogql_value": "filter_test_accounts",
+ "id": null,
+ "name": "filter_test_accounts",
+ "schema_valid": true,
+ "table": null,
+ "type": "integer"
+ }
+ },
+ "id": "system.revenue_analytics_config",
+ "name": "system.revenue_analytics_config",
+ "row_count": null,
+ "type": "system"
+ },
"system.session_recordings": {
"certification": null,
"fields": {
diff --git a/products/signals/backend/test/test_scout_precheck.py b/products/signals/backend/test/test_scout_precheck.py
index 4e723d90130a..f9e759fc3994 100644
--- a/products/signals/backend/test/test_scout_precheck.py
+++ b/products/signals/backend/test/test_scout_precheck.py
@@ -30,6 +30,7 @@ from products.signals.backend.scout_harness.precheck import (
resolve_effective_precheck,
)
from products.skills.backend.models.skills import LLMSkill
+from products.warehouse_sources.backend.facade.models import ExternalDataSource
NOW = datetime(2026, 10, 9, 12, 0, 0, tzinfo=UTC)
SKILL = "signals-scout-errors"
@@ -37,6 +38,7 @@ NEW_EVENTS_QUERY = "SELECT event FROM events WHERE event = 'boom' AND timestamp
# An access-scoped system table: a query with no user is denied it.
DASHBOARDS_QUERY = "SELECT count() FROM system.dashboards"
SURVEYS_SKILL = "signals-scout-surveys"
+REVENUE_SKILL = "signals-scout-revenue-analytics"
ROLLOUT_PERCENT = "products.signals.backend.scout_harness.precheck.precheck_default_rollout_percent"
@@ -335,6 +337,63 @@ class TestSystemTableSkillDefaults(ClickhouseTestMixin, NonAtomicBaseTest):
assert capture.call_args.kwargs["properties"].get("error_type") is None
+@time_machine.travel(NOW, tick=False)
+class TestRevenueDefaultPrecheck(NonAtomicBaseTest):
+ # The system tables read Postgres through ClickHouse, which sees only committed rows.
+ CLASS_DATA_LEVEL_SETUP = False
+
+ def setUp(self) -> None:
+ super().setUp()
+ LLMSkill.objects.create(
+ team=self.team, name=REVENUE_SKILL, description="", body="", metadata={"seeded_by": HARNESS_SEEDED_BY}
+ )
+ SignalScoutConfig.all_teams.create(team=self.team, skill_name=REVENUE_SKILL)
+
+ @parameterized.expand(
+ [
+ ("nothing_configured", None, False, None, "skip", "no_rows", 0),
+ ("config_without_events", None, False, [], "skip", "no_rows", 0),
+ (
+ "revenue_events_only",
+ None,
+ False,
+ [{"eventName": "purchase", "revenueProperty": "amount"}],
+ "run",
+ "rows",
+ 1,
+ ),
+ ("stripe_source_only", "Stripe", False, None, "run", "rows", 1),
+ ("deleted_stripe_source", "Stripe", True, None, "skip", "no_rows", 0),
+ ("non_payment_source", "Postgres", False, None, "skip", "no_rows", 0),
+ ]
+ )
+ def test_revenue_default_gates_the_run(
+ self, _name, source_type, deleted, events, outcome, reason, row_count
+ ) -> None:
+ if source_type is not None:
+ ExternalDataSource.objects.create(
+ team=self.team,
+ source_id="s1",
+ connection_id="c1",
+ status="Running",
+ source_type=source_type,
+ deleted=deleted,
+ )
+ if events is not None:
+ config = self.team.revenue_analytics_config
+ config.events = events
+ config.save()
+
+ with (
+ patch(ROLLOUT_PERCENT, return_value=100),
+ patch("products.signals.backend.scout_harness.precheck.posthoganalytics.capture"),
+ ):
+ result = evaluate_scout_precheck(self.team.pk, REVENUE_SKILL)
+
+ assert result is not None
+ assert (result.outcome, result.reason, result.row_count) == (outcome, reason, row_count)
+
+
class TestResolveEffectivePrecheck(SimpleTestCase):
@parameterized.expand(
[
diff --git a/products/signals/skills/signals-scout-revenue-analytics/SKILL.md b/products/signals/skills/signals-scout-revenue-analytics/SKILL.md
index e0399a9db5c4..a0017dd5d5eb 100644
--- a/products/signals/skills/signals-scout-revenue-analytics/SKILL.md
+++ b/products/signals/skills/signals-scout-revenue-analytics/SKILL.md
@@ -16,6 +16,17 @@ allowed_tools:
metadata:
owner_team: signals
scope: revenue_analytics
+scout-precheck-query: |
+ SELECT * FROM (
+ SELECT 'source' AS kind, source_type AS detail
+ FROM system.data_warehouse_sources
+ WHERE source_type = 'Stripe' AND deleted = 0
+ UNION ALL
+ SELECT 'events', toString(JSONLength(events))
+ FROM system.revenue_analytics_config
+ WHERE JSONLength(events) > 0
+ )
+ LIMIT 10
---
# Signals scout: revenue analytics
@@ -63,6 +74,10 @@ The fallback has limits. Say so in any finding that relies on it:
- It does not show the property mapping. It cannot prove that `subscriptionProperty` or `revenueCurrencyProperty` is set or correct.
- It does not show `filter_test_accounts`.
+## Pre-check rows
+
+A scheduled run can start with a `<precheck_result>` block. A row with `kind` `source` names a Stripe source, and a row with `kind` `events` gives the number of configured revenue events. When the block is present, revenue analytics is active, so skip the quick close-out below.
+
## Quick close-out: is revenue analytics even active?
Revenue analytics is active when either source is present: