Commit 3318dcf
authored
fix(analytics): wrap GA4 fetch in waitUntil to prevent dropped events (#59)
The fire-and-forget fetch() in trackEvent() returns a dangling Promise
that the Vercel serverless runtime cancels the moment the response is
returned. With GA4_MEASUREMENT_ID and GA4_API_SECRET correctly set in
production, events were still never reaching google-analytics.com
because the POST was cut off mid-flight.
Wrap the fetch in waitUntil() from @vercel/functions so the runtime
keeps the function instance alive until the GA4 request settles —
without blocking the airdrop response.
waitUntil is runtime-agnostic and reads a context object Vercel
injects on globalThis; it does not change the deploy type, the runtime
(Node.js Fluid Compute), regions, or pricing. Outside Vercel it
silently no-ops, matching the prior fire-and-forget semantics.1 parent 8db6c0a commit 3318dcf
3 files changed
Lines changed: 57 additions & 21 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
| 13 | + | |
| 14 | + | |
13 | 15 | | |
14 | 16 | | |
15 | 17 | | |
| |||
41 | 43 | | |
42 | 44 | | |
43 | 45 | | |
44 | | - | |
45 | | - | |
46 | | - | |
47 | | - | |
48 | | - | |
49 | | - | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
50 | 56 | | |
51 | | - | |
52 | | - | |
53 | | - | |
| 57 | + | |
54 | 58 | | |
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
| 24 | + | |
24 | 25 | | |
25 | 26 | | |
26 | 27 | | |
| |||
0 commit comments