📈 Open source, privacy-first web analytics — a cookie-less Google Analytics alternative with built-in error tracking and performance monitoring. Self-host it or use our cloud. Get started for free!
TypeScript chartsclickhousedockergdprgoogle-analyticsmetricsmonitoringmysqlnestjsprivacyredisself-hostedselfhostedstatisticstailwindcssweb-analyticswebanalyticswebsite
Remove Cloudflare based geolocation detection
Blue Mouse9ad937d2467c
diff --git a/backend/apps/selfhosted/src/analytics/analytics.controller.ts b/backend/apps/selfhosted/src/analytics/analytics.controller.tsindex bde436065..59f5c59b7 100644--- a/backend/apps/selfhosted/src/analytics/analytics.controller.ts+++ b/backend/apps/selfhosted/src/analytics/analytics.controller.ts@@ -933,7 +933,7 @@ export class AnalyticsController {const os = ua.os.nameconst osv = this.analyticsService.extractMajorMinorVersion(ua.os.version)- const { city, region, country } = getGeoDetails(ip, eventsDTO.tz, headers)+ const { city, region, country } = getGeoDetails(ip, eventsDTO.tz)const [, psid] = await this.analyticsService.isUnique(eventsDTO.pid,@@ -1026,7 +1026,7 @@ export class AnalyticsController {)}- const { city, region, country } = getGeoDetails(ip, logDTO.tz, headers)+ const { city, region, country } = getGeoDetails(ip, logDTO.tz)const ua = UAParser(userAgent, extensions)const dv = ua.device.type || 'desktop'@@ -1166,7 +1166,7 @@ export class AnalyticsController {const os = ua.os.nameconst osv = this.analyticsService.extractMajorMinorVersion(ua.os.version)- const { city, region, country } = getGeoDetails(ip, null, headers)+ const { city, region, country } = getGeoDetails(ip, null)const transformed = trafficTransformer(psid,@@ -1446,7 +1446,7 @@ export class AnalyticsController {await this.analyticsService.validate(errorDTO, origin, ip)- const { city, region, country } = getGeoDetails(ip, errorDTO.tz, headers)+ const { city, region, country } = getGeoDetails(ip, errorDTO.tz)const ua = UAParser(userAgent, extensions)const dv = ua.device.type || 'desktop'diff --git a/backend/apps/selfhosted/src/common/utils.ts b/backend/apps/selfhosted/src/common/utils.tsindex 1e1316d0f..e3b6484c7 100644--- a/backend/apps/selfhosted/src/common/utils.ts+++ b/backend/apps/selfhosted/src/common/utils.ts@@ -749,11 +749,7 @@ interface IPGeoDetails {city: string | null}-const getGeoDetails = (- ip: string,- tz?: string,- headers?: unknown,-): IPGeoDetails => {+const getGeoDetails = (ip: string, tz?: string): IPGeoDetails => {// Stage 1: Using IP address based geo lookupconst data = lookup.get(ip)@@ -770,20 +766,7 @@ const getGeoDetails = (}}- // Stage 2: If Cloudflare is enabled, use their headers- if (- isProxiedByCloudflare &&- headers['cf-ipcountry'] &&- headers?.['cf-ipcountry'] !== 'XX'- ) {- return {- country: headers['cf-ipcountry'],- city: null,- region: null,- }- }-- // Stage 3: Using timezone based geo lookup as a fallback+ // Stage 2: Using timezone based geo lookup as a fallbackconst tzCountry = timezones.getCountryForTimezone(tz)?.id || nullreturn {