diff --git a/posthog/test/test_utils.py b/posthog/test/test_utils.py index f6c5d4079505c..827c5dd1de851 100644 --- a/posthog/test/test_utils.py +++ b/posthog/test/test_utils.py @@ -281,16 +281,16 @@ def test_normal_date(self): class TestDefaultEventName(BaseTest): def test_no_events(self): - self.assertEqual(get_default_event_name(), "$pageview") + self.assertEqual(get_default_event_name(self.team), "$pageview") def test_take_screen(self): EventDefinition.objects.create(name="$screen", team=self.team) - self.assertEqual(get_default_event_name(), "$screen") + self.assertEqual(get_default_event_name(self.team), "$screen") def test_prefer_pageview(self): EventDefinition.objects.create(name="$pageview", team=self.team) EventDefinition.objects.create(name="$screen", team=self.team) - self.assertEqual(get_default_event_name(), "$pageview") + self.assertEqual(get_default_event_name(self.team), "$pageview") class TestLoadDataFromRequest(TestCase): diff --git a/posthog/utils.py b/posthog/utils.py index 278d47f5acf39..ecefc4ea1f6e0 100644 --- a/posthog/utils.py +++ b/posthog/utils.py @@ -371,7 +371,7 @@ def render_template( "current_user": None, "current_team": None, "preflight": json.loads(preflight_check(request).getvalue()), - "default_event_name": get_default_event_name(), + "default_event_name": "$pageview", "switched_team": getattr(request, "switched_team", None), **posthog_app_context, } @@ -399,6 +399,7 @@ def render_template( ) posthog_app_context["current_team"] = team_serialized.data posthog_app_context["frontend_apps"] = get_frontend_apps(user.team.pk) + posthog_app_context["default_event_name"] = get_default_event_name(user.team) context["posthog_app_context"] = json.dumps(posthog_app_context, default=json_uuid_convert) @@ -456,12 +457,12 @@ def get_self_capture_api_token(request: Optional[HttpRequest]) -> Optional[str]: return None -def get_default_event_name(): +def get_default_event_name(team: "Team"): from posthog.models import EventDefinition - if EventDefinition.objects.filter(name="$pageview").exists(): + if EventDefinition.objects.filter(team=team, name="$pageview").exists(): return "$pageview" - elif EventDefinition.objects.filter(name="$screen").exists(): + elif EventDefinition.objects.filter(team=team, name="$screen").exists(): return "$screen" return "$pageview"