: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.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
feat(growth): mark projects created through an oauth connector (#118852)
Rafael Audibertdaaf9a060907
diff --git a/docs/published/handbook/engineering/oauth-development-guide.md b/docs/published/handbook/engineering/oauth-development-guide.mdindex be12cc02a78b..f999ca82ce1a 100644--- a/docs/published/handbook/engineering/oauth-development-guide.md+++ b/docs/published/handbook/engineering/oauth-development-guide.md@@ -356,7 +356,7 @@ An account created while the cookie is present skips in-app onboarding. Signup sWhile the cookie is present, the signup form pins the data region to the region the form is served from. An OAuth client is registered in one region only, so an account created in the other region could not finish the connection.-Analytics: the frontend captures `oauth pending connection viewed` with a `screen` property (`login`, `signup`, or `verify_email`). `user signed up` carries `signup_oauth_client_name` and `signup_oauth_client_id`, which are also set as person properties, so a signup can be traced back to the application that started it.+Analytics: the frontend captures `oauth pending connection viewed` with a `screen` property (`login`, `signup`, or `verify_email`). `user signed up` carries `signup_oauth_client_name` and `signup_oauth_client_id`, which are also set as person properties, so a signup can be traced back to the application that started it. When the signup creates a new organization, the project group also gets `created_via_oauth_client` and `created_via_oauth_client_id`.## Endpointsdiff --git a/posthog/api/test/test_signup.py b/posthog/api/test/test_signup.pyindex e93a7646a886..d49518197e49 100644--- a/posthog/api/test/test_signup.py+++ b/posthog/api/test/test_signup.py@@ -1627,15 +1627,22 @@ class TestSignupAPI(APIBaseTest):@parameterized.expand([- ("plain_signup", "plain", True),- ("social_signup", "social", True),- ("invite_signup", "invite", True),- ("delegated_invite_signup", "delegated_invite", False),+ ("plain_signup", "plain", True, True),+ ("social_signup", "social", True, True),+ ("invite_signup", "invite", True, False),+ ("delegated_invite_signup", "delegated_invite", False, False),])+ @patch("posthoganalytics.group_identify")@patch("posthoganalytics.capture")def test_api_sign_up_reports_the_pending_oauth_connection(- self, _name: str, signup_path: str, expect_onboarding_skip: bool, mock_capture+ self,+ _name: str,+ signup_path: str,+ expect_onboarding_skip: bool,+ expect_project_marked: bool,+ mock_capture,+ mock_group_identify,):email = "[email protected]"self.client.cookies[PENDING_OAUTH_CONNECTION_COOKIE] = PendingOAuthConnection(@@ -1691,6 +1698,25 @@ class TestSignupAPI(APIBaseTest):self.assertIsNone(user.onboarding_skipped_at)self.assertIsNone(user.onboarding_skipped_reason)+ project_calls = [c for c in mock_group_identify.call_args_list if c.args[0] == "project"]+ if expect_project_marked:+ assert user.team is not None+ self.assertEqual(+ project_calls,+ [+ mock.call(+ "project",+ str(user.team.uuid),+ properties={+ "created_via_oauth_client": "Claude",+ "created_via_oauth_client_id": "https://claude.example.com/.well-known/oauth-client",+ },+ )+ ],+ )+ else:+ self.assertEqual(project_calls, [])+@pytest.mark.skip_on_multitenancy@patch("posthog.utils.get_ip_address", return_value="192.168.1.100")def test_signup_rate_limit_by_ip(self, mock_get_ip):diff --git a/posthog/event_usage.py b/posthog/event_usage.pyindex 2b60f268e393..fe5055ac0efc 100644--- a/posthog/event_usage.py+++ b/posthog/event_usage.py@@ -89,6 +89,16 @@ def report_user_signed_up(if is_organization_first_user and user.organization is not None:exclude_internal_organization_from_crm(user.organization, user)+ if oauth_connection is not None and is_organization_first_user and user.team is not None:+ posthoganalytics.group_identify(+ "project",+ str(user.team.uuid),+ properties={+ "created_via_oauth_client": oauth_connection.client_name,+ "created_via_oauth_client_id": oauth_connection.client_id,+ },+ )+def report_user_verified_email(current_user: User) -> None:"""