From 85c0d4bab5b5fef3a08e42804b63decfcdc4cde2 Mon Sep 17 00:00:00 2001 From: Ritul Date: Fri, 27 Mar 2026 00:11:10 +0530 Subject: [PATCH] Modified company id fetching process for iframe --- client/src/utils/runtimeContext.js | 32 +++++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/client/src/utils/runtimeContext.js b/client/src/utils/runtimeContext.js index 10c0e37..3265f6e 100644 --- a/client/src/utils/runtimeContext.js +++ b/client/src/utils/runtimeContext.js @@ -8,21 +8,43 @@ function getRuntimeUrl() { } } +function getReferrerUrl() { + if (typeof document === 'undefined' || !document.referrer) return null; + + try { + return new URL(document.referrer); + } catch { + return null; + } +} + function getPathMatch(pathname, regex) { const match = pathname.match(regex); return match?.[1] || ''; } +function getFirstSearchParam(url, keys) { + if (!url) return ''; + + for (const key of keys) { + const value = url.searchParams.get(key); + if (value) return value.trim(); + } + + return ''; +} + export function getRuntimeCompanyId() { const runtimeUrl = getRuntimeUrl(); - if (!runtimeUrl) return ''; + const referrerUrl = getReferrerUrl(); return ( - runtimeUrl.searchParams.get('companyId') - || runtimeUrl.searchParams.get('company_id') - || getPathMatch(runtimeUrl.pathname, /\/company\/([^/]+)/i) + getFirstSearchParam(runtimeUrl, ['companyId', 'company_id', 'bltt-gtw-f-c-cid']) + || getPathMatch(runtimeUrl?.pathname || '', /\/company\/([^/]+)/i) + || getFirstSearchParam(referrerUrl, ['companyId', 'company_id']) + || getPathMatch(referrerUrl?.pathname || '', /\/company\/([^/]+)/i) || '' - ).trim(); + ); } export function getRuntimeApplicationId() {