The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
Add continent to API
Steven Tey384c115fd521
diff --git a/apps/web/lib/analytics/constants.ts b/apps/web/lib/analytics/constants.tsindex 0d566de312..7efc8c9648 100644--- a/apps/web/lib/analytics/constants.ts+++ b/apps/web/lib/analytics/constants.ts@@ -83,7 +83,7 @@ export const INTERVAL_DATA: Record<export const VALID_ANALYTICS_ENDPOINTS = ["count","timeseries",- // "continents",+ "continents","countries","cities","devices",@@ -96,7 +96,7 @@ export const VALID_ANALYTICS_ENDPOINTS = [] as const;export const SINGULAR_ANALYTICS_ENDPOINTS = {- // continents: "continent",+ continents: "continent",countries: "country",cities: "city",devices: "device",diff --git a/apps/web/lib/zod/schemas/clicks-analytics.ts b/apps/web/lib/zod/schemas/clicks-analytics.tsindex 6f950f6e53..047a510271 100644--- a/apps/web/lib/zod/schemas/clicks-analytics.ts+++ b/apps/web/lib/zod/schemas/clicks-analytics.ts@@ -1,5 +1,5 @@import z from "@/lib/zod";-import { COUNTRY_CODES } from "@dub/utils";+import { CONTINENT_CODES, COUNTRY_CODES } from "@dub/utils";// Click analytics response schemasexport const clickAnalyticsResponse = {@@ -16,16 +16,16 @@ export const clickAnalyticsResponse = {}).openapi({ ref: "ClicksTimeseries" }),- // continents: z- // .object({- // continent: z- // .enum(CONTINENT_CODES)- // .describe(- // "The 2-letter ISO 3166-1 code representing the continent associated with the location of the user.",- // ),- // clicks: z.number().describe("The number of clicks from this continent"),- // })- // .openapi({ ref: "ClicksContinents" }),+ continents: z+ .object({+ continent: z+ .enum(CONTINENT_CODES)+ .describe(+ "The 2-letter ISO 3166-1 code representing the continent associated with the location of the user.",+ ),+ clicks: z.number().describe("The number of clicks from this continent"),+ })+ .openapi({ ref: "ClicksContinents" }),countries: z.object({diff --git a/apps/web/lib/zod/schemas/clicks.ts b/apps/web/lib/zod/schemas/clicks.tsindex b8713fd96d..9a8c5f27a9 100644--- a/apps/web/lib/zod/schemas/clicks.ts+++ b/apps/web/lib/zod/schemas/clicks.ts@@ -5,6 +5,7 @@ export const clickEventSchemaTB = z.object({click_id: z.string(),link_id: z.string(),url: z.string(),+ continent: z.string().nullable(),country: z.string().nullable(),city: z.string().nullable(),region: z.string().nullable(),diff --git a/apps/web/lib/zod/schemas/composite-analytics.ts b/apps/web/lib/zod/schemas/composite-analytics.tsindex 165f59b2d8..f5f7925739 100644--- a/apps/web/lib/zod/schemas/composite-analytics.ts+++ b/apps/web/lib/zod/schemas/composite-analytics.ts@@ -1,5 +1,5 @@import z from "@/lib/zod";-import { COUNTRY_CODES } from "@dub/utils";+import { CONTINENT_CODES, COUNTRY_CODES } from "@dub/utils";export const compositeAnalyticsResponse = {count: z.object({@@ -17,19 +17,19 @@ export const compositeAnalyticsResponse = {amount: z.number().describe("The total amount of sales in the interval"),}),- // continents: z.object({- // continent: z- // .enum(CONTINENT_CODES)- // .describe(- // "The 2-letter ISO 3166-1 code representing the continent associated with the location of the user.",- // ),- // clicks: z.number().describe("The number of clicks from this continent"),- // leads: z.number().describe("The number of leads from this continent"),- // sales: z.number().describe("The number of sales from this continent"),- // amount: z- // .number()- // .describe("The total amount of sales from this continent"),- // }),+ continents: z.object({+ continent: z+ .enum(CONTINENT_CODES)+ .describe(+ "The 2-letter ISO 3166-1 code representing the continent associated with the location of the user.",+ ),+ clicks: z.number().describe("The number of clicks from this continent"),+ leads: z.number().describe("The number of leads from this continent"),+ sales: z.number().describe("The number of sales from this continent"),+ amount: z+ .number()+ .describe("The total amount of sales from this continent"),+ }),countries: z.object({diff --git a/apps/web/lib/zod/schemas/leads-analytics.ts b/apps/web/lib/zod/schemas/leads-analytics.tsindex de8e4eec2d..6100df7ec3 100644--- a/apps/web/lib/zod/schemas/leads-analytics.ts+++ b/apps/web/lib/zod/schemas/leads-analytics.ts@@ -1,5 +1,5 @@import z from "@/lib/zod";-import { COUNTRY_CODES } from "@dub/utils";+import { CONTINENT_CODES, COUNTRY_CODES } from "@dub/utils";export const leadAnalyticsResponse = {count: z@@ -15,16 +15,16 @@ export const leadAnalyticsResponse = {}).openapi({ ref: "LeadsTimeseries" }),- // continents: z- // .object({- // continent: z- // .enum(CONTINENT_CODES)- // .describe(- // "The 2-letter ISO 3166-1 code representing the continent associated with the location of the user.",- // ),- // leads: z.number().describe("The number of leads from this continent"),- // })- // .openapi({ ref: "LeadsContinents" }),+ continents: z+ .object({+ continent: z+ .enum(CONTINENT_CODES)+ .describe(+ "The 2-letter ISO 3166-1 code representing the continent associated with the location of the user.",+ ),+ leads: z.number().describe("The number of leads from this continent"),+ })+ .openapi({ ref: "LeadsContinents" }),countries: z.object({diff --git a/apps/web/lib/zod/schemas/sales-analytics.ts b/apps/web/lib/zod/schemas/sales-analytics.tsindex 3a74ada69e..4b6cecfa60 100644--- a/apps/web/lib/zod/schemas/sales-analytics.ts+++ b/apps/web/lib/zod/schemas/sales-analytics.ts@@ -1,5 +1,5 @@import z from "@/lib/zod";-import { COUNTRY_CODES } from "@dub/utils";+import { CONTINENT_CODES, COUNTRY_CODES } from "@dub/utils";export const saleAnalyticsResponse = {count: z@@ -17,16 +17,16 @@ export const saleAnalyticsResponse = {}).openapi({ ref: "SalesTimeseries" }),- // continents: z- // .object({- // continent: z- // .enum(CONTINENT_CODES)- // .describe(- // "The 2-letter ISO 3166-1 code representing the continent associated with the location of the user.",- // ),- // sales: z.number().describe("The number of sales from this continent"),- // })- // .openapi({ ref: "SalesContinents" }),+ continents: z+ .object({+ continent: z+ .enum(CONTINENT_CODES)+ .describe(+ "The 2-letter ISO 3166-1 code representing the continent associated with the location of the user.",+ ),+ sales: z.number().describe("The number of sales from this continent"),+ })+ .openapi({ ref: "SalesContinents" }),countries: z.object({diff --git a/apps/web/ui/analytics/continent-icon.tsx b/apps/web/ui/analytics/continent-icon.tsxnew file mode 100644index 0000000000..d4c28f752d--- /dev/null+++ b/apps/web/ui/analytics/continent-icon.tsx@@ -0,0 +1,34 @@+import {+ Africa,+ Asia,+ Europe,+ Globe,+ NorthAmerica,+ Oceania,+ SouthAmerica,+} from "@dub/ui/src/icons";++export default function ContinentIcon({+ display,+ className,+}: {+ display: string;+ className?: string;+}) {+ switch (display) {+ case "AF":+ return <Africa className={className} />;+ case "AS":+ return <Asia className={className} />;+ case "EU":+ return <Europe className={className} />;+ case "NA":+ return <NorthAmerica className={className} />;+ case "OC":+ return <Oceania className={className} />;+ case "SA":+ return <SouthAmerica className={className} />;+ default:+ return <Globe className={className} />;+ }+}diff --git a/apps/web/ui/analytics/locations.tsx b/apps/web/ui/analytics/locations.tsxindex 2dc918cfa8..b27090c860 100644--- a/apps/web/ui/analytics/locations.tsx+++ b/apps/web/ui/analytics/locations.tsx@@ -1,16 +1,19 @@import { SINGULAR_ANALYTICS_ENDPOINTS } from "@/lib/analytics/constants";import { useRouterStuff } from "@dub/ui";-import { COUNTRIES } from "@dub/utils";+import { CONTINENTS, COUNTRIES } from "@dub/utils";import { useState } from "react";import { AnalyticsCard } from "./analytics-card";import { AnalyticsLoadingSpinner } from "./analytics-loading-spinner";import BarList from "./bar-list";+import ContinentIcon from "./continent-icon";import { useAnalyticsFilterOption } from "./utils";export default function Locations() {const { queryParams } = useRouterStuff();- const [tab, setTab] = useState<"countries" | "cities">("countries");+ const [tab, setTab] = useState<"countries" | "cities" | "continents">(+ "continents",+ );const data = useAnalyticsFilterOption(tab);const singularTabName = SINGULAR_ANALYTICS_ENDPOINTS[tab];@@ -19,6 +22,7 @@ export default function Locations() {tabs={[{ id: "countries", label: "Countries" },{ id: "cities", label: "Cities" },+ { id: "continents", label: "Continents" },]}selectedTabId={tab}onSelectTab={setTab}@@ -32,14 +36,22 @@ export default function Locations() {tab={singularTabName}data={data?.map((d) => ({- icon: (- <img- alt={d.country}- src={`https://flag.vercel.app/m/${d.country}.svg`}- className="h-3 w-5"- />- ),- title: tab === "countries" ? COUNTRIES[d.country] : d.city,+ icon:+ tab === "continents" ? (+ <ContinentIcon display={d.continent} className="size-3" />+ ) : (+ <img+ alt={d.country}+ src={`https://flag.vercel.app/m/${d.country}.svg`}+ className="h-3 w-5"+ />+ ),+ title:+ tab === "continents"+ ? CONTINENTS[d.continent]+ : tab === "countries"+ ? COUNTRIES[d.country]+ : d.city,href: queryParams({set: {[singularTabName]: d[singularTabName],diff --git a/packages/ui/src/icons/continents/af.tsx b/packages/ui/src/icons/continents/af.tsxindex 2d5b069bca..f73005c225 100644--- a/packages/ui/src/icons/continents/af.tsx+++ b/packages/ui/src/icons/continents/af.tsx@@ -11,7 +11,7 @@ export function Africa(props: SVGProps<SVGSVGElement>) {{...props}><path- fill="#E0F1FA"+ fill="#FFFFFF"d="M213 106.488a106.443 106.443 0 01-18.316 59.747 106.46 106.46 0 01-48.693 39.175 106.471 106.471 0 01-123.986-34.114A106.772 106.772 0 012.147 85.132l.113-.548A106.661 106.661 0 0164.898 8.452 105.59 105.59 0 0198.774.387c2.63-.29 5.162-.387 7.727-.387a106.36 106.36 0 0172.29 28.22 106.338 106.338 0 0133.871 69.816c.226 2.774.338 5.613.338 8.452z"></path><pathdiff --git a/packages/ui/src/icons/continents/as.tsx b/packages/ui/src/icons/continents/as.tsxindex 5ecfbc626f..2e233df657 100644--- a/packages/ui/src/icons/continents/as.tsx+++ b/packages/ui/src/icons/continents/as.tsx@@ -11,7 +11,7 @@ export function Asia(props: SVGProps<SVGSVGElement>) {{...props}><path- fill="#E0F1FA"+ fill="#FFFFFF"d="M213.003 106.562a106.13 106.13 0 01-20.854 63.336 34.038 34.038 0 01-1.161 1.517c-.403.501-.468.614-.694.888a109.13 109.13 0 01-2.435 3.002c-.823.985-1.613 1.937-2.516 2.873-.565.63-1.129 1.259-1.726 1.873l-1.79 1.824-1.823 1.791-.919.84a106.43 106.43 0 01-39.957 23.405 106.368 106.368 0 01-89.64-11.556 106.499 106.499 0 01-32.726-32.777A106.606 106.606 0 015.285 73.859a106.547 106.547 0 0123.42-39.97A106.446 106.446 0 0166.863 7.652 105.554 105.554 0 01106.524 0c1.354 0 2.693 0 4.048.096 6.637.23 13.236 1.096 19.709 2.583a106.762 106.762 0 0124.708 8.974 106.482 106.482 0 0142.371 39.272 106.589 106.589 0 0115.643 55.636z"></path><pathdiff --git a/packages/ui/src/icons/continents/eu.tsx b/packages/ui/src/icons/continents/eu.tsxindex 4925e72b14..dd0bac93e8 100644--- a/packages/ui/src/icons/continents/eu.tsx+++ b/packages/ui/src/icons/continents/eu.tsx@@ -11,7 +11,7 @@ export function Europe(props: SVGProps<SVGSVGElement>) {{...props}><path- fill="#E0F1FA"+ fill="#FFFFFF"d="M213 106.492a106.621 106.621 0 01-23.473 66.66 106.54 106.54 0 01-59.996 37.317 106.502 106.502 0 01-70.142-8.431 106.568 106.568 0 01-49.451-50.473A106.709 106.709 0 0122.004 41.698c3.5-4.554 7.357-8.823 11.534-12.765A106.445 106.445 0 01104.14.026a106.442 106.442 0 0171.807 25.76 106.37 106.37 0 0127.348 36.3A106.418 106.418 0 01213 106.492z"></path><pathdiff --git a/packages/ui/src/icons/continents/index.tsx b/packages/ui/src/icons/continents/index.tsxindex c42614a238..8e0ee99446 100644--- a/packages/ui/src/icons/continents/index.tsx+++ b/packages/ui/src/icons/continents/index.tsx@@ -1,3 +1,5 @@+// Icons adapted to JSX from https://www.figma.com/community/file/1009565851324834062+export * from "./af";export * from "./as";export * from "./eu";diff --git a/packages/ui/src/icons/continents/na.tsx b/packages/ui/src/icons/continents/na.tsxindex 73aa6b1e40..b7d7d7e9d1 100644--- a/packages/ui/src/icons/continents/na.tsx+++ b/packages/ui/src/icons/continents/na.tsx@@ -11,7 +11,7 @@ export function NorthAmerica(props: SVGProps<SVGSVGElement>) {{...props}><path- fill="#E0F1FA"+ fill="#FFFFFF"d="M213 106.662a106.143 106.143 0 01-7.326 38.931 106.35 106.35 0 01-39.167 48.966A106.65 106.65 0 01106.512 213C47.677 213-.718 165.388.008 106.694.395 74.561 16.145 44.135 36.01 27.03A107.902 107.902 0 0191.992 1.415a107.993 107.993 0 0160.898 9.153 106.334 106.334 0 0142.036 36.515 105.94 105.94 0 0117.428 48.03c.43 3.835.646 7.691.646 11.549z"></path><pathdiff --git a/packages/ui/src/icons/continents/oc.tsx b/packages/ui/src/icons/continents/oc.tsxindex f1604ea778..650def2b2f 100644--- a/packages/ui/src/icons/continents/oc.tsx+++ b/packages/ui/src/icons/continents/oc.tsx@@ -11,7 +11,7 @@ export function Oceania(props: SVGProps<SVGSVGElement>) {{...props}><path- fill="#E0F1FA"+ fill="#FFFFFF"d="M213 106.511a106.46 106.46 0 01-41.551 84.221 106.505 106.505 0 01-92.07 18.583 106.513 106.513 0 01-42.636-22.51A106.473 106.473 0 01.17 100.306a106.464 106.464 0 0113.56-46.26 106.49 106.49 0 0139.06-39.558A106.516 106.516 0 01106.468 0c2.888 0 5.76.113 8.6.339a106.509 106.509 0 0169.723 33.948A106.468 106.468 0 01213 106.511z"></path><pathdiff --git a/packages/ui/src/icons/continents/sa.tsx b/packages/ui/src/icons/continents/sa.tsxindex b7b53746b2..b2534cf630 100644--- a/packages/ui/src/icons/continents/sa.tsx+++ b/packages/ui/src/icons/continents/sa.tsx@@ -11,7 +11,7 @@ export function SouthAmerica(props: SVGProps<SVGSVGElement>) {{...props}><path- fill="#E0F1FA"+ fill="#FFFFFF"d="M212.999 106.426a106.541 106.541 0 01-17.707 58.869 106.504 106.504 0 01-47.28 39.28 106.48 106.48 0 01-115.687-21.659A106.546 106.546 0 017.228 67.902 106.52 106.52 0 0145.07 19.46 106.484 106.484 0 01103.372 0h3.224a106.127 106.127 0 0184.8 42.103 105.715 105.715 0 0121.136 54.084c.326 3.403.482 6.82.467 10.239z"></path><path