From d69b84b2904a75251d401c8f134d9912fe634ee8 Mon Sep 17 00:00:00 2001 From: Sahaj Jain Date: Mon, 28 Apr 2025 23:08:29 +0530 Subject: [PATCH] feat(auth): integrate PostHog for user identification and tracking --- components/auth-dialog-wrapper.tsx | 19 ++++++++++++++++++- components/user-profile-dropdown.tsx | 3 +++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/components/auth-dialog-wrapper.tsx b/components/auth-dialog-wrapper.tsx index dd14778e..a3489d18 100644 --- a/components/auth-dialog-wrapper.tsx +++ b/components/auth-dialog-wrapper.tsx @@ -5,6 +5,7 @@ import { useAuthStore } from "@/store/auth-store"; import { useEffect } from "react"; import { authClient } from "@/lib/auth-client"; import { executePostLoginAction } from "@/hooks/use-post-login-action"; +import { usePostHog } from "posthog-js/react"; export function AuthDialogWrapper() { const { @@ -15,17 +16,33 @@ export function AuthDialogWrapper() { clearPostLoginAction, } = useAuthStore(); const { data: session } = authClient.useSession(); + const posthog = usePostHog(); useEffect(() => { if (isOpen && session) { closeAuthDialog(); } + if (session && session.user && session.user.email) { + // Identify user with PostHog + posthog.identify(session.user.email, { + name: session.user.name, + email: session.user.email, + }); + } + if (session && postLoginAction) { executePostLoginAction(postLoginAction); clearPostLoginAction(); } - }, [session, isOpen, closeAuthDialog, postLoginAction, clearPostLoginAction]); + }, [ + session, + isOpen, + closeAuthDialog, + postLoginAction, + clearPostLoginAction, + posthog, + ]); return ( @@ -91,6 +93,7 @@ export function UserProfileDropdown() { { + posthog.reset(); await authClient.signOut(); }} >