Skip to content

Papermark is the open-source DocSend alternative and secure data rooms with built-in analytics and custom domains.

fix: change path for document metrics

Marc Seitz7df3a48fc62b
diff --git a/lib/types.ts b/lib/types.ts
index 5f3f07f5..95210305 100644
--- a/lib/types.ts
+++ b/lib/types.ts
@@ -112,7 +112,7 @@ export type AnalyticsEvents =
documentId: string;
name: string;
fileSize: string | null | undefined;
- path: string | undefined;
+ path: string | null | undefined;
}
| {
event: "Link Added";
@@ -139,4 +139,4 @@ export type AnalyticsEvents =
| {
event: "Domain Verified";
slug: string;
- };
+ };
\ No newline at end of file
diff --git a/pages/api/documents/index.ts b/pages/api/documents/index.ts
index 995eeb44..029209c6 100644
--- a/pages/api/documents/index.ts
+++ b/pages/api/documents/index.ts
@@ -51,6 +51,13 @@ export default async function handle(
return;
}
+ const referer = req.headers.referer;
+ let pathWithQuery = null;
+ if (referer) {
+ const url = new URL(referer);
+ pathWithQuery = url.pathname + url.search;
+ }
+
// Assuming data is an object with `name` and `description` properties
const { name, url, numPages } = req.body;
@@ -83,7 +90,13 @@ export default async function handle(
documentId: document.id,
name: document.name,
fileSize: null,
- path: req.url,
+ path: pathWithQuery,
+ });
+ await trackAnalytics({
+ event: "Link Added",
+ linkId: document.links[0].id,
+ documentId: document.id,
+ customDomain: null,
});
res.status(201).json(document);