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.

Merge branch 'main' into link-folders

Steven Teyef2608b8fbe2
diff --cc apps/web/lib/zod/schemas/analytics.ts
index a9f31fdc83,07c68fd26a..6fbae49211
--- a/apps/web/lib/zod/schemas/analytics.ts
+++ b/apps/web/lib/zod/schemas/analytics.ts
@@@ -66,133 -67,134 +67,138 @@@ export const analyticsPathParamsSchema
});
// Query schema for /api/analytics endpoint
- export const analyticsQuerySchema = z.object({
- event: analyticsEvents,
- groupBy: analyticsGroupBy,
- domain: z.string().optional().describe("The domain to filter analytics for."),
- key: z.string().optional().describe("The short link slug."),
- linkId: z
- .string()
- .optional()
- .describe("The unique ID of the short link on Dub."),
- externalId: z
- .string()
- .optional()
- .describe(
- "This is the ID of the link in the your database. Must be prefixed with 'ext_' when passed as a query parameter.",
- ),
- interval: z
- .enum(intervals)
- .optional()
- .describe(
- "The interval to retrieve analytics for. If undefined, defaults to 24h.",
- ),
- start: parseDateSchema
- .refine((value: Date) => value >= DUB_FOUNDING_DATE, {
- message: `The start date cannot be earlier than ${formatDate(DUB_FOUNDING_DATE)}.`,
- })
- .optional()
- .describe(
- "The start date and time when to retrieve analytics from. Takes precedence over `interval`.",
- ),
- end: parseDateSchema
- .optional()
- .describe(
- "The end date and time when to retrieve analytics from. If not provided, defaults to the current date. Takes precedence over `interval`.",
- ),
- timezone: z
- .string()
- .optional()
- .describe(
- "The IANA time zone code for aligning timeseries granularity (e.g. America/New_York). Defaults to UTC.",
- )
- .openapi({ example: "America/New_York", default: "UTC" }),
- country: z
- .enum(COUNTRY_CODES)
- .optional()
- .describe("The country to retrieve analytics for.")
- .openapi({ ref: "countryCode" }),
- 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()
- .transform((v) => capitalize(v) as string | undefined)
- .describe("The device to retrieve analytics for.")
- .openapi({ example: "Desktop" }),
- browser: z
- .string()
- .optional()
- .transform((v) => capitalize(v) as string | undefined)
- .describe("The browser to retrieve analytics for.")
- .openapi({ example: "Chrome" }),
- os: z
- .string()
- .optional()
- .transform((v) => {
- if (v === "iOS") return "iOS";
- return capitalize(v) as string | undefined;
- })
- .describe("The OS to retrieve analytics for.")
- .openapi({ example: "Windows" }),
- trigger: z
- .enum(TRIGGER_TYPES)
- .optional()
- .describe(
- "The trigger to retrieve analytics for. If undefined, return both QR and link clicks.",
- ),
- referer: z
- .string()
- .optional()
- .describe("The referer to retrieve analytics for.")
- .openapi({ example: "google.com" }),
- refererUrl: z
- .string()
- .optional()
- .describe("The full referer URL to retrieve analytics for.")
- .openapi({ example: "https://dub.co/blog" }),
- url: z.string().optional().describe("The URL to retrieve analytics for."),
- tagId: z
- .string()
- .optional()
- .describe(
- "Deprecated. Use `tagIds` instead. The tag ID to retrieve analytics for.",
- )
- .openapi({ deprecated: true }),
- tagIds: z
- .union([z.string(), z.array(z.string())])
- .transform((v) => (Array.isArray(v) ? v : v.split(",")))
- .optional()
- .describe("The tag IDs to retrieve analytics for."),
- qr: booleanQuerySchema
- .optional()
- .describe(
- "Deprecated. Use the `trigger` field instead. Filter for QR code scans. If true, filter for QR codes only. If false, filter for links only. If undefined, return both.",
- )
- .openapi({ deprecated: true }),
- root: booleanQuerySchema
- .optional()
- .describe(
- "Filter for root domains. If true, filter for domains only. If false, filter for links only. If undefined, return both.",
- ),
- folderId: z
- .string()
- .optional()
- .describe("The folder ID to retrieve analytics for."),
- });
+ export const analyticsQuerySchema = z
+ .object({
+ event: analyticsEvents,
+ groupBy: analyticsGroupBy,
+ domain: z
+ .string()
+ .optional()
+ .describe("The domain to filter analytics for."),
+ key: z.string().optional().describe("The short link slug."),
+ linkId: z
+ .string()
+ .optional()
+ .describe("The unique ID of the short link on Dub."),
+ externalId: z
+ .string()
+ .optional()
+ .describe(
+ "This is the ID of the link in the your database. Must be prefixed with 'ext_' when passed as a query parameter.",
+ ),
+ interval: z
+ .enum(intervals)
+ .optional()
+ .describe(
+ "The interval to retrieve analytics for. If undefined, defaults to 24h.",
+ ),
+ start: parseDateSchema
+ .refine((value: Date) => value >= DUB_FOUNDING_DATE, {
+ message: `The start date cannot be earlier than ${formatDate(DUB_FOUNDING_DATE)}.`,
+ })
+ .optional()
+ .describe(
+ "The start date and time when to retrieve analytics from. Takes precedence over `interval`.",
+ ),
+ end: parseDateSchema
+ .optional()
+ .describe(
+ "The end date and time when to retrieve analytics from. If not provided, defaults to the current date. Takes precedence over `interval`.",
+ ),
+ timezone: z
+ .string()
+ .optional()
+ .describe(
+ "The IANA time zone code for aligning timeseries granularity (e.g. America/New_York). Defaults to UTC.",
+ )
+ .openapi({ example: "America/New_York", default: "UTC" }),
+ country: z
+ .enum(COUNTRY_CODES)
+ .optional()
+ .describe("The country to retrieve analytics for.")
+ .openapi({ ref: "countryCode" }),
+ 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()
+ .transform((v) => capitalize(v) as string | undefined)
+ .describe("The device to retrieve analytics for.")
+ .openapi({ example: "Desktop" }),
+ browser: z
+ .string()
+ .optional()
+ .transform((v) => capitalize(v) as string | undefined)
+ .describe("The browser to retrieve analytics for.")
+ .openapi({ example: "Chrome" }),
+ os: z
+ .string()
+ .optional()
+ .transform((v) => {
+ if (v === "iOS") return "iOS";
+ return capitalize(v) as string | undefined;
+ })
+ .describe("The OS to retrieve analytics for.")
+ .openapi({ example: "Windows" }),
+ trigger: z
+ .enum(TRIGGER_TYPES)
+ .optional()
+ .describe(
+ "The trigger to retrieve analytics for. If undefined, return both QR and link clicks.",
+ ),
+ referer: z
+ .string()
+ .optional()
+ .describe("The referer to retrieve analytics for.")
+ .openapi({ example: "google.com" }),
+ refererUrl: z
+ .string()
+ .optional()
+ .describe("The full referer URL to retrieve analytics for.")
+ .openapi({ example: "https://dub.co/blog" }),
+ url: z.string().optional().describe("The URL to retrieve analytics for."),
+ tagId: z
+ .string()
+ .optional()
+ .describe(
+ "Deprecated. Use `tagIds` instead. The tag ID to retrieve analytics for.",
+ )
+ .openapi({ deprecated: true }),
+ tagIds: z
+ .union([z.string(), z.array(z.string())])
+ .transform((v) => (Array.isArray(v) ? v : v.split(",")))
+ .optional()
+ .describe("The tag IDs to retrieve analytics for."),
++ folderId: z
++ .string()
++ .optional()
++ .describe("The folder ID to retrieve analytics for."),
+ qr: booleanQuerySchema
+ .optional()
+ .describe(
+ "Deprecated. Use the `trigger` field instead. Filter for QR code scans. If true, filter for QR codes only. If false, filter for links only. If undefined, return both.",
+ )
+ .openapi({ deprecated: true }),
+ root: booleanQuerySchema
+ .optional()
+ .describe(
+ "Filter for root domains. If true, filter for domains only. If false, filter for links only. If undefined, return both.",
+ ),
+ })
+ .merge(utmTagsSchema);
// Analytics filter params for Tinybird endpoints
export const analyticsFilterTB = z
@@@ -232,7 -237,12 +241,13 @@@
referer: true,
refererUrl: true,
tagIds: true,
++ folderId: true,
url: true,
+ utm_source: true,
+ utm_medium: true,
+ utm_campaign: true,
+ utm_term: true,
+ utm_content: true,
}),
);