Skip to content

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

feat: don't send event if already sent

Marc Seitz22cdd10e50c9
diff --git a/pages/welcome.tsx b/pages/welcome.tsx
index d3d2e784..dcba7bf6 100644
--- a/pages/welcome.tsx
+++ b/pages/welcome.tsx
@@ -1,6 +1,6 @@
import { useRouter } from "next/router";
-import { useEffect } from "react";
+import { useEffect, useRef } from "react";
import { useState } from "react";
import { sendGTMEvent } from "@next/third-parties/google";
@@ -26,6 +26,7 @@ export default function Welcome() {
const router = useRouter();
const [showSkipButtons, setShowSkipButtons] = useState(false);
const { data: session } = useSession();
+ const signupEventSent = useRef(false);
useEffect(() => {
const timer = setTimeout(() => {
@@ -35,15 +36,17 @@ export default function Welcome() {
return () => clearTimeout(timer);
}, []);
- // Track signup for new users when welcome page loads
+ // Track signup for new users when welcome page loads (with deduplication)
useEffect(() => {
const user = session?.user as CustomUser;
- if (user?.createdAt) {
- // Check if user was created within the last 30 seconds (indicating new signup)
- const isNewUser = new Date(user.createdAt).getTime() > Date.now() - 30000;
+
+ if (user?.createdAt && !signupEventSent.current) {
+ // Check if user was created within the last 10 seconds (indicating new signup)
+ const isNewUser = new Date(user.createdAt).getTime() > Date.now() - 10000;
if (isNewUser) {
sendGTMEvent({ event: "signup" });
+ signupEventSent.current = true;
}
}
}, [session]);