Modified company id fetching process for iframe
This commit is contained in:
parent
388ede765a
commit
85c0d4bab5
|
|
@ -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) {
|
function getPathMatch(pathname, regex) {
|
||||||
const match = pathname.match(regex);
|
const match = pathname.match(regex);
|
||||||
return match?.[1] || '';
|
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() {
|
export function getRuntimeCompanyId() {
|
||||||
const runtimeUrl = getRuntimeUrl();
|
const runtimeUrl = getRuntimeUrl();
|
||||||
if (!runtimeUrl) return '';
|
const referrerUrl = getReferrerUrl();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
runtimeUrl.searchParams.get('companyId')
|
getFirstSearchParam(runtimeUrl, ['companyId', 'company_id', 'bltt-gtw-f-c-cid'])
|
||||||
|| runtimeUrl.searchParams.get('company_id')
|
|| getPathMatch(runtimeUrl?.pathname || '', /\/company\/([^/]+)/i)
|
||||||
|| getPathMatch(runtimeUrl.pathname, /\/company\/([^/]+)/i)
|
|| getFirstSearchParam(referrerUrl, ['companyId', 'company_id'])
|
||||||
|
|| getPathMatch(referrerUrl?.pathname || '', /\/company\/([^/]+)/i)
|
||||||
|| ''
|
|| ''
|
||||||
).trim();
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getRuntimeApplicationId() {
|
export function getRuntimeApplicationId() {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user