diff --git a/src/background/telemetry/metrics.js b/src/background/telemetry/metrics.js index 7b4c9ffa6..184269485 100644 --- a/src/background/telemetry/metrics.js +++ b/src/background/telemetry/metrics.js @@ -352,8 +352,18 @@ export default class Metrics { _timeToExpired(type, frequency) { if (frequency === 'all') return 0; - const last = this.storage[`${type}_${frequency}`] || 0; - const frequency_ago = Date.now() - FREQUENCIES[frequency]; + const key = `${type}_${frequency}`; + const now = Date.now(); + + // 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] = now; + this.saveStorage(this.storage); + } + + const last = this.storage[key]; + const frequency_ago = now - FREQUENCIES[frequency]; return last ? last - frequency_ago : 0; }