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.
TypeScript analyticsaudience-segmentationchartscohort-analysisgoogle-analyticsproduct-analyticsstatisticsuser-journeyweb-analytics
Ensure region code includes country.
Mike Cao4b0118dce155
diff --git a/src/lib/detect.ts b/src/lib/detect.tsindex 43dac6499..86f812bd9 100644--- a/src/lib/detect.ts+++ b/src/lib/detect.ts@@ -65,19 +65,27 @@ export async function getLocation(ip, req) {// Cloudflare headersif (req.headers['cf-ipcountry']) {+ const country = safeDecodeURIComponent(req.headers['cf-ipcountry']);+ const subdivision1 = safeDecodeURIComponent(req.headers['cf-region-code']);+ const city = safeDecodeURIComponent(req.headers['cf-ipcity']);+return {- country: safeDecodeURIComponent(req.headers['cf-ipcountry']),- subdivision1: safeDecodeURIComponent(req.headers['cf-region-code']),- city: safeDecodeURIComponent(req.headers['cf-ipcity']),+ country,+ subdivision1: subdivision1.includes('-') ? subdivision1 : `${country}-${subdivision1}`,+ city,};}// Vercel headersif (req.headers['x-vercel-ip-country']) {+ const country = safeDecodeURIComponent(req.headers['x-vercel-ip-country']);+ const subdivision1 = safeDecodeURIComponent(req.headers['x-vercel-ip-country-region']);+ const city = safeDecodeURIComponent(req.headers['x-vercel-ip-city']);+return {- country: safeDecodeURIComponent(req.headers['x-vercel-ip-country']),- subdivision1: safeDecodeURIComponent(req.headers['x-vercel-ip-country-region']),- city: safeDecodeURIComponent(req.headers['x-vercel-ip-city']),+ country,+ subdivision1: subdivision1.includes('-') ? subdivision1 : `${country}-${subdivision1}`,+ city,};}