MCPcopy Create free account
hub / github.com/heygen-com/hyperframes / flushEvents

Function flushEvents

packages/studio/src/utils/studioTelemetry.ts:65–91  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

63}
64
65async function flushEvents(): Promise<void> {
66 if (queue.length === 0) return;
67
68 const batch = queue.map((e) => ({
69 event: e.event,
70 properties: { ...e.properties, $ip: null },
71 distinct_id: getDistinctId(),
72 timestamp: e.timestamp,
73 }));
74 queue = [];
75
76 const controller = new AbortController();
77 const timeout = setTimeout(() => controller.abort(), FLUSH_TIMEOUT_MS);
78
79 try {
80 await fetch(`${POSTHOG_HOST}/batch/`, {
81 method: "POST",
82 headers: { "Content-Type": "application/json" },
83 body: JSON.stringify({ api_key: POSTHOG_API_KEY, batch }),
84 signal: controller.signal,
85 });
86 } catch {
87 // Telemetry must never break the studio
88 } finally {
89 clearTimeout(timeout);
90 }
91}
92
93if (typeof window !== "undefined") {
94 window.addEventListener("visibilitychange", () => {

Callers

nothing calls this directly

Calls 2

getDistinctIdFunction · 0.85
fetchFunction · 0.85

Tested by

no test coverage detected