Skip to content

armgit / dub

Public Imported from GitHub
0

The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.

Improve eu country filter logic

Steven Tey92a5fa1f858d
diff --git a/apps/web/lib/tinybird/record-click.ts b/apps/web/lib/tinybird/record-click.ts
index e87bba2f26..d217da470b 100644
--- a/apps/web/lib/tinybird/record-click.ts
+++ b/apps/web/lib/tinybird/record-click.ts
@@ -4,6 +4,7 @@ import {
capitalize,
getDomainWithoutWWW,
} from "@dub/utils";
+import { EU_COUNTRY_CODES } from "@dub/utils/src/constants/countries";
import { ipAddress } from "@vercel/edge";
import { nanoid } from "ai";
import { NextRequest, userAgent } from "next/server";
@@ -37,6 +38,7 @@ export async function recordClick({
? req.headers.get("x-vercel-ip-continent")
: LOCALHOST_GEO_DATA.continent;
const geo = process.env.VERCEL === "1" ? req.geo : LOCALHOST_GEO_DATA;
+ const isEuCountry = geo?.country && EU_COUNTRY_CODES.includes(geo.country);
const ua = userAgent(req);
const referer = req.headers.get("referer");
@@ -67,8 +69,8 @@ export async function recordClick({
alias_link_id: "",
url: url || "",
ip:
- // only record IP if it's a valid IP and not from EU
- typeof ip === "string" && ip.trim().length > 0 && continent !== "EU"
+ // only record IP if it's a valid IP and not from a EU country
+ typeof ip === "string" && ip.trim().length > 0 && !isEuCountry
? ip
: "",
continent: continent || "",
diff --git a/packages/utils/src/constants/countries.ts b/packages/utils/src/constants/countries.ts
index b9921ed091..649054d01a 100644
--- a/packages/utils/src/constants/countries.ts
+++ b/packages/utils/src/constants/countries.ts
@@ -252,3 +252,34 @@ export const COUNTRIES: { [key: string]: string } = {
};
export const COUNTRY_CODES = Object.keys(COUNTRIES) as [string, ...string[]];
+
+export const EU_COUNTRY_CODES = [
+ "AT",
+ "BE",
+ "BG",
+ "CY",
+ "CZ",
+ "DE",
+ "DK",
+ "EE",
+ "ES",
+ "FI",
+ "FR",
+ "GB",
+ "GR",
+ "HR",
+ "HU",
+ "IE",
+ "IT",
+ "LT",
+ "LU",
+ "LV",
+ "MT",
+ "NL",
+ "PL",
+ "PT",
+ "RO",
+ "SE",
+ "SI",
+ "SK",
+];