Skip to content

armgit / umami

Public Imported from GitHub
0

Umami is a privacy-first web and product analytics platform. Traffic, campaigns, behavior, conversions, and revenue in one place. No cookies, no surveillance, self-hosted or in the cloud.

Fixed vercel region issues.

Mike Cao4ea3eec98cc8
diff --git a/lib/detect.ts b/lib/detect.ts
index 01e6c9a6d..868d0a806 100644
--- a/lib/detect.ts
+++ b/lib/detect.ts
@@ -63,10 +63,15 @@ export async function getLocation(ip, req) {
}
if (req.headers['x-vercel-ip-country']) {
+ const country = req.headers['x-vercel-ip-country'];
+ const region = req.headers['x-vercel-ip-country-region'];
+ const city = req.headers['x-vercel-ip-city'];
+
return {
- country: req.headers['x-vercel-ip-country'],
- subdivision1: req.headers['x-vercel-ip-country-region'],
- city: decodeURIComponent(req.headers['x-vercel-ip-city']),
+ country,
+ // Vercel documentation says they return only region, but that is not always the case
+ subdivision1: region.includes('-') ? region : `${country}-${region}`,
+ city: decodeURIComponent(city),
};
}