-
Notifications
You must be signed in to change notification settings - Fork 83
Expand file tree
/
Copy pathpublic-path.ts
More file actions
79 lines (65 loc) · 2.58 KB
/
Copy pathpublic-path.ts
File metadata and controls
79 lines (65 loc) · 2.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
export const getUrlBase = (path = '') => {
const l = window.location;
if (!/^\/(br_)/.test(l.pathname)) return path;
const get_path = path.startsWith('/') ? path : `/${path}`;
return `/${l.pathname.split('/')[1]}${get_path}`;
};
export function setBotPublicPath(path: string) {
window.__webpack_public_path__ = '';
window.__webpack_public_path__ = path; // eslint-disable-line no-global-assign
}
export const getImageLocation = (image_name: string) => `assets/images/${image_name}`;
declare global {
interface Window {
Survicate?: {
track: (attribute: string, value: string) => void;
};
}
}
const setSurvicateUserAttributes = (country: string, type: string, creationDate: string) => {
if (window.Survicate) {
if (country) window.Survicate.track('userCountry', country);
if (type) window.Survicate.track('accountType', type);
if (creationDate) window.Survicate.track('accountCreationDate', creationDate);
}
};
let initSurvicateCalled = false;
const setSurvicateCalledValue = (value: boolean) => {
initSurvicateCalled = value;
};
const loadSurvicateScript = (callback: () => void) => {
const script = document.createElement('script');
script.id = 'dbot-survicate';
script.async = true;
script.src = 'https://survey.survicate.com/workspaces/83b651f6b3eca1ab4551d95760fe5deb/web_surveys.js';
script.onload = callback;
const firstScript = document.getElementsByTagName('script')[0];
if (firstScript?.parentNode) {
firstScript.parentNode.insertBefore(script, firstScript);
} else {
document.body.appendChild(script);
}
};
const initSurvicate = () => {
if (initSurvicateCalled) return;
setSurvicateCalledValue(true);
const active_loginid = localStorage.getItem('active_loginid');
const client_accounts = JSON.parse(localStorage.getItem('accountsList') as string) || undefined;
const setAttributesIfAvailable = () => {
if (active_loginid && client_accounts) {
const { residence, account_type, created_at } = client_accounts[active_loginid] || {};
setSurvicateUserAttributes(residence, account_type, created_at);
}
};
if (document.getElementById('dbot-survicate')) {
const survicateBox = document.getElementById('survicate-box');
if (survicateBox) {
survicateBox.style.display = 'block';
}
setAttributesIfAvailable();
} else {
loadSurvicateScript(setAttributesIfAvailable);
}
};
export { initSurvicate, setSurvicateCalledValue };
setBotPublicPath(getUrlBase('/'));