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.

LocationPin

Steven Teye5d4e6f52817
diff --git a/apps/web/lib/tinybird/record-click.ts b/apps/web/lib/tinybird/record-click.ts
index 05cd854663..a4e5a6bca6 100644
--- a/apps/web/lib/tinybird/record-click.ts
+++ b/apps/web/lib/tinybird/record-click.ts
@@ -102,8 +102,8 @@ export async function recordClick({
typeof ip === "string" && ip.trim().length > 0 && !isEuCountry ? ip : "",
continent: continent || "",
country: geo.country || "Unknown",
- city: geo.city || "Unknown",
region: region || "Unknown",
+ city: geo.city || "Unknown",
latitude: geo.latitude || "Unknown",
longitude: geo.longitude || "Unknown",
vercel_region: req.headers.get("x-vercel-id") || "",
diff --git a/apps/web/lib/zod/schemas/analytics-response.ts b/apps/web/lib/zod/schemas/analytics-response.ts
index 654a5c89f0..d4d3f7eece 100644
--- a/apps/web/lib/zod/schemas/analytics-response.ts
+++ b/apps/web/lib/zod/schemas/analytics-response.ts
@@ -86,61 +86,61 @@ export const analyticsResponse = {
})
.openapi({ ref: "AnalyticsContinents" }),
- regions: z
+ countries: z
.object({
- region: z
- .string()
- .describe(
- "The 2-letter ISO 3166-2 region code representing the region associated with the location of the user.",
- ),
country: z
.enum(COUNTRY_CODES)
- .describe("The 2-letter country code of the region: https://d.to/geo"),
+ .describe(
+ "The 2-letter ISO 3166-1 country code for the country associated with the location of the user. Learn more: https://d.to/geo",
+ ),
+ city: z.literal("*").default("*"),
clicks: z
.number()
- .describe("The number of clicks from this region")
+ .describe("The number of clicks from this country")
.default(0),
leads: z
.number()
- .describe("The number of leads from this region")
+ .describe("The number of leads from this country")
.default(0),
sales: z
.number()
- .describe("The number of sales from this region")
+ .describe("The number of sales from this country")
.default(0),
saleAmount: z
.number()
- .describe("The total amount of sales from this region, in cents")
+ .describe("The total amount of sales from this country, in cents")
.default(0),
})
- .openapi({ ref: "AnalyticsRegions" }),
+ .openapi({ ref: "AnalyticsCountries" }),
- countries: z
+ regions: z
.object({
- country: z
- .enum(COUNTRY_CODES)
+ region: z
+ .string()
.describe(
- "The 2-letter ISO 3166-1 country code for the country associated with the location of the user. Learn more: https://d.to/geo",
+ "The 2-letter ISO 3166-2 region code representing the region associated with the location of the user.",
),
- city: z.literal("*").default("*"),
+ country: z
+ .enum(COUNTRY_CODES)
+ .describe("The 2-letter country code of the region: https://d.to/geo"),
clicks: z
.number()
- .describe("The number of clicks from this country")
+ .describe("The number of clicks from this region")
.default(0),
leads: z
.number()
- .describe("The number of leads from this country")
+ .describe("The number of leads from this region")
.default(0),
sales: z
.number()
- .describe("The number of sales from this country")
+ .describe("The number of sales from this region")
.default(0),
saleAmount: z
.number()
- .describe("The total amount of sales from this country, in cents")
+ .describe("The total amount of sales from this region, in cents")
.default(0),
})
- .openapi({ ref: "AnalyticsCountries" }),
+ .openapi({ ref: "AnalyticsRegions" }),
cities: z
.object({
diff --git a/apps/web/lib/zod/schemas/analytics.ts b/apps/web/lib/zod/schemas/analytics.ts
index 80e38a800f..768061b656 100644
--- a/apps/web/lib/zod/schemas/analytics.ts
+++ b/apps/web/lib/zod/schemas/analytics.ts
@@ -113,16 +113,16 @@ export const analyticsQuerySchema = z.object({
.optional()
.describe("The continent to retrieve analytics for.")
.openapi({ ref: "continentCode" }),
- region: z
- .enum(REGION_CODES)
- .optional()
- .describe("The region to retrieve analytics for.")
- .openapi({ ref: "regionCode" }),
country: z
.enum(COUNTRY_CODES)
.optional()
.describe("The country to retrieve analytics for.")
.openapi({ ref: "countryCode" }),
+ region: z
+ .enum(REGION_CODES)
+ .optional()
+ .describe("The region to retrieve analytics for.")
+ .openapi({ ref: "regionCode" }),
city: z
.string()
.optional()
diff --git a/apps/web/lib/zod/schemas/clicks.ts b/apps/web/lib/zod/schemas/clicks.ts
index f71694116c..cd1c7be5ee 100644
--- a/apps/web/lib/zod/schemas/clicks.ts
+++ b/apps/web/lib/zod/schemas/clicks.ts
@@ -9,8 +9,8 @@ export const clickEventSchemaTB = z.object({
url: z.string(),
continent: z.string().nullable(),
country: z.string().nullable(),
- city: z.string().nullable(),
region: z.string().nullable(),
+ city: z.string().nullable(),
latitude: z.string().nullable(),
longitude: z.string().nullable(),
device: z.string().nullable(),
diff --git a/apps/web/ui/analytics/locations.tsx b/apps/web/ui/analytics/locations.tsx
index 2d2ed7a78d..89c22a8a91 100644
--- a/apps/web/ui/analytics/locations.tsx
+++ b/apps/web/ui/analytics/locations.tsx
@@ -64,7 +64,7 @@ export default function Locations() {
: tab === "regions"
? REGIONS[
`${d.country}-${d.region}`.toUpperCase()
- ] || "Unknown"
+ ] || d.region
: d.city,
href: queryParams({
...(searchParams.has(singularTabName)
diff --git a/apps/web/ui/analytics/toggle.tsx b/apps/web/ui/analytics/toggle.tsx
index df7f7feab2..f38458add4 100644
--- a/apps/web/ui/analytics/toggle.tsx
+++ b/apps/web/ui/analytics/toggle.tsx
@@ -36,6 +36,7 @@ import {
Globe2,
Hyperlink,
LinkBroken,
+ LocationPin,
Magic,
MapPosition,
MobilePhone,
@@ -52,6 +53,7 @@ import {
DUB_DEMO_LINKS,
DUB_LOGO,
GOOGLE_FAVICON_URL,
+ REGIONS,
capitalize,
cn,
fetcher,
@@ -149,6 +151,7 @@ export default function Toggle({
key,
continent,
country,
+ region,
city,
device,
browser,
@@ -174,6 +177,7 @@ export default function Toggle({
: []),
...(continent ? [{ key: "continent", value: continent }] : []),
...(country ? [{ key: "country", value: country }] : []),
+ ...(region ? [{ key: "region", value: region }] : []),
...(city ? [{ key: "city", value: city }] : []),
...(device ? [{ key: "device", value: device }] : []),
...(browser ? [{ key: "browser", value: browser }] : []),
@@ -199,6 +203,9 @@ export default function Toggle({
const countries = useAnalyticsFilterOption("countries", {
cacheOnly: !isRequested("country"),
});
+ const regions = useAnalyticsFilterOption("regions", {
+ cacheOnly: !isRequested("region"),
+ });
const cities = useAnalyticsFilterOption("cities", {
cacheOnly: !isRequested("city"),
});
@@ -441,6 +448,24 @@ export default function Toggle({
right: nFormatter(count, { full: true }),
})) ?? null,
},
+ {
+ key: "region",
+ icon: LocationPin,
+ label: "Region",
+ options:
+ regions?.map(({ region, country, count }) => ({
+ value: region,
+ label: REGIONS[`${country}-${region}`.toUpperCase()] || region,
+ icon: (
+ <img
+ alt={country}
+ src={`https://flag.vercel.app/m/${country}.svg`}
+ className="h-2.5 w-4"
+ />
+ ),
+ right: nFormatter(count, { full: true }),
+ })) ?? null,
+ },
{
key: "device",
icon: MobilePhone,
diff --git a/packages/ui/src/icons/nucleo/index.ts b/packages/ui/src/icons/nucleo/index.ts
index 20db69b361..c26258666f 100644
--- a/packages/ui/src/icons/nucleo/index.ts
+++ b/packages/ui/src/icons/nucleo/index.ts
@@ -88,6 +88,7 @@ export * from "./key";
export * from "./layout-sidebar";
export * from "./lines-y";
export * from "./link-broken";
+export * from "./location-pin";
export * from "./magnifier";
export * from "./map-position";
export * from "./menu3";
diff --git a/packages/ui/src/icons/nucleo/location-pin.tsx b/packages/ui/src/icons/nucleo/location-pin.tsx
new file mode 100644
index 0000000000..b5a6782231
--- /dev/null
+++ b/packages/ui/src/icons/nucleo/location-pin.tsx
@@ -0,0 +1,42 @@
+import { SVGProps } from "react";
+
+export function LocationPin(props: SVGProps<SVGSVGElement>) {
+ return (
+ <svg
+ height="18"
+ width="18"
+ viewBox="0 0 18 18"
+ xmlns="http://www.w3.org/2000/svg"
+ {...props}
+ >
+ <g fill="currentColor">
+ <path
+ d="M13.429,5.978c0,2.609-4.429,7.272-4.429,7.272,0,0-4.429-4.662-4.429-7.272,0-2.675,2.289-4.228,4.429-4.228s4.429,1.552,4.429,4.228Z"
+ fill="none"
+ stroke="currentColor"
+ strokeLinecap="round"
+ strokeLinejoin="round"
+ strokeWidth="1.5"
+ />
+ <path
+ d="M14.381,11.682l1.023,2.5c.404,.987-.322,2.068-1.388,2.068H3.984c-1.066,0-1.792-1.081-1.388-2.068l1.023-2.5"
+ fill="none"
+ stroke="currentColor"
+ strokeLinecap="round"
+ strokeLinejoin="round"
+ strokeWidth="1.5"
+ />
+ <circle
+ cx="9"
+ cy="6"
+ fill="none"
+ r="1.5"
+ stroke="currentColor"
+ strokeLinecap="round"
+ strokeLinejoin="round"
+ strokeWidth="1.5"
+ />
+ </g>
+ </svg>
+ );
+}