-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
63 lines (54 loc) · 1.1 KB
/
index.js
File metadata and controls
63 lines (54 loc) · 1.1 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
// MIT License
// Copyright (c) 2026 Open2b
// See the LICENSE file for full text.
import { EndpointURLError, Krenalis } from './krenalis.js'
import { uuid } from './utils.js'
function loadSDK() {
// Do nothing if the browser is not supported.
if (!uuid) {
return
}
const krenalis = globalThis.krenalis
let e
try {
e = new Krenalis(krenalis.key, krenalis.url, krenalis.options)
} catch (error) {
if (error instanceof EndpointURLError) {
console.error(error.message)
return
}
throw error
}
void e.ready(function () {
const methods = [
'alias',
'close',
'debug',
'endSession',
'getAnonymousId',
'getSessionId',
'group',
'identify',
'page',
'ready',
'reset',
'screen',
'setAnonymousId',
'startSession',
'track',
'user',
]
for (let i = 0; i < methods.length; i++) {
const method = methods[i]
krenalis[method] = e[method].bind(e)
}
for (let i = 0; i < krenalis.length; i++) {
const event = krenalis[i]
krenalis[event[0]](...event.splice(1))
}
// empty the array.
krenalis.length = 0
globalThis.krenalis = e
})
}
loadSDK()