MOREE!!!!

This commit is contained in:
legop3
2026-06-19 01:22:42 -04:00
parent ea8e027be9
commit c7f5cb68f4
22 changed files with 429 additions and 138 deletions
+19
View File
@@ -7,6 +7,7 @@
const MAX_EVENT_NAME_LENGTH = 80;
const MAX_PROPERTY_KEY_LENGTH = 80;
const MAX_STRING_VALUE_LENGTH = 240;
const throttledEvents = new Map();
function getAdapter() {
if (typeof window === 'undefined') return null;
@@ -90,3 +91,21 @@ export function identifyAnalyticsSession(payload = {}) {
console.warn('Analytics identify failed', error);
}
}
export function trackAnalyticsEventThrottled(name, payload = {}, options = {}) {
const eventName = normalizeEventName(name);
if (!eventName) return;
const throttleMs = Number.isFinite(options?.throttleMs) ? Math.max(0, options.throttleMs) : 30 * 1000;
const key = `${eventName}:${typeof options?.key === 'string' ? options.key : JSON.stringify(normalizePayload(payload))}`;
const now = Date.now();
const lastTrackedAt = throttledEvents.get(key) || 0;
/*
Reliability signals can repeat every reconnect loop or failed media retry.
Throttling by a caller-owned key keeps Umami useful as an incident signal
without turning transient outages into hundreds of duplicate custom events.
*/
if (now - lastTrackedAt < throttleMs) return;
throttledEvents.set(key, now);
trackAnalyticsEvent(eventName, payload);
}