Skip to content

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

feat: add tracking to link adding

Marc Seitz2a794381602b
diff --git a/components/documents/document-header.tsx b/components/documents/document-header.tsx
index 3cc6ed21..8112fb3d 100644
--- a/components/documents/document-header.tsx
+++ b/components/documents/document-header.tsx
@@ -4,6 +4,7 @@ import { useRouter } from "next/router";
import { useEffect, useRef, useState } from "react";
import { useTeam } from "@/context/team-context";
+import { DocumentAIDialog } from "@/ee/features/ai/components/document-ai-dialog";
import { PlanEnum } from "@/ee/stripe/constants";
import { Document, DocumentVersion } from "@prisma/client";
import {
@@ -26,7 +27,6 @@ import { useTheme } from "next-themes";
import { toast } from "sonner";
import { mutate } from "swr";
-import { DocumentAIDialog } from "@/ee/features/ai/components/document-ai-dialog";
import { getFile } from "@/lib/files/get-file";
import { usePlan } from "@/lib/swr/use-billing";
import useDatarooms from "@/lib/swr/use-datarooms";
@@ -545,6 +545,7 @@ export default function DocumentHeader({
<div className="flex items-center gap-x-4 md:gap-x-2">
{primaryVersion.type !== "notion" &&
+ primaryVersion.type !== "link" &&
primaryVersion.type !== "sheet" &&
primaryVersion.type !== "zip" &&
primaryVersion.type !== "video" &&
@@ -571,27 +572,28 @@ export default function DocumentHeader({
</div>
))}
- {primaryVersion.type !== "notion" && (
- <AddDocumentModal
- newVersion
- openModal={openAddDocModal}
- setAddDocumentModalOpen={setOpenAddDocModal}
- >
- <ButtonTooltip content="Upload new version">
- <Button
- variant="outline"
- size="icon"
- onClick={(e) => {
- e.stopPropagation();
- setOpenAddDocModal(true);
- }}
- className="hidden size-8 md:flex lg:size-9"
- >
- <FileUp className="h-6 w-6" />
- </Button>
- </ButtonTooltip>
- </AddDocumentModal>
- )}
+ {primaryVersion.type !== "notion" &&
+ primaryVersion.type !== "link" && (
+ <AddDocumentModal
+ newVersion
+ openModal={openAddDocModal}
+ setAddDocumentModalOpen={setOpenAddDocModal}
+ >
+ <ButtonTooltip content="Upload new version">
+ <Button
+ variant="outline"
+ size="icon"
+ onClick={(e) => {
+ e.stopPropagation();
+ setOpenAddDocModal(true);
+ }}
+ className="hidden size-8 md:flex lg:size-9"
+ >
+ <FileUp className="h-6 w-6" />
+ </Button>
+ </ButtonTooltip>
+ </AddDocumentModal>
+ )}
{/* TODO: Assistant feature temporarily disabled. Will be re-enabled in a future update */}
{/* {prismaDocument.type !== "notion" &&
@@ -743,6 +745,7 @@ export default function DocumentHeader({
{/* AI Agents - only show when team has AI enabled */}
{isAIEnabled &&
prismaDocument.type !== "notion" &&
+ primaryVersion.type !== "link" &&
prismaDocument.type !== "sheet" &&
prismaDocument.type !== "zip" &&
primaryVersion.type !== "video" && (
@@ -760,6 +763,7 @@ export default function DocumentHeader({
)}
{primaryVersion.type !== "notion" &&
+ primaryVersion.type !== "link" &&
primaryVersion.type !== "zip" &&
primaryVersion.type !== "map" &&
primaryVersion.type !== "email" && (
@@ -825,6 +829,7 @@ export default function DocumentHeader({
{/* Download latest version */}
{primaryVersion.type !== "notion" &&
+ primaryVersion.type !== "link" &&
primaryVersion.type !== "video" && (
<DropdownMenuItem
onClick={() => downloadDocument(primaryVersion)}
diff --git a/components/documents/link-document-indicator.tsx b/components/documents/link-document-indicator.tsx
index 51e9de7f..e033021d 100644
--- a/components/documents/link-document-indicator.tsx
+++ b/components/documents/link-document-indicator.tsx
@@ -1,10 +1,12 @@
-import { useState } from "react";
+import { useEffect, useState } from "react";
import { useTeam } from "@/context/team-context";
import { DocumentVersion } from "@prisma/client";
import { Edit, ExternalLink, LinkIcon } from "lucide-react";
import { toast } from "sonner";
+import { useAnalytics } from "@/lib/analytics";
+
import { Button } from "@/components/ui/button";
import {
Dialog,
@@ -32,12 +34,19 @@ export default function LinkDocumentIndicator({
onUrlUpdate,
}: LinkDocumentIndicatorProps) {
const teamInfo = useTeam();
+ const analytics = useAnalytics();
const [isMainDialogOpen, setIsMainDialogOpen] = useState(false);
const [isUrlDialogOpen, setIsUrlDialogOpen] = useState(false);
const [newUrl, setNewUrl] = useState("");
const [isUpdating, setIsUpdating] = useState(false);
- const currentUrl = primaryVersion.file;
+ // Local state for immediate UI updates
+ const [currentUrl, setCurrentUrl] = useState(primaryVersion.file);
+
+ // Sync with prop changes (e.g., when SWR revalidates)
+ useEffect(() => {
+ setCurrentUrl(primaryVersion.file);
+ }, [primaryVersion.file]);
const updateLinkUrl = async () => {
if (!teamInfo?.currentTeam?.id || !newUrl.trim()) return;
@@ -58,9 +67,23 @@ export default function LinkDocumentIndicator({
const data = await response.json();
if (response.ok) {
+ // Immediately update local state for instant UI feedback
+ setCurrentUrl(newUrl.trim());
toast.success("Link URL updated successfully");
setIsUrlDialogOpen(false);
setNewUrl("");
+
+ // Track analytics event
+ analytics.capture("Document Updated", {
+ documentId: documentId,
+ url: newUrl.trim(),
+ type: "link",
+ teamId: teamInfo.currentTeam.id,
+ $set: {
+ teamId: teamInfo.currentTeam.id,
+ },
+ });
+
// Trigger parent component update if provided
if (onUrlUpdate) {
onUrlUpdate();
@@ -82,15 +105,6 @@ export default function LinkDocumentIndicator({
}
};
- const getDisplayUrl = () => {
- try {
- const urlObj = new URL(currentUrl);
- return urlObj.hostname + (urlObj.pathname !== "/" ? urlObj.pathname : "");
- } catch {
- return currentUrl;
- }
- };
-
// Only render for link documents
if (primaryVersion.type !== "link") {
return null;
@@ -210,4 +224,3 @@ export default function LinkDocumentIndicator({
</>
);
}
-