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.

deprecate qr → move to trigger

Steven Teyeede2bb6a964
diff --git a/apps/web/lib/analytics/constants.ts b/apps/web/lib/analytics/constants.ts
index e8a0822648..04e67916e8 100644
--- a/apps/web/lib/analytics/constants.ts
+++ b/apps/web/lib/analytics/constants.ts
@@ -125,11 +125,6 @@ export const SINGULAR_ANALYTICS_ENDPOINTS = {
triggers: "trigger",
};
-export const TRIGGER_DISPLAY = {
- qr: "QR Scan",
- link: "Link Click",
-};
-
export const VALID_ANALYTICS_FILTERS = [
"domain",
"key",
@@ -151,7 +146,12 @@ export const VALID_ANALYTICS_FILTERS = [
"root",
];
+export const TRIGGER_DISPLAY = {
+ qr: "QR Scan",
+ link: "Link Click",
+};
export const TRIGGER_TYPES = ["qr", "link"] as const;
+
export const EVENT_TYPES = ["clicks", "leads", "sales"] as const;
export const ANALYTICS_VIEWS = ["default", "funnel"] as const;
diff --git a/apps/web/lib/analytics/get-analytics.ts b/apps/web/lib/analytics/get-analytics.ts
index 0357c1da75..dd1620319b 100644
--- a/apps/web/lib/analytics/get-analytics.ts
+++ b/apps/web/lib/analytics/get-analytics.ts
@@ -19,6 +19,8 @@ export const getAnalytics = async (params: AnalyticsFilters) => {
interval,
start,
end,
+ qr,
+ trigger,
timezone = "UTC",
isDemo,
isDeprecatedClicksEndpoint = false,
@@ -70,6 +72,14 @@ export const getAnalytics = async (params: AnalyticsFilters) => {
granularity = INTERVAL_DATA[interval].granularity;
}
+ if (trigger) {
+ if (trigger === "qr") {
+ qr = true;
+ } else if (trigger === "link") {
+ qr = false;
+ }
+ }
+
// Create a Tinybird pipe
const pipe = (isDemo ? tbDemo : tb).buildPipe({
pipe: `v1_${groupBy}`,
@@ -81,6 +91,7 @@ export const getAnalytics = async (params: AnalyticsFilters) => {
...params,
eventType: event,
workspaceId,
+ qr,
start: start.toISOString().replace("T", " ").replace("Z", ""),
end: end.toISOString().replace("T", " ").replace("Z", ""),
granularity,
diff --git a/apps/web/lib/zod/schemas/analytics.ts b/apps/web/lib/zod/schemas/analytics.ts
index 87b184c3c8..e4bdb6d0ad 100644
--- a/apps/web/lib/zod/schemas/analytics.ts
+++ b/apps/web/lib/zod/schemas/analytics.ts
@@ -2,6 +2,7 @@ import {
EVENT_TYPES,
OLD_ANALYTICS_ENDPOINTS,
OLD_TO_NEW_ANALYTICS_ENDPOINTS,
+ TRIGGER_TYPES,
VALID_ANALYTICS_ENDPOINTS,
eventIntervals,
intervals,
@@ -137,6 +138,14 @@ export const analyticsQuerySchema = z.object({
.transform((v) => 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. Available options are: ${TRIGGER_TYPES.join(
+ ", ",
+ )}. If undefined, return both QR and link clicks.`,
+ ),
referer: z
.string()
.optional()
@@ -155,8 +164,9 @@ export const analyticsQuerySchema = z.object({
qr: booleanQuerySchema
.optional()
.describe(
- "Filter for QR code scans. If true, filter for QR codes only. If false, filter for links only. If undefined, return both.",
- ),
+ "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(
diff --git a/apps/web/ui/analytics/devices.tsx b/apps/web/ui/analytics/devices.tsx
index 6390e560f4..af9ce2eafd 100644
--- a/apps/web/ui/analytics/devices.tsx
+++ b/apps/web/ui/analytics/devices.tsx
@@ -55,12 +55,7 @@ export default function Devices() {
? TRIGGER_DISPLAY[d.trigger]
: d[singularTabName],
href: queryParams({
- set:
- tab === "triggers"
- ? {
- qr: d.trigger === "link" ? "false" : "true",
- }
- : { [singularTabName]: d[singularTabName] },
+ set: { [singularTabName]: d[singularTabName] },
getNewPath: true,
}) as string,
value: d[dataKey] || 0,
diff --git a/apps/web/ui/analytics/toggle.tsx b/apps/web/ui/analytics/toggle.tsx
index 9cef42e8e7..34805e4862 100644
--- a/apps/web/ui/analytics/toggle.tsx
+++ b/apps/web/ui/analytics/toggle.tsx
@@ -104,13 +104,13 @@ export default function Toggle({
domain,
key,
tagId,
- qr,
continent,
country,
city,
device,
browser,
os,
+ trigger,
referer,
refererUrl,
url,
@@ -127,13 +127,13 @@ export default function Toggle({
]
: []),
...(tagId ? [{ key: "tagId", value: tagId }] : []),
- ...(qr ? [{ key: "qr", value: qr === "true" }] : []),
...(continent ? [{ key: "continent", value: continent }] : []),
...(country ? [{ key: "country", value: country }] : []),
...(city ? [{ key: "city", value: city }] : []),
...(device ? [{ key: "device", value: device }] : []),
...(browser ? [{ key: "browser", value: browser }] : []),
...(os ? [{ key: "os", value: os }] : []),
+ ...(trigger ? [{ key: "trigger", value: trigger }] : []),
...(referer ? [{ key: "referer", value: referer }] : []),
...(refererUrl ? [{ key: "refererUrl", value: refererUrl }] : []),
...(url ? [{ key: "url", value: url }] : []),
@@ -331,7 +331,7 @@ export default function Toggle({
},
]),
{
- key: "qr",
+ key: "trigger",
icon: CursorRays,
label: "Trigger",
options: