From c43f83fd46bf91ca18756f1cd00a37d2cf266606 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20Luba=C5=84ski?= Date: Wed, 11 Dec 2024 10:38:27 +0100 Subject: [PATCH] fix(telemetry): send events on trailing edge of the frequency --- src/background/telemetry/metrics.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/background/telemetry/metrics.js b/src/background/telemetry/metrics.js index 7b4c9ffa6..4af929502 100644 --- a/src/background/telemetry/metrics.js +++ b/src/background/telemetry/metrics.js @@ -352,7 +352,16 @@ export default class Metrics { _timeToExpired(type, frequency) { if (frequency === 'all') return 0; - const last = this.storage[`${type}_${frequency}`] || 0; + const key = `${type}_${frequency}`; + + // Protect against calling events immediately after install for all frequencies + // They should trigger on the trailing edge of the frequency + if (!this.storage[key]) { + this.storage[key] = Date.now(); + this.saveStorage(this.storage); + } + + const last = this.storage[key]; const frequency_ago = Date.now() - FREQUENCIES[frequency]; return last ? last - frequency_ago : 0;