Papermark is the open-source DocSend alternative and secure data rooms with built-in analytics and custom domains.
chore: add error logging to server client
Marc Seitz6af6284f088c
diff --git a/lib/analytics/index.ts b/lib/analytics/index.tsindex 17a51262..b59eaad3 100644--- a/lib/analytics/index.ts+++ b/lib/analytics/index.ts@@ -3,6 +3,7 @@ import { AnalyticsEvents } from "@/lib/types";import prisma from "@/lib/prisma";import { getPostHogConfig, getPostHogServerClient } from "@/lib/posthog";import { posthog } from "posthog-js";+import { log } from "../utils";export function useAnalytics() {const isPostHogEnabled = getPostHogConfig();@@ -47,26 +48,25 @@ export function getAnalyticsServer() {properties?: Record<string, unknown>,) => {if (!postHogClient) {+ log({+ message: `Posthog client not enabled for server event: *${event}*`,+ type: "error",+ });return;}- postHogClient.capture({ distinctId, event, properties });- };-- const identify = (- distinctId: string, // email or user id- properties?: Record<string, unknown>,- ) => {- if (!postHogClient) {- return;+ try {+ postHogClient.capture({ distinctId, event, properties });+ } catch (e) {+ log({+ message: `Failed to record posthog for event: *${event}*`,+ type: "error",+ });}-- postHogClient.identify({ distinctId, properties });};return {capture,- identify,};}diff --git a/pages/api/auth/[...nextauth].ts b/pages/api/auth/[...nextauth].tsindex 27f61943..40663591 100644--- a/pages/api/auth/[...nextauth].ts+++ b/pages/api/auth/[...nextauth].ts@@ -18,8 +18,6 @@ export const config = {maxDuration: 180,};-const analytics = getAnalyticsServer();-export const authOptions: NextAuthOptions = {pages: {error: "/login",@@ -115,6 +113,7 @@ export const authOptions: NextAuthOptions = {},};+ const analytics = getAnalyticsServer();analytics.capture(message.user.email ?? message.user.id,"User Signed Up",@@ -123,6 +122,7 @@ export const authOptions: NextAuthOptions = {await sendWelcomeEmail(params);},async signIn(message) {+ const analytics = getAnalyticsServer();analytics.capture(message.user.email ?? message.user.id,"User Signed In",