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.

chore(demo): write demo insights as query, not filters (#94922)

Thomas Obermüllerfd107edce438
diff --git a/products/demo/backend/logic/legacy/app_data_generator.py b/products/demo/backend/logic/legacy/app_data_generator.py
index 79af11f19dff..2acc70e21d26 100644
--- a/products/demo/backend/logic/legacy/app_data_generator.py
+++ b/products/demo/backend/logic/legacy/app_data_generator.py
@@ -4,7 +4,8 @@ from django.utils.timezone import now
from dateutil.relativedelta import relativedelta
-from posthog.constants import TREND_FILTER_TYPE_ACTIONS
+from posthog.schema import ActionsNode, DateRange, EventPropertyFilter, FunnelsQuery, InsightVizNode, PropertyOperator
+
from posthog.models import EventDefinition, Person, PropertyDefinition
from products.actions.backend.models.action import Action
@@ -38,31 +39,22 @@ class AppDataGenerator(DataGenerator):
insight = Insight.objects.create(
team=self.team,
name="Installed App -> Rated App -> Rated App 5 Stars",
- filters={
- "actions": [
- {
- "id": installed_app_action.id,
- "name": "Installed App",
- "order": 0,
- "type": TREND_FILTER_TYPE_ACTIONS,
- },
- {
- "id": rated_app_action.id,
- "name": "Rated App",
- "order": 1,
- "type": TREND_FILTER_TYPE_ACTIONS,
- },
- {
- "id": rated_app_action.id,
- "name": "Rated App",
- "order": 2,
- "type": TREND_FILTER_TYPE_ACTIONS,
- "properties": {"app_rating": 5},
- },
- ],
- "insight": "FUNNELS",
- "date_from": "yStart",
- },
+ query=InsightVizNode(
+ source=FunnelsQuery(
+ series=[
+ ActionsNode(id=installed_app_action.id, name="Installed App"),
+ ActionsNode(id=rated_app_action.id, name="Rated App"),
+ ActionsNode(
+ id=rated_app_action.id,
+ name="Rated App",
+ properties=[
+ EventPropertyFilter(key="app_rating", value=5, operator=PropertyOperator.EXACT)
+ ],
+ ),
+ ],
+ dateRange=DateRange(date_from="yStart"),
+ )
+ ).model_dump(),
)
DashboardTile.objects.create(insight=insight, dashboard=dashboard)
dashboard.save() # to update the insight's filter hash
diff --git a/products/demo/backend/logic/legacy/revenue_data_generator.py b/products/demo/backend/logic/legacy/revenue_data_generator.py
index ff407930ddaf..a7c4067bd1f8 100644
--- a/products/demo/backend/logic/legacy/revenue_data_generator.py
+++ b/products/demo/backend/logic/legacy/revenue_data_generator.py
@@ -4,7 +4,16 @@ from django.utils.timezone import now
from dateutil.relativedelta import relativedelta
-from posthog.constants import TREND_FILTER_TYPE_ACTIONS
+from posthog.schema import (
+ ActionsNode,
+ DateRange,
+ EventPropertyFilter,
+ EventsNode,
+ FunnelsQuery,
+ InsightVizNode,
+ PropertyOperator,
+)
+
from posthog.models import EventDefinition, Person, PropertyDefinition
from products.actions.backend.models.action import Action
@@ -64,27 +73,21 @@ class RevenueDataGenerator(DataGenerator):
insight = Insight.objects.create(
team=self.team,
name="Entered Free Trial -> Purchase (Premium)",
- filters={
- "events": [
- {
- "id": "$pageview",
- "name": "Pageview",
- "order": 0,
- "type": TREND_FILTER_TYPE_ACTIONS,
- }
- ],
- "actions": [
- {
- "id": purchase_action.id,
- "name": "Purchase",
- "order": 1,
- "type": TREND_FILTER_TYPE_ACTIONS,
- "properties": {"plan": "premium"},
- }
- ],
- "insight": "FUNNELS",
- "date_from": "all",
- },
+ query=InsightVizNode(
+ source=FunnelsQuery(
+ series=[
+ EventsNode(event="$pageview", name="Pageview"),
+ ActionsNode(
+ id=purchase_action.id,
+ name="Purchase",
+ properties=[
+ EventPropertyFilter(key="plan", value="premium", operator=PropertyOperator.EXACT)
+ ],
+ ),
+ ],
+ dateRange=DateRange(date_from="all"),
+ )
+ ).model_dump(),
short_id="TEST1234",
)
DashboardTile.objects.create(insight=insight, dashboard=dashboard)
diff --git a/products/demo/backend/logic/legacy/web_data_generator.py b/products/demo/backend/logic/legacy/web_data_generator.py
index 377ddf9f9f29..bb525f192452 100644
--- a/products/demo/backend/logic/legacy/web_data_generator.py
+++ b/products/demo/backend/logic/legacy/web_data_generator.py
@@ -8,7 +8,8 @@ from django.utils.timezone import now
from dateutil.relativedelta import relativedelta
-from posthog.constants import TREND_FILTER_TYPE_ACTIONS
+from posthog.schema import ActionsNode, FunnelsQuery, InsightVizNode
+
from posthog.models import Person, PropertyDefinition
from posthog.models.filters.mixins.utils import cached_property
from posthog.models.utils import UUIDT
@@ -78,29 +79,15 @@ class WebDataGenerator(DataGenerator):
team=self.team,
name="Hogflix signup -> watching movie",
description="Shows a conversion funnel from sign up to watching a movie.",
- filters={
- "actions": [
- {
- "id": homepage.id,
- "name": "Hogflix homepage view",
- "order": 0,
- "type": TREND_FILTER_TYPE_ACTIONS,
- },
- {
- "id": user_signed_up.id,
- "name": "Hogflix signed up",
- "order": 1,
- "type": TREND_FILTER_TYPE_ACTIONS,
- },
- {
- "id": user_paid.id,
- "name": "Hogflix paid",
- "order": 2,
- "type": TREND_FILTER_TYPE_ACTIONS,
- },
- ],
- "insight": "FUNNELS",
- },
+ query=InsightVizNode(
+ source=FunnelsQuery(
+ series=[
+ ActionsNode(id=homepage.id, name="Hogflix homepage view"),
+ ActionsNode(id=user_signed_up.id, name="Hogflix signed up"),
+ ActionsNode(id=user_paid.id, name="Hogflix paid"),
+ ],
+ )
+ ).model_dump(),
)
DashboardTile.objects.create(insight=insight, dashboard=dashboard)
dashboard.save() # to update the insight's filter hash