| 436 | // --------------------------------------------------------------------------- |
| 437 | |
| 438 | async function sendEvent(payload, ua, ip) { |
| 439 | const headers = { |
| 440 | 'Content-Type': 'application/json', |
| 441 | 'user-agent': ua, |
| 442 | 'openpanel-client-id': CLIENT_ID, |
| 443 | 'x-forwarded-for': ip, |
| 444 | origin: ORIGIN, |
| 445 | }; |
| 446 | |
| 447 | const res = await fetch(TRACK_URL, { |
| 448 | method: 'POST', |
| 449 | headers, |
| 450 | body: JSON.stringify(payload), |
| 451 | }); |
| 452 | |
| 453 | if (!res.ok) { |
| 454 | const text = await res.text().catch(() => ''); |
| 455 | console.warn(` [WARN] ${res.status} ${payload.type}/${payload.payload?.name ?? ''}: ${text.slice(0, 120)}`); |
| 456 | } |
| 457 | return res; |
| 458 | } |
| 459 | |
| 460 | // --------------------------------------------------------------------------- |
| 461 | // Build session event list |