From d7fff9f70cce94ac7060525b15626e4a13211537 Mon Sep 17 00:00:00 2001 From: Theodore Li Date: Mon, 6 Apr 2026 14:06:55 -0700 Subject: [PATCH 1/3] feat(posthog): Add posthog log for signup failed --- apps/sim/app/(auth)/signup/signup-form.tsx | 20 ++++++++++++++++++++ apps/sim/lib/posthog/events.ts | 5 +++++ 2 files changed, 25 insertions(+) diff --git a/apps/sim/app/(auth)/signup/signup-form.tsx b/apps/sim/app/(auth)/signup/signup-form.tsx index 1b0bd50c05b..25580c47d88 100644 --- a/apps/sim/app/(auth)/signup/signup-form.tsx +++ b/apps/sim/app/(auth)/signup/signup-form.tsx @@ -261,6 +261,9 @@ function SignupFormContent({ widget.execute() token = await widget.getResponsePromise() } catch { + captureEvent(posthog, 'signup_failed', { + reason: 'captcha_client_failure', + }) setFormError('Captcha verification failed. Please try again.') setIsLoading(false) return @@ -284,7 +287,9 @@ function SignupFormContent({ logger.error('Signup error:', ctx.error) const errorMessage: string[] = ['Failed to create account'] + let reason = 'unknown' if (ctx.error.code?.includes('USER_ALREADY_EXISTS')) { + reason = 'user_already_exists' errorMessage.push( 'An account with this email already exists. Please sign in instead.' ) @@ -293,24 +298,30 @@ function SignupFormContent({ ctx.error.code?.includes('BAD_REQUEST') || ctx.error.message?.includes('Email and password sign up is not enabled') ) { + reason = 'signup_disabled' errorMessage.push('Email signup is currently disabled.') setEmailError(errorMessage[0]) } else if (ctx.error.code?.includes('INVALID_EMAIL')) { + reason = 'invalid_email' errorMessage.push('Please enter a valid email address.') setEmailError(errorMessage[0]) } else if (ctx.error.code?.includes('PASSWORD_TOO_SHORT')) { + reason = 'password_too_short' errorMessage.push('Password must be at least 8 characters long.') setPasswordErrors(errorMessage) setShowValidationError(true) } else if (ctx.error.code?.includes('PASSWORD_TOO_LONG')) { + reason = 'password_too_long' errorMessage.push('Password must be less than 128 characters long.') setPasswordErrors(errorMessage) setShowValidationError(true) } else if (ctx.error.code?.includes('network')) { + reason = 'network_error' errorMessage.push('Network error. Please check your connection and try again.') setPasswordErrors(errorMessage) setShowValidationError(true) } else if (ctx.error.code?.includes('rate limit')) { + reason = 'rate_limited' errorMessage.push('Too many requests. Please wait a moment before trying again.') setPasswordErrors(errorMessage) setShowValidationError(true) @@ -318,6 +329,11 @@ function SignupFormContent({ setPasswordErrors(errorMessage) setShowValidationError(true) } + + captureEvent(posthog, 'signup_failed', { + reason, + error_code: ctx.error.code, + }) }, } ) @@ -345,6 +361,10 @@ function SignupFormContent({ router.push('/verify?fromSignup=true') } catch (error) { logger.error('Signup error:', error) + captureEvent(posthog, 'signup_failed', { + reason: 'unexpected_error', + error_code: error instanceof Error ? error.message : undefined, + }) setIsLoading(false) } } diff --git a/apps/sim/lib/posthog/events.ts b/apps/sim/lib/posthog/events.ts index c186d82cd47..75420b81fae 100644 --- a/apps/sim/lib/posthog/events.ts +++ b/apps/sim/lib/posthog/events.ts @@ -16,6 +16,11 @@ export interface PostHogEventMap { signup_page_viewed: Record + signup_failed: { + reason: string + error_code?: string + } + subscription_created: { plan: string status: string From 0ee66f523730b5c410bb809bc3bec3266e33c3d1 Mon Sep 17 00:00:00 2001 From: Theodore Li Date: Mon, 6 Apr 2026 16:57:48 -0700 Subject: [PATCH 2/3] Adjust event shape --- apps/sim/app/(auth)/signup/signup-form.tsx | 26 +++++++++------------- apps/sim/lib/posthog/events.ts | 3 +-- 2 files changed, 12 insertions(+), 17 deletions(-) diff --git a/apps/sim/app/(auth)/signup/signup-form.tsx b/apps/sim/app/(auth)/signup/signup-form.tsx index 25580c47d88..2830d7b1429 100644 --- a/apps/sim/app/(auth)/signup/signup-form.tsx +++ b/apps/sim/app/(auth)/signup/signup-form.tsx @@ -262,7 +262,7 @@ function SignupFormContent({ token = await widget.getResponsePromise() } catch { captureEvent(posthog, 'signup_failed', { - reason: 'captcha_client_failure', + error_code: 'captcha_client_failure', }) setFormError('Captcha verification failed. Please try again.') setIsLoading(false) @@ -287,9 +287,9 @@ function SignupFormContent({ logger.error('Signup error:', ctx.error) const errorMessage: string[] = ['Failed to create account'] - let reason = 'unknown' + let errorCode = 'unknown' if (ctx.error.code?.includes('USER_ALREADY_EXISTS')) { - reason = 'user_already_exists' + errorCode = 'user_already_exists' errorMessage.push( 'An account with this email already exists. Please sign in instead.' ) @@ -298,30 +298,30 @@ function SignupFormContent({ ctx.error.code?.includes('BAD_REQUEST') || ctx.error.message?.includes('Email and password sign up is not enabled') ) { - reason = 'signup_disabled' + errorCode = 'signup_disabled' errorMessage.push('Email signup is currently disabled.') setEmailError(errorMessage[0]) } else if (ctx.error.code?.includes('INVALID_EMAIL')) { - reason = 'invalid_email' + errorCode = 'invalid_email' errorMessage.push('Please enter a valid email address.') setEmailError(errorMessage[0]) } else if (ctx.error.code?.includes('PASSWORD_TOO_SHORT')) { - reason = 'password_too_short' + errorCode = 'password_too_short' errorMessage.push('Password must be at least 8 characters long.') setPasswordErrors(errorMessage) setShowValidationError(true) } else if (ctx.error.code?.includes('PASSWORD_TOO_LONG')) { - reason = 'password_too_long' + errorCode = 'password_too_long' errorMessage.push('Password must be less than 128 characters long.') setPasswordErrors(errorMessage) setShowValidationError(true) } else if (ctx.error.code?.includes('network')) { - reason = 'network_error' + errorCode = 'network_error' errorMessage.push('Network error. Please check your connection and try again.') setPasswordErrors(errorMessage) setShowValidationError(true) } else if (ctx.error.code?.includes('rate limit')) { - reason = 'rate_limited' + errorCode = 'rate_limited' errorMessage.push('Too many requests. Please wait a moment before trying again.') setPasswordErrors(errorMessage) setShowValidationError(true) @@ -330,10 +330,7 @@ function SignupFormContent({ setShowValidationError(true) } - captureEvent(posthog, 'signup_failed', { - reason, - error_code: ctx.error.code, - }) + captureEvent(posthog, 'signup_failed', { error_code: errorCode }) }, } ) @@ -362,8 +359,7 @@ function SignupFormContent({ } catch (error) { logger.error('Signup error:', error) captureEvent(posthog, 'signup_failed', { - reason: 'unexpected_error', - error_code: error instanceof Error ? error.message : undefined, + error_code: 'unexpected_error', }) setIsLoading(false) } diff --git a/apps/sim/lib/posthog/events.ts b/apps/sim/lib/posthog/events.ts index 75420b81fae..e11d1bdfdd0 100644 --- a/apps/sim/lib/posthog/events.ts +++ b/apps/sim/lib/posthog/events.ts @@ -17,8 +17,7 @@ export interface PostHogEventMap { signup_page_viewed: Record signup_failed: { - reason: string - error_code?: string + error_code: string } subscription_created: { From 73f57d1223cae9e0ccaab4259e1107edafbc6756 Mon Sep 17 00:00:00 2001 From: Theodore Li Date: Mon, 6 Apr 2026 17:28:35 -0700 Subject: [PATCH 3/3] Remove false signup failed events --- apps/sim/app/(auth)/signup/signup-form.tsx | 3 --- 1 file changed, 3 deletions(-) diff --git a/apps/sim/app/(auth)/signup/signup-form.tsx b/apps/sim/app/(auth)/signup/signup-form.tsx index 2830d7b1429..56dc1631106 100644 --- a/apps/sim/app/(auth)/signup/signup-form.tsx +++ b/apps/sim/app/(auth)/signup/signup-form.tsx @@ -358,9 +358,6 @@ function SignupFormContent({ router.push('/verify?fromSignup=true') } catch (error) { logger.error('Signup error:', error) - captureEvent(posthog, 'signup_failed', { - error_code: 'unexpected_error', - }) setIsLoading(false) } }