Skip to content

Commit f9eaa2e

Browse files
committed
fix: query GeoIP before IP anonymization for accurate location data
1 parent c0258a1 commit f9eaa2e

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

server/utils/analytics/track.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,15 +93,18 @@ function cleanReferrer(referrer: string): string {
9393
*/
9494
export async function trackClickEvent(event: H3Event, link: Link): Promise<void> {
9595
try {
96-
const ip = anonymizeIP(getClientIP(event));
96+
const rawIp = getClientIP(event);
9797
const userAgent = getHeader(event, "user-agent") ?? "";
9898
const referrer = cleanReferrer(getHeader(event, "referer") ?? "");
9999

100100
// Parse User-Agent
101101
const ua = UAParser(userAgent);
102102

103-
// Query GeoIP
104-
const geo: GeoLocation | null = await geoip.lookup(ip);
103+
// Query GeoIP with original IP for accuracy
104+
const geo: GeoLocation | null = await geoip.lookup(rawIp);
105+
106+
// Anonymize IP for storage (privacy)
107+
const ip = anonymizeIP(rawIp);
105108

106109
// Extract query parameters
107110
const queryParams: Record<string, string> = {};

0 commit comments

Comments
 (0)