Skip to content

πŸ™Œ OpenHands: AI-Driven Development

fix: set email person property in PostHog during onboarding completion (#15070)

Lila Garcia518e44b6ab9f
diff --git a/enterprise/server/routes/auth.py b/enterprise/server/routes/auth.py
index 55e5fa61c9..5ee157ee73 100644
--- a/enterprise/server/routes/auth.py
+++ b/enterprise/server/routes/auth.py
@@ -1064,6 +1064,16 @@ async def complete_onboarding(
analytics = get_analytics_service()
if analytics:
ctx = await resolve_analytics_context(user_id)
+ # Stamp email on the person profile so person_display_name
+ # is set when the onboarding event is viewed in PostHog.
+ # identify_user was a no-op at login (consent was False),
+ # and accept_tos never re-triggered it, so this is the
+ # first opportunity after consent is granted.
+ if user.email:
+ analytics.set_person_properties(
+ ctx=ctx,
+ properties={'email': user.email},
+ )
analytics.track_onboarding_completed(
ctx=ctx,
selections=selections,
diff --git a/enterprise/tests/unit/server/routes/test_auth_onboarding.py b/enterprise/tests/unit/server/routes/test_auth_onboarding.py
index 93d45291ae..6421ae6ad8 100644
--- a/enterprise/tests/unit/server/routes/test_auth_onboarding.py
+++ b/enterprise/tests/unit/server/routes/test_auth_onboarding.py
@@ -542,6 +542,7 @@ class TestCompleteOnboardingEndpoint:
the user's current org."""
user_id = str(uuid.uuid4())
org_id = str(uuid.uuid4())
+ mock_user.email = '[email protected]'
selections = {
'role': 'software_engineer',
'org_size': 'solo',
@@ -581,6 +582,10 @@ class TestCompleteOnboardingEndpoint:
assert isinstance(result, JSONResponse)
assert result.status_code == status.HTTP_200_OK
+ mock_analytics.set_person_properties.assert_called_once_with(
+ ctx=mock_ctx,
+ properties={'email': '[email protected]'},
+ )
mock_analytics.track_onboarding_completed.assert_called_once_with(
ctx=mock_ctx,
selections=selections,
@@ -591,6 +596,49 @@ class TestCompleteOnboardingEndpoint:
assert gi_kwargs['group_key'] == org_id
assert 'onboarding_completed_at' in gi_kwargs['properties']
+ @pytest.mark.asyncio
+ async def test_skips_set_person_properties_when_no_email(
+ self, mock_request, mock_user
+ ):
+ """set_person_properties must not fire when user.email is None."""
+ user_id = str(uuid.uuid4())
+ mock_user.email = None
+ mock_user_auth = MagicMock(spec=SaasUserAuth)
+ mock_user_auth.get_user_id = AsyncMock(return_value=user_id)
+
+ mock_analytics = MagicMock()
+ mock_ctx = MagicMock(org_id=None)
+
+ with (
+ patch(
+ 'server.routes.auth.get_user_auth',
+ new_callable=AsyncMock,
+ return_value=mock_user_auth,
+ ),
+ patch(
+ 'server.routes.auth.UserStore.mark_onboarding_completed',
+ new_callable=AsyncMock,
+ return_value=mock_user,
+ ),
+ patch(
+ 'server.routes.auth.get_analytics_service',
+ return_value=mock_analytics,
+ ),
+ patch(
+ 'server.routes.auth.resolve_analytics_context',
+ new_callable=AsyncMock,
+ return_value=mock_ctx,
+ ),
+ ):
+ result = await complete_onboarding(
+ mock_request, body=OnboardingSubmission(selections={})
+ )
+
+ assert isinstance(result, JSONResponse)
+ assert result.status_code == status.HTTP_200_OK
+ mock_analytics.set_person_properties.assert_not_called()
+ mock_analytics.track_onboarding_completed.assert_called_once()
+
@pytest.mark.asyncio
async def test_skips_group_identify_when_no_org_id(self, mock_request, mock_user):
"""group_identify must not fire when the user has no current org."""