Skip to content

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

refactor(analytics): link added

Marc Seitzbf56d615fde4
diff --git a/components/links/link-sheet/index.tsx b/components/links/link-sheet/index.tsx
index dca8794c..8b9b6a7e 100644
--- a/components/links/link-sheet/index.tsx
+++ b/components/links/link-sheet/index.tsx
@@ -20,6 +20,7 @@ import DomainSection from "./domain-section";
import { useTeam } from "@/context/team-context";
import { ScrollArea } from "@/components/ui/scroll-area";
import { LinkOptions } from "./link-options";
+import { useAnalytics } from "@/lib/analytics";
export const DEFAULT_LINK_PROPS = {
id: null,
@@ -73,6 +74,7 @@ export default function LinkSheet({
const { links } = useDocumentLinks();
const { domains } = useDomains();
const teamInfo = useTeam();
+ const analytics = useAnalytics();
const [data, setData] = useState<DEFAULT_LINK_TYPE>(DEFAULT_LINK_PROPS);
const [isLoading, setIsLoading] = useState<boolean>(false);
@@ -155,6 +157,13 @@ export default function LinkSheet({
[...(links || []), returnedLink],
false,
);
+
+ analytics.capture("Link Added", {
+ linkId: returnedLink.id,
+ documentId,
+ customDomain: returnedLink.domainSlug,
+ });
+
toast.success("Link created successfully");
}
diff --git a/pages/api/links/index.ts b/pages/api/links/index.ts
index ca1af7a3..b53a9a6d 100644
--- a/pages/api/links/index.ts
+++ b/pages/api/links/index.ts
@@ -3,7 +3,6 @@ import prisma from "@/lib/prisma";
import { getServerSession } from "next-auth/next";
import { authOptions } from "../auth/[...nextauth]";
import { hashPassword } from "@/lib/utils";
-import { identifyUser, trackAnalytics } from "@/lib/analytics";
import { CustomUser } from "@/lib/types";
import { errorhandler } from "@/lib/errorHandler";
import {
@@ -119,14 +118,6 @@ export default async function handler(
return res.status(404).json({ error: "Link not found" });
}
- await identifyUser((session.user as CustomUser).id);
- await trackAnalytics({
- event: "Link Added",
- linkId: linkWithView.id,
- documentId: linkWithView.documentId,
- customDomain: linkWithView.domainSlug,
- });
-
return res.status(200).json(linkWithView);
} catch (error) {
errorhandler(error, res);