MCPcopy Create free account
hub / github.com/caesarHQ/textSQL / sendToVercelAnalytics

Function sendToVercelAnalytics

client/censusGPT/src/vitals.js:11–40  ·  view source on GitHub ↗
(metric)

Source from the content-addressed store, hash-verified

9}
10
11export function sendToVercelAnalytics(metric) {
12 const analyticsId = process.env.REACT_APP_VERCEL_ANALYTICS_ID
13 if (!analyticsId) {
14 return
15 }
16
17 const body = {
18 dsn: analyticsId,
19 id: metric.id,
20 page: window.location.pathname,
21 href: window.location.href,
22 event_name: metric.name,
23 value: metric.value.toString(),
24 speed: getConnectionSpeed(),
25 }
26
27 const blob = new Blob([new URLSearchParams(body).toString()], {
28 // This content type is necessary for `sendBeacon`
29 type: 'application/x-www-form-urlencoded',
30 })
31 if (navigator.sendBeacon) {
32 navigator.sendBeacon(vitalsUrl, blob)
33 } else
34 fetch(vitalsUrl, {
35 body: blob,
36 method: 'POST',
37 credentials: 'omit',
38 keepalive: true,
39 })
40}

Callers

nothing calls this directly

Calls 1

getConnectionSpeedFunction · 0.85

Tested by

no test coverage detected