add login posthog events

This commit is contained in:
msukkari 2025-02-25 10:30:52 -08:00
parent 07863b2753
commit f853335ef1
4 changed files with 16 additions and 0 deletions

View file

@ -10,12 +10,14 @@ import { signIn } from "next-auth/react";
import { verifyCredentialsRequestSchema } from "@/lib/schemas";
import { useState } from "react";
import { Loader2 } from "lucide-react";
import useCaptureEvent from "@/hooks/useCaptureEvent";
interface CredentialsFormProps {
callbackUrl?: string;
}
export const CredentialsForm = ({ callbackUrl }: CredentialsFormProps) => {
const captureEvent = useCaptureEvent();
const [isLoading, setIsLoading] = useState(false);
const form = useForm<z.infer<typeof verifyCredentialsRequestSchema>>({
resolver: zodResolver(verifyCredentialsRequestSchema),
@ -27,6 +29,7 @@ export const CredentialsForm = ({ callbackUrl }: CredentialsFormProps) => {
const onSubmit = (values: z.infer<typeof verifyCredentialsRequestSchema>) => {
setIsLoading(true);
captureEvent("wa_login_with_credentials", {});
signIn("credentials", {
email: values.email,
password: values.password,

View file

@ -11,6 +11,7 @@ import { MagicLinkForm } from "./magicLinkForm";
import { CredentialsForm } from "./credentialsForm";
import { SourcebotLogo } from "@/app/components/sourcebotLogo";
import { TextSeparator } from "@/app/components/textSeparator";
import useCaptureEvent from "@/hooks/useCaptureEvent";
interface LoginFormProps {
callbackUrl?: string;
@ -24,6 +25,7 @@ interface LoginFormProps {
}
export const LoginForm = ({ callbackUrl, error, enabledMethods }: LoginFormProps) => {
const captureEvent = useCaptureEvent();
const onSignInWithOauth = useCallback((provider: string) => {
signIn(provider, { redirectTo: callbackUrl ?? "/" });
}, [callbackUrl]);
@ -66,6 +68,7 @@ export const LoginForm = ({ callbackUrl, error, enabledMethods }: LoginFormProps
name="GitHub"
logo={getCodeHostIcon("github")!}
onClick={() => {
captureEvent("wa_login_with_github", {});
onSignInWithOauth("github")
}}
/>
@ -76,6 +79,7 @@ export const LoginForm = ({ callbackUrl, error, enabledMethods }: LoginFormProps
name="Google"
logo={{ src: googleLogo }}
onClick={() => {
captureEvent("wa_login_with_google", {});
onSignInWithOauth("google")
}}
/>

View file

@ -9,6 +9,8 @@ import { z } from "zod";
import { signIn } from "next-auth/react";
import { useState } from "react";
import { Loader2 } from "lucide-react";
import useCaptureEvent from "@/hooks/useCaptureEvent";
const magicLinkSchema = z.object({
email: z.string().email(),
});
@ -18,6 +20,7 @@ interface MagicLinkFormProps {
}
export const MagicLinkForm = ({ callbackUrl }: MagicLinkFormProps) => {
const captureEvent = useCaptureEvent();
const [isLoading, setIsLoading] = useState(false);
const magicLinkForm = useForm<z.infer<typeof magicLinkSchema>>({
resolver: zodResolver(magicLinkSchema),
@ -28,6 +31,7 @@ export const MagicLinkForm = ({ callbackUrl }: MagicLinkFormProps) => {
const onSignIn = (values: z.infer<typeof magicLinkSchema>) => {
setIsLoading(true);
captureEvent("wa_login_with_magic_link", {});
signIn("nodemailer", { email: values.email, redirectTo: callbackUrl ?? "/" })
.finally(() => {
setIsLoading(false);

View file

@ -219,6 +219,11 @@ export type PosthogEventMap = {
error: string,
},
//////////////////////////////////////////////////////////////////
wa_login_with_github: {},
wa_login_with_google: {},
wa_login_with_magic_link: {},
wa_login_with_credentials: {},
//////////////////////////////////////////////////////////////////
}
export type PosthogEvent = keyof PosthogEventMap;