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.

Update workspace.ts

Kiran Kd9b92c256ce1
diff --git a/apps/web/lib/auth/workspace.ts b/apps/web/lib/auth/workspace.ts
index 6a8a34839b..4ba4dbf0f2 100644
--- a/apps/web/lib/auth/workspace.ts
+++ b/apps/web/lib/auth/workspace.ts
@@ -13,6 +13,7 @@ import { throwIfNoAccess } from "../api/tokens/permissions";
import { Scope, mapScopesToPermissions } from "../api/tokens/scopes";
import { normalizeWorkspaceId } from "../api/workspace-id";
import { getFeatureFlags } from "../edge-config";
+import { logConversionEvent } from "../tinybird/log-conversion-events";
import { hashToken } from "./hash-token";
import { Session, getSession } from "./utils";
@@ -68,6 +69,7 @@ export const withWorkspace = (
let apiKey: string | undefined = undefined;
let headers = {};
+ let workspace: WorkspaceWithUsers | undefined;
try {
const authorizationHeader = req.headers.get("Authorization");
@@ -249,7 +251,7 @@ export const withWorkspace = (
}
}
- const workspace = (await prisma.project.findUnique({
+ workspace = (await prisma.project.findUnique({
where: {
id: workspaceId || undefined,
slug: workspaceSlug || undefined,
@@ -396,6 +398,22 @@ export const withWorkspace = (
});
} catch (error) {
req.log.error(error);
+
+ // Log the conversion events for debugging purposes
+ waitUntil(
+ (async () => {
+ const paths = ["/track/lead", "/track/sale"];
+
+ if (workspace && paths.includes(req.nextUrl.pathname)) {
+ logConversionEvent({
+ workspace_slug: workspace.slug,
+ path: req.nextUrl.pathname,
+ error: error.message,
+ });
+ }
+ })(),
+ );
+
return handleAndReturnErrorResponse(error, headers);
}
},