improve tracking

This commit is contained in:
orangecoding
2025-09-13 17:06:18 +02:00
parent 251de1e42d
commit d66dc2cd93
5 changed files with 32 additions and 21 deletions

View File

@@ -10,11 +10,7 @@ const deviceId = getUniqueId() || 'N/A';
const version = await getPackageVersion();
const FREDY_TRACKING_URL = 'https://fredy.orange-coding.net/tracking';
let cached = null;
let lastSent = 0;
const SIX_HOURS = 6 * 3_600_000;
export const track = async () => {
export const trackMainEvent = async () => {
try {
if (config.analyticsEnabled && !inDevMode()) {
const activeProvider = new Set();
@@ -33,19 +29,11 @@ export const track = async () => {
provider: Array.from(activeProvider),
});
const stringify = JSON.stringify(trackingObj);
const now = Date.now();
// send if changed OR six hours passed since last send
if (stringify !== cached || now - lastSent >= SIX_HOURS) {
await fetch(`${FREDY_TRACKING_URL}/main`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: stringify,
});
cached = stringify;
lastSent = now;
}
await fetch(`${FREDY_TRACKING_URL}/main`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(trackingObj),
});
}
}
} catch (error) {