forked from mintlify/docs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
77 lines (77 loc) · 2.33 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
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
const e = 'octolane_session_id',
t = () =>
`${crypto.randomUUID()}-${Math.random()
.toString(36)
.substring(2, 15)}-${new Date().getTime()}`,
n = (n, o) => {
const r = {
api_key: n,
event: {
event_type: 'page_view',
session_id: (() => {
const n = document.cookie.split('; ');
for (const t of n) {
const [n, o] = t.split('=');
if (n === e) return o;
}
return t();
})(),
page_title: o.title,
page_url: o.href,
referrer: o.referrer,
url_change_type: o.url_change_type,
favicon_url: o.favicon_url
? window.location.origin + o.favicon_url
: null,
},
},
c = new Blob([JSON.stringify(r)], { type: 'application/json' });
navigator.sendBeacon('https://enrich.octolane.com/v1/events', c),
'beforeunload' === o.url_change_type &&
(document.cookie = `${e}=; path=/; expires=Thu, 01 Jan 1970 00:00:01 GMT`);
},
o = (e) => {
const t = (() => {
const e = document.querySelectorAll('script');
for (const t of e) {
const e = t.getAttribute('src');
if (e && e.startsWith('https://cdn.octolane.com/tag.js?pk=')) {
const t = new URL(e).searchParams.get('pk');
if (t) return t;
}
}
return null;
})(),
o = {
href: window.location.href,
title: document.title,
description:
document
.querySelector("meta[name='description']")
?.getAttribute('content') ?? '',
referrer: document.referrer,
favicon_url:
document.querySelector("link[rel='icon']")?.getAttribute('href') ??
'',
};
(o.url_change_type = e),
t ? n(t, o) : console.error('[OCTOLANE] Misconfigured script tag key');
};
function r(n = 'urlChange') {
if ('onlanded' === n) {
((t) => {
document.cookie = `${e}=${t}; path=/`;
})(t());
}
o(n);
}
r('onlanded'),
(() => {
let e = document.location.href;
new MutationObserver(() => {
e !== document.location.href && ((e = document.location.href), r());
}).observe(document.body, { childList: !0, subtree: !0 });
})(),
window.addEventListener('beforeunload', () => {
r('beforeunload');
});