Много разных изменений

This commit is contained in:
Zuev
2026-08-20 00:55:27 +03:00
parent 3599d850f6
commit a1c4ee4298
78 changed files with 4698 additions and 428 deletions

View File

@@ -1,13 +1,40 @@
let telemetryPromise = null;
const pendingUxEvents = [];
export function initializeTelemetry() {
if (['localhost', '127.0.0.1', '::1'].includes(window.location.hostname)) {
return Promise.resolve();
}
if (!telemetryPromise) {
telemetryPromise = import('/vendor/otel.js').catch(error => {
telemetryPromise = import('/vendor/otel.js').then(() => flushPendingUxEvents()).catch(error => {
console.warn('Не удалось инициализировать браузерную телеметрию');
});
}
return telemetryPromise;
}
export function trackUxEvent(name, attributes = {}) {
const event = {
name: String(name || 'неизвестное_событие'),
attributes: sanitizeAttributes(attributes),
timestamp: new Date().toISOString()
};
document.dispatchEvent(new CustomEvent('magistr:ux-event', { detail: event }));
if (typeof window.__magistrTrackUx === 'function') {
window.__magistrTrackUx(event.name, event.attributes);
} else {
pendingUxEvents.push(event);
if (pendingUxEvents.length > 100) pendingUxEvents.shift();
}
}
export function flushPendingUxEvents() {
if (typeof window.__magistrTrackUx !== 'function') return;
pendingUxEvents.splice(0).forEach(event => window.__magistrTrackUx(event.name, event.attributes));
}
function sanitizeAttributes(attributes) {
return Object.fromEntries(Object.entries(attributes || {})
.filter(([, value]) => ['string', 'number', 'boolean'].includes(typeof value))
.map(([key, value]) => [String(key), value]));
}