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.

Lookup location for payload IPs. Removed hostname from session id.

Mike Cao0aad3d8e05a1
diff --git a/src/app/api/send/route.ts b/src/app/api/send/route.ts
index 2d220f38c..933ef78e2 100644
--- a/src/app/api/send/route.ts
+++ b/src/app/api/send/route.ts
@@ -87,7 +87,7 @@ export async function POST(request: Request) {
return forbidden();
}
- const sessionId = uuid(websiteId, hostname, ip, userAgent);
+ const sessionId = uuid(websiteId, ip, userAgent);
// Find session
if (!clickhouse.enabled && !cache?.sessionId) {
diff --git a/src/lib/detect.ts b/src/lib/detect.ts
index cd91069e4..9d9fd7db1 100644
--- a/src/lib/detect.ts
+++ b/src/lib/detect.ts
@@ -86,13 +86,13 @@ function decodeHeader(s: string | undefined | null): string | undefined | null {
return Buffer.from(s, 'latin1').toString('utf-8');
}
-export async function getLocation(ip: string = '', headers: Headers) {
+export async function getLocation(ip: string = '', headers: Headers, hasPayloadIP: boolean) {
// Ignore local ips
if (await isLocalhost(ip)) {
return;
}
- if (!process.env.SKIP_LOCATION_HEADERS) {
+ if (!hasPayloadIP && !process.env.SKIP_LOCATION_HEADERS) {
// Cloudflare headers
if (headers.get('cf-ipcountry')) {
const country = decodeHeader(headers.get('cf-ipcountry'));
@@ -147,7 +147,7 @@ export async function getLocation(ip: string = '', headers: Headers) {
export async function getClientInfo(request: Request, payload: Record<string, any>) {
const userAgent = payload?.userAgent || request.headers.get('user-agent');
const ip = payload?.ip || getIpAddress(request.headers);
- const location = await getLocation(ip, request.headers);
+ const location = await getLocation(ip, request.headers, !!payload?.ip);
const country = payload?.userAgent || location?.country;
const subdivision1 = location?.subdivision1;
const subdivision2 = location?.subdivision2;