MCPcopy Create free account
hub / github.com/outerbase/studio / sendAnalyticEvents

Function sendAnalyticEvents

src/lib/tracking.ts:23–59  ·  view source on GitHub ↗
(events: TrackEventItem[])

Source from the content-addressed store, hash-verified

21}
22
23export function sendAnalyticEvents(events: TrackEventItem[]) {
24 if (typeof window === "undefined") {
25 return;
26 }
27
28 if (!process.env.NEXT_PUBLIC_ANALYTIC_ENABLED) return;
29
30 /**
31 * Some error send at very high rate, we need to throttle them
32 * to prevent the server from being overwhelmed.
33 */
34 const finalEvents = events.filter((e) => {
35 if (!["unhandledrejection", "error"].includes(e.name)) return true;
36 return throttleEvent(e.name, 5, 5000);
37 });
38
39 if (finalEvents.length === 0) return;
40
41 let deviceId = localStorage.getItem("od-id");
42 if (!deviceId) {
43 deviceId = generateId();
44 localStorage.setItem("od-id", deviceId);
45 }
46
47 fetch("/api/events", {
48 method: "POST",
49 body: JSON.stringify({
50 events: finalEvents,
51 }),
52 headers: {
53 "Content-Type": "application/json",
54 "x-od-id": deviceId,
55 },
56 })
57 .then()
58 .catch();
59}

Callers 5

PageTrackerFunction · 0.90
handlerFunction · 0.90
DatabaseGuiFunction · 0.90
onRunClickedFunction · 0.90
multipleQueryFunction · 0.90

Calls 2

throttleEventFunction · 0.90
generateIdFunction · 0.90

Tested by

no test coverage detected