57 lines
1.4 KiB
JavaScript
57 lines
1.4 KiB
JavaScript
import TelemetryDeck from '@telemetrydeck/sdk';
|
|
|
|
|
|
///////////////
|
|
// TELEMETRY //
|
|
///////////////
|
|
|
|
// Telemetry Deck only collects fully anonymized data!
|
|
|
|
const getCookieValueOrNull = (name) => {
|
|
const cookie = document.cookie
|
|
.split(";")
|
|
.map(c => c.trim())
|
|
.find(c => c.startsWith(name + "="));
|
|
return cookie ? cookie.split("=")[1] : null;
|
|
};
|
|
|
|
function getOrCreateUUID() {
|
|
let cookie_val = getCookieValueOrNull("id");
|
|
if (
|
|
cookie_val
|
|
) {
|
|
return cookie_val;
|
|
} else {
|
|
let uuid =crypto.randomUUID();
|
|
const days = 365;
|
|
const expires = new Date(Date.now() + days * 864e5).toUTCString();
|
|
document.cookie = `id=${uuid}; expires=${expires}`;
|
|
return uuid;
|
|
}
|
|
}
|
|
|
|
// Send Test Signals when running locally
|
|
function init() {
|
|
if (location.hostname === "localhost" || location.hostname === "127.0.0.1") {
|
|
const td = new TelemetryDeck({
|
|
appID: '4A88C6F5-2BDE-489E-9834-34D89FD5473F',
|
|
clientUser: getOrCreateUUID(),
|
|
testMode: true
|
|
});
|
|
return td;
|
|
} else {
|
|
const td = new TelemetryDeck({
|
|
appID: '4A88C6F5-2BDE-489E-9834-34D89FD5473F',
|
|
clientUser: getOrCreateUUID()
|
|
});
|
|
return td;
|
|
}
|
|
}
|
|
|
|
let td = init();
|
|
|
|
|
|
export function send(type, payload) {
|
|
td.signal(type, payload);
|
|
}
|