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.

add timezone support

Steven Teyd8aa8b02c59b
diff --git a/apps/web/lib/analytics/get-analytics.ts b/apps/web/lib/analytics/get-analytics.ts
index 31f54b812a..0381046cf2 100644
--- a/apps/web/lib/analytics/get-analytics.ts
+++ b/apps/web/lib/analytics/get-analytics.ts
@@ -35,7 +35,16 @@ export const getAnalytics = async (
eventType: AnalyticsEventType,
params: AnalyticsFilters,
) => {
- let { workspaceId, linkId, interval, start, end, isDemo, endpoint } = params;
+ let {
+ workspaceId,
+ linkId,
+ interval,
+ start,
+ end,
+ timezone,
+ isDemo,
+ endpoint,
+ } = params;
// get all-time clicks count if:
// 1. linkId is defined
@@ -104,6 +113,7 @@ export const getAnalytics = async (
start: start.toISOString().replace("T", " ").replace("Z", ""),
end: end.toISOString().replace("T", " ").replace("Z", ""),
granularity,
+ timezone,
});
// for total clicks|leads, we return just the value;
diff --git a/apps/web/lib/zod/schemas/analytics.ts b/apps/web/lib/zod/schemas/analytics.ts
index 35b2d0af1e..5eda368726 100644
--- a/apps/web/lib/zod/schemas/analytics.ts
+++ b/apps/web/lib/zod/schemas/analytics.ts
@@ -78,6 +78,13 @@ export const analyticsQuerySchema = z.object({
.describe(
"The end date and time when to retrieve analytics from. If not provided, defaults to the current date.",
),
+ timezone: z
+ .string()
+ .optional()
+ .default("UTC")
+ .describe(
+ "The IANA time zone code for aligning timeseries granularity (e.g. America/New_York). Defaults to UTC.",
+ ),
country: z
.enum(COUNTRY_CODES)
.optional()
@@ -145,6 +152,7 @@ export const analyticsFilterTB = z
start: z.string(),
end: z.string(),
granularity: z.enum(["minute", "hour", "day", "month"]).optional(),
+ timezone: z.string().optional(),
})
.merge(
analyticsQuerySchema.pick({
diff --git a/apps/web/ui/analytics/index.tsx b/apps/web/ui/analytics/index.tsx
index afa96c8966..3f7365c2f6 100644
--- a/apps/web/ui/analytics/index.tsx
+++ b/apps/web/ui/analytics/index.tsx
@@ -146,6 +146,7 @@ export default function Analytics({
end && { start: start.toISOString(), end: end.toISOString() }),
...(tagId && { tagId }),
...availableFilterParams,
+ timezone: Intl.DateTimeFormat().resolvedOptions().timeZone,
}).toString();
}, [id, domain, key, searchParams, start, end, tagId]);