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.

fixed events table

Steven Tey7de6ea39a6cf
diff --git a/apps/web/lib/analytics/constants.ts b/apps/web/lib/analytics/constants.ts
index d72bd3719e..f09e4a6509 100644
--- a/apps/web/lib/analytics/constants.ts
+++ b/apps/web/lib/analytics/constants.ts
@@ -134,10 +134,10 @@ export const VALID_ANALYTICS_FILTERS = [
"interval",
"start",
"end",
- "continent",
- "region",
"country",
"city",
+ "region",
+ "continent",
"device",
"browser",
"os",
diff --git a/apps/web/lib/analytics/get-events.ts b/apps/web/lib/analytics/get-events.ts
index fe3b494e1c..a41e7c6494 100644
--- a/apps/web/lib/analytics/get-events.ts
+++ b/apps/web/lib/analytics/get-events.ts
@@ -101,7 +101,8 @@ export const getEvents = async (params: EventsFilters) => {
click: clickEventSchema.parse({
...evt,
id: evt.click_id,
- // normalize referer_url_processed to camelCase
+ // normalize processed values
+ region: evt.region_processed ?? "",
refererUrl: evt.referer_url_processed ?? "",
}),
// transformLink -> add shortLink, qrCode, workspaceId, etc.
diff --git a/apps/web/lib/zod/schemas/analytics.ts b/apps/web/lib/zod/schemas/analytics.ts
index 768061b656..541b7e453f 100644
--- a/apps/web/lib/zod/schemas/analytics.ts
+++ b/apps/web/lib/zod/schemas/analytics.ts
@@ -13,7 +13,6 @@ import {
COUNTRY_CODES,
DUB_FOUNDING_DATE,
PAGINATION_LIMIT,
- REGION_CODES,
capitalize,
formatDate,
} from "@dub/utils";
@@ -108,26 +107,26 @@ export const analyticsQuerySchema = z.object({
"The IANA time zone code for aligning timeseries granularity (e.g. America/New_York). Defaults to UTC.",
)
.openapi({ example: "America/New_York", default: "UTC" }),
- continent: z
- .enum(CONTINENT_CODES)
- .optional()
- .describe("The continent to retrieve analytics for.")
- .openapi({ ref: "continentCode" }),
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()
.describe("The city to retrieve analytics for.")
.openapi({ example: "New York" }),
+ region: z
+ .string()
+ .optional()
+ .describe("The ISO 3166-2 region code to retrieve analytics for.")
+ .openapi({ ref: "regionCode" }),
+ continent: z
+ .enum(CONTINENT_CODES)
+ .optional()
+ .describe("The continent to retrieve analytics for.")
+ .openapi({ ref: "continentCode" }),
device: z
.string()
.optional()
diff --git a/apps/web/lib/zod/schemas/clicks.ts b/apps/web/lib/zod/schemas/clicks.ts
index d04170e23d..a32da5d565 100644
--- a/apps/web/lib/zod/schemas/clicks.ts
+++ b/apps/web/lib/zod/schemas/clicks.ts
@@ -40,6 +40,7 @@ export const clickEventSchemaTBEndpoint = z.object({
country: z.string().nullable(),
city: z.string().nullable(),
region: z.string().nullable(),
+ region_processed: z.string().nullable(),
continent: z.string().nullable(),
device: z.string().nullable(),
browser: z.string().nullable(),
diff --git a/apps/web/lib/zod/schemas/leads.ts b/apps/web/lib/zod/schemas/leads.ts
index 0db78a7bf9..21c0c4a792 100644
--- a/apps/web/lib/zod/schemas/leads.ts
+++ b/apps/web/lib/zod/schemas/leads.ts
@@ -99,6 +99,8 @@ export const leadEventSchemaTBEndpoint = z.object({
continent: z.string().nullable(),
country: z.string().nullable(),
city: z.string().nullable(),
+ region: z.string().nullable(),
+ region_processed: z.string().nullable(),
device: z.string().nullable(),
browser: z.string().nullable(),
os: z.string().nullable(),
diff --git a/apps/web/lib/zod/schemas/sales.ts b/apps/web/lib/zod/schemas/sales.ts
index 6084fdc272..0fc9e26b1d 100644
--- a/apps/web/lib/zod/schemas/sales.ts
+++ b/apps/web/lib/zod/schemas/sales.ts
@@ -106,6 +106,8 @@ export const saleEventSchemaTBEndpoint = z.object({
continent: z.string().nullable(),
country: z.string().nullable(),
city: z.string().nullable(),
+ region: z.string().nullable(),
+ region_processed: z.string().nullable(),
device: z.string().nullable(),
browser: z.string().nullable(),
os: z.string().nullable(),
diff --git a/apps/web/ui/analytics/events/events-table.tsx b/apps/web/ui/analytics/events/events-table.tsx
index 872c98e769..80aca57b57 100644
--- a/apps/web/ui/analytics/events/events-table.tsx
+++ b/apps/web/ui/analytics/events/events-table.tsx
@@ -270,7 +270,7 @@ export default function EventsTable({
/>
)}
<span className="truncate">
- {REGIONS[`${row.original.country}-${getValue()}`] || getValue()}
+ {REGIONS[getValue()] || getValue().split("-")[1]}
</span>
</div>
),
diff --git a/apps/web/ui/analytics/locations.tsx b/apps/web/ui/analytics/locations.tsx
index 0174d40ba3..4eee2219a5 100644
--- a/apps/web/ui/analytics/locations.tsx
+++ b/apps/web/ui/analytics/locations.tsx
@@ -62,7 +62,7 @@ export default function Locations() {
: tab === "countries"
? COUNTRIES[d.country]
: tab === "regions"
- ? REGIONS[`${d.country}-${d.region}`] || d.region
+ ? REGIONS[d.region] || d.region.split("-")[1]
: d.city,
href: queryParams({
...(searchParams.has(singularTabName)
diff --git a/apps/web/ui/analytics/toggle.tsx b/apps/web/ui/analytics/toggle.tsx
index f38458add4..3e3eb57a38 100644
--- a/apps/web/ui/analytics/toggle.tsx
+++ b/apps/web/ui/analytics/toggle.tsx
@@ -455,7 +455,7 @@ export default function Toggle({
options:
regions?.map(({ region, country, count }) => ({
value: region,
- label: REGIONS[`${country}-${region}`.toUpperCase()] || region,
+ label: REGIONS[region] || region.split("-")[1],
icon: (
<img
alt={country}