From 5ecc0d4da9333f1d45584bf63b6fda7a93e661fe Mon Sep 17 00:00:00 2001 From: Sabiha Khan <87858386+chewwbaka@users.noreply.github.com> Date: Fri, 17 Apr 2026 11:47:20 +0530 Subject: [PATCH] fix: allow cross subdomain cookies at posthog (#243) --- api/db/organization_usage_client.py | 15 ++++++++++----- api/routes/organization_usage.py | 1 + ui/package-lock.json | 4 ++-- ui/src/app/usage/page.tsx | 10 ++++++++++ ui/src/client/types.gen.ts | 14 ++++++++++++++ ui/src/instrumentation-client.ts | 2 ++ 6 files changed, 39 insertions(+), 7 deletions(-) diff --git a/api/db/organization_usage_client.py b/api/db/organization_usage_client.py index 5968475..9140140 100644 --- a/api/db/organization_usage_client.py +++ b/api/db/organization_usage_client.py @@ -315,11 +315,15 @@ class OrganizationUsageClient(BaseDBClient): total_tokens += dograh_tokens total_duration_seconds += int(round(call_duration)) - # Extract phone number from initial_context - # Outbound calls store it as "phone_number"; inbound calls store it as "caller_number" - phone_number = None - if run.initial_context: - phone_number = run.initial_context.get("phone_number") or run.initial_context.get("caller_number") + # Extract phone number from initial_context based on call_type. + # Inbound runs only have caller_number/called_number; the + # caller_number is the customer. Outbound runs use the + # phone_number key written by the dispatchers. + ic = run.initial_context or {} + if run.call_type == "inbound": + phone_number = ic.get("caller_number") + else: + phone_number = ic.get("phone_number") # Extract disposition from gathered_context disposition = None @@ -337,6 +341,7 @@ class OrganizationUsageClient(BaseDBClient): "recording_url": run.recording_url, "transcript_url": run.transcript_url, "phone_number": phone_number, + "call_type": run.call_type, "disposition": disposition, "initial_context": run.initial_context, "gathered_context": run.gathered_context, diff --git a/api/routes/organization_usage.py b/api/routes/organization_usage.py index 1627363..bb26795 100644 --- a/api/routes/organization_usage.py +++ b/api/routes/organization_usage.py @@ -48,6 +48,7 @@ class WorkflowRunUsageResponse(BaseModel): recording_url: Optional[str] = None transcript_url: Optional[str] = None phone_number: Optional[str] = None + call_type: Optional[str] = None disposition: Optional[str] = None initial_context: Optional[Dict[str, Any]] = None gathered_context: Optional[Dict[str, Any]] = None diff --git a/ui/package-lock.json b/ui/package-lock.json index 07c1430..904b266 100644 --- a/ui/package-lock.json +++ b/ui/package-lock.json @@ -1,12 +1,12 @@ { "name": "ui", - "version": "1.21.0", + "version": "1.24.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "ui", - "version": "1.21.0", + "version": "1.24.0", "dependencies": { "@dagrejs/dagre": "^1.1.4", "@nangohq/frontend": "^0.69.47", diff --git a/ui/src/app/usage/page.tsx b/ui/src/app/usage/page.tsx index a5055c5..5745d55 100644 --- a/ui/src/app/usage/page.tsx +++ b/ui/src/app/usage/page.tsx @@ -457,6 +457,7 @@ export default function UsagePage() { Run ID Agent Name + Call Type Phone Number Disposition Date @@ -479,6 +480,15 @@ export default function UsagePage() { #{run.id} {run.workflow_name || 'Unknown'} + + {run.call_type ? ( + + {run.call_type === 'inbound' ? 'Inbound' : 'Outbound'} + + ) : ( + - + )} + {run.phone_number || '-'} diff --git a/ui/src/client/types.gen.ts b/ui/src/client/types.gen.ts index 465a306..9c819a2 100644 --- a/ui/src/client/types.gen.ts +++ b/ui/src/client/types.gen.ts @@ -3344,6 +3344,16 @@ export type ValidationError = { * Error Type */ type: string; + /** + * Input + */ + input?: unknown; + /** + * Context + */ + ctx?: { + [key: string]: unknown; + }; }; /** @@ -3818,6 +3828,10 @@ export type WorkflowRunUsageResponse = { * Phone Number */ phone_number?: string | null; + /** + * Call Type + */ + call_type?: string | null; /** * Disposition */ diff --git a/ui/src/instrumentation-client.ts b/ui/src/instrumentation-client.ts index 93d4349..baf8e7a 100644 --- a/ui/src/instrumentation-client.ts +++ b/ui/src/instrumentation-client.ts @@ -53,6 +53,7 @@ const initPostHog = () => { capture_pageview: 'history_change', capture_pageleave: true, capture_exceptions: true, + cross_subdomain_cookie: true, debug: process.env.NEXT_PUBLIC_NODE_ENV === 'development', }); console.log('PostHog initialized from NEXT_PUBLIC config'); @@ -68,6 +69,7 @@ const initPostHog = () => { capture_pageview: 'history_change', capture_pageleave: true, capture_exceptions: true, + cross_subdomain_cookie: true, debug: process.env.NEXT_PUBLIC_NODE_ENV === 'development', }); console.log('PostHog initialized from API config');