(event: string, properties?: Record<string, string | number | boolean>)
| 69 | } |
| 70 | |
| 71 | export async function track(event: string, properties?: Record<string, string | number | boolean>): Promise<void> { |
| 72 | if (!(await isEnabled())) return |
| 73 | |
| 74 | queue.push({ |
| 75 | event, |
| 76 | properties, |
| 77 | timestamp: Date.now(), |
| 78 | }) |
| 79 | |
| 80 | log.debug("tracked", { event, properties }) |
| 81 | |
| 82 | if (queue.length >= MAX_QUEUE_SIZE) { |
| 83 | flush().catch(() => {}) |
| 84 | } |
| 85 | |
| 86 | if (!flushTimer) { |
| 87 | flushTimer = setInterval(() => flush().catch(() => {}), FLUSH_INTERVAL) |
| 88 | } |
| 89 | } |
| 90 | |
| 91 | export async function flush(): Promise<void> { |
| 92 | if (queue.length === 0) return |
no test coverage detected