The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
WIP support showing Region
Kiran K1fe7226fc3af
diff --git a/apps/web/lib/analytics/constants.ts b/apps/web/lib/analytics/constants.tsindex 2410a4bbad..d72bd3719e 100644--- a/apps/web/lib/analytics/constants.ts+++ b/apps/web/lib/analytics/constants.ts@@ -101,6 +101,7 @@ export const VALID_ANALYTICS_ENDPOINTS = ["count","timeseries","continents",+ "regions","countries","cities","devices",@@ -116,6 +117,7 @@ export const VALID_ANALYTICS_ENDPOINTS = [export const SINGULAR_ANALYTICS_ENDPOINTS = {continents: "continent",+ regions: "region",countries: "country",cities: "city",devices: "device",@@ -133,6 +135,7 @@ export const VALID_ANALYTICS_FILTERS = ["start","end","continent",+ "region","country","city","device",diff --git a/apps/web/lib/analytics/types.ts b/apps/web/lib/analytics/types.tsindex 039b22d617..b479de4e4f 100644--- a/apps/web/lib/analytics/types.ts+++ b/apps/web/lib/analytics/types.ts@@ -25,8 +25,6 @@ export type EventType = (typeof EVENT_TYPES)[number];export type AnalyticsView = (typeof ANALYTICS_VIEWS)[number];-export type LocationTabs = "countries" | "cities";-export type TopLinksTabs = "link" | "url";export type DeviceTabs = "devices" | "browsers" | "os" | "triggers";export type RefererTabs = "referers" | "referer_urls";diff --git a/apps/web/lib/zod/schemas/analytics-response.ts b/apps/web/lib/zod/schemas/analytics-response.tsindex 76c9048589..f0f6a4032c 100644--- a/apps/web/lib/zod/schemas/analytics-response.ts+++ b/apps/web/lib/zod/schemas/analytics-response.ts@@ -1,6 +1,6 @@import { TRIGGER_TYPES } from "@/lib/analytics/constants";import z from "@/lib/zod";-import { CONTINENT_CODES, COUNTRY_CODES } from "@dub/utils";+import { CONTINENT_CODES, COUNTRY_CODES, REGION_CODES } from "@dub/utils";const analyticsTriggersResponse = z.object({@@ -86,6 +86,35 @@ export const analyticsResponse = {}).openapi({ ref: "AnalyticsContinents" }),+ regions: z+ .object({+ region: z+ .enum(REGION_CODES)+ .describe(+ "The 2-letter ISO 3166-2 code representing the region associated with the location of the user.",+ ),+ country: z+ .enum(COUNTRY_CODES)+ .describe("The 2-letter country code of the city: https://d.to/geo"),+ clicks: z+ .number()+ .describe("The number of clicks from this region")+ .default(0),+ leads: z+ .number()+ .describe("The number of leads from this region")+ .default(0),+ sales: z+ .number()+ .describe("The number of sales from this region")+ .default(0),+ saleAmount: z+ .number()+ .describe("The total amount of sales from this region, in cents")+ .default(0),+ })+ .openapi({ ref: "AnalyticsRegions" }),+countries: z.object({country: zdiff --git a/apps/web/lib/zod/schemas/analytics.ts b/apps/web/lib/zod/schemas/analytics.tsindex 66a96c2eec..6a8dc7e8ff 100644--- a/apps/web/lib/zod/schemas/analytics.ts+++ b/apps/web/lib/zod/schemas/analytics.ts@@ -112,6 +112,11 @@ export const analyticsQuerySchema = z.object({.optional().describe("The continent to retrieve analytics for.").openapi({ ref: "continentCode" }),+ region: z+ .string()+ .optional()+ .describe("The region to retrieve analytics for.")+ .openapi({ example: "California" }),country: z.enum(COUNTRY_CODES).optional()diff --git a/apps/web/ui/analytics/locations.tsx b/apps/web/ui/analytics/locations.tsxindex 33692ebaca..cc0a9bba13 100644--- a/apps/web/ui/analytics/locations.tsx+++ b/apps/web/ui/analytics/locations.tsx@@ -15,9 +15,10 @@ export default function Locations() {const { selectedTab } = useContext(AnalyticsContext);const dataKey = selectedTab === "sales" ? "saleAmount" : "count";- const [tab, setTab] = useState<"countries" | "cities" | "continents">(- "countries",- );+ const [tab, setTab] = useState<+ "countries" | "cities" | "continents" | "regions"+ >("countries");+const data = useAnalyticsFilterOption(tab);const singularTabName = SINGULAR_ANALYTICS_ENDPOINTS[tab];@@ -26,6 +27,7 @@ export default function Locations() {tabs={[{ id: "countries", label: "Countries" },{ id: "cities", label: "Cities" },+ { id: "regions", label: "Regions" },{ id: "continents", label: "Continents" },]}selectedTabId={tab}diff --git a/packages/utils/src/constants/index.ts b/packages/utils/src/constants/index.tsindex a0f5ea5867..d72440a808 100644--- a/packages/utils/src/constants/index.ts+++ b/packages/utils/src/constants/index.ts@@ -13,4 +13,5 @@ export * from "./middleware";export * from "./misc";export * from "./partners";export * from "./pricing";+export * from "./regions";export * from "./saml";diff --git a/packages/utils/src/constants/regions.ts b/packages/utils/src/constants/regions.tsnew file mode 100644index 0000000000..aafd3fbcde--- /dev/null+++ b/packages/utils/src/constants/regions.ts@@ -0,0 +1,5 @@+export const REGIONS: { [key: string]: string } = {+ //+};++export const REGION_CODES = Object.keys(REGIONS) as [string, ...string[]];