Posthog behoben

This commit is contained in:
Timo Knuth
2025-12-11 11:40:38 +01:00
parent 8c5e2fa58e
commit 18f92c4285
8 changed files with 141 additions and 34 deletions

View File

@@ -132,6 +132,48 @@ export default function DashboardPage() {
},
];
// Track Google OAuth login/signup
useEffect(() => {
const authMethod = searchParams.get('authMethod');
const isNewUser = searchParams.get('isNewUser') === 'true';
if (authMethod === 'google') {
const trackGoogleAuth = async () => {
try {
// Fetch user data from API (cookie-based auth)
const response = await fetch('/api/user');
if (!response.ok) return;
const user = await response.json();
// Store in localStorage for consistency
localStorage.setItem('user', JSON.stringify(user));
const { identifyUser, trackEvent } = await import('@/components/PostHogProvider');
identifyUser(user.id, {
email: user.email,
name: user.name,
plan: user.plan || 'FREE',
provider: 'google',
});
trackEvent(isNewUser ? 'user_signup' : 'user_login', {
method: 'google',
email: user.email,
isNewUser,
});
// Clean up URL params
router.replace('/dashboard');
} catch (error) {
console.error('PostHog tracking error:', error);
}
};
trackGoogleAuth();
}
}, [searchParams, router]);
// Check for successful payment and verify session
useEffect(() => {
const success = searchParams.get('success');