Modified company id fetching process for iframe

This commit is contained in:
Ritul Jadhav 2026-03-27 00:11:10 +05:30
parent 388ede765a
commit 85c0d4bab5

View File

@ -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() {