-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
48 lines (45 loc) · 1.2 KB
/
script.js
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
// @ts-check
(function (
/** @type {Window} */
window,
/** @type {Document} */
document,
/** @type {InitializeData} */
initializeData
) {
var firstScript = document.getElementsByTagName('script')[0];
var aasaamAnalyticScript = document.createElement('script');
aasaamAnalyticScript.async = true;
aasaamAnalyticScript.defer = true;
var prefix =
'https://' +
initializeData.s +
'/_/' +
new Date().toISOString().split('T')[0].replace(/-/g, '');
// modern browser
// condition for modern browser detect about ~ 90% total users
// https://caniuse.com/mdn-javascript_builtins_promise_any
if (
'WeakSet' in window &&
'URLSearchParams' in window &&
'entries' in Object &&
'Promise' in window &&
'any' in Promise
) {
aasaamAnalyticScript.setAttribute(
'data-i',
window.btoa(encodeURIComponent(JSON.stringify(initializeData)))
);
aasaamAnalyticScript.src = prefix + '/a.js';
} else {
// legacy browsers
window.aai_lid = initializeData;
aasaamAnalyticScript.src = prefix + '/l.js';
}
firstScript.parentNode.insertBefore(aasaamAnalyticScript, firstScript);
})(
window,
document,
// @ts-ignore
__INITIALIZE_DATA__
);