Skip to content

Commit 3e8313e

Browse files
committed
Merge branch 'ahmd'
:wq# the commit.
2 parents d6ce76d + ff614cd commit 3e8313e

22 files changed

Lines changed: 18493 additions & 11 deletions

File tree

frontend/app/home/page.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { toast } from 'sonner';
88
import { useRouter } from 'next/navigation';
99
import Loading from '@/components/CenterLoader';
1010
import ProfileHover from '@/components/ProfileIcon';
11+
import { posthog } from '@/lib/posthog';
1112

1213
export default function FindMatchPage() {
1314
const [isSearching, setIsSearching] = useState(false);
@@ -165,6 +166,7 @@ export default function FindMatchPage() {
165166
setPeerProfile(null);
166167
setCurrentQuote(0);
167168
socket.emit('match:start', { skills });
169+
posthog.capture('match_search_started', { skill_count: skills.length });
168170
} catch {
169171
toast.error('Unable to start matching');
170172
}
@@ -201,6 +203,7 @@ export default function FindMatchPage() {
201203
setPeerId(peerId);
202204
setIsSearching(false);
203205
setMatchFound(true);
206+
posthog.capture('match_found', { session_id: sessionId });
204207
};
205208

206209
socket.on('match:found', onMatchFound);
@@ -229,6 +232,7 @@ export default function FindMatchPage() {
229232
clearInterval(autoJoinRef.current);
230233
autoJoinRef.current = null;
231234
}
235+
posthog.capture('match_accepted');
232236
router.push(`/session?callId=${sessionId}&peerId=${peerId}`);
233237
};
234238

@@ -238,6 +242,7 @@ export default function FindMatchPage() {
238242
autoJoinRef.current = null;
239243
}
240244
socket.emit('match:decline', { sessionId, peerId });
245+
posthog.capture('match_declined');
241246
setMatchFound(false);
242247
setSessionId(null);
243248
setPeerId(null);

frontend/app/session/page.tsx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import {
2222
Clock,
2323
} from 'lucide-react';
2424
import Link from 'next/link';
25+
import { posthog } from '@/lib/posthog';
2526

2627
type PermissionState = 'idle' | 'requesting' | 'granted' | 'denied';
2728
type CallEndReason =
@@ -290,6 +291,7 @@ function VideoCallInner() {
290291
peerUserIdRef.current = peer;
291292
iceServersRef.current = iceServers;
292293
setStatus('Partner ready — connecting...');
294+
posthog.capture('call_started', { session_id: cId });
293295

294296
try {
295297
const pc = getOrCreatePC(iceServers);
@@ -377,6 +379,10 @@ function VideoCallInner() {
377379
localStreamRef.current = null;
378380
cleanup();
379381
setCallEndReason(reason ?? 'USER_ENDED');
382+
posthog.capture('call_ended', {
383+
reason: reason ?? 'USER_ENDED',
384+
duration_seconds: callDurationRef.current,
385+
});
380386
setCallEnded(true);
381387
};
382388

@@ -426,6 +432,10 @@ function VideoCallInner() {
426432
callId: callIdRef.current,
427433
reason: 'USER_ENDED',
428434
});
435+
posthog.capture('call_ended', {
436+
reason: 'USER_ENDED',
437+
duration_seconds: callDurationRef.current,
438+
});
429439
cleanup();
430440
setSelfLeft(true);
431441
};

frontend/app/verifyotp/verifyOtp.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ export default function VerifyOtpPage() {
6969
setLoading(true);
7070

7171
await axiosInstance.post(
72-
'/auth/verifyOtp',
72+
'/auth/verifyotp',
7373
{ otp },
7474
{
7575
headers: {
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
'use client';
2+
3+
import { usePathname, useSearchParams } from 'next/navigation';
4+
import { useEffect } from 'react';
5+
import { posthog } from '@/lib/posthog';
6+
7+
export function PostHogPageView() {
8+
const pathname = usePathname();
9+
const searchParams = useSearchParams();
10+
11+
useEffect(() => {
12+
if (!pathname) return;
13+
14+
let url = window.origin + pathname;
15+
if (searchParams.toString()) {
16+
url += `?${searchParams.toString()}`;
17+
}
18+
19+
posthog.capture('$pageview', { $current_url: url });
20+
}, [pathname, searchParams]);
21+
22+
return null;
23+
}

frontend/components/auth/GoogleButton.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { GoogleLogin } from '@react-oauth/google';
55
import axios from 'axios';
66
import { ArrowRight, MonitorX } from 'lucide-react';
77
import { useRouter } from 'next/navigation';
8+
import { posthog } from '@/lib/posthog';
89
import { useState } from 'react';
910
import { toast } from 'sonner';
1011

@@ -63,6 +64,10 @@ export default function GoogleButton() {
6364
const role = res.data.role;
6465
console.log(role);
6566
const target = role === 'admin' ? '/admin' : '/home';
67+
posthog.identify(res.data.userId, {
68+
role,
69+
});
70+
posthog.capture('login_completed', { method: 'google' });
6671
console.log('navigating navigating');
6772
router.replace(target);
6873
router.refresh();

frontend/components/auth/LoginForm.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { axiosInstance } from '@/lib/axiosInstance';
1414
import { useRouter } from 'next/navigation';
1515
import axios from 'axios';
1616
import { toast } from 'sonner';
17+
import { posthog } from '@/lib/posthog';
1718

1819
export function LoginRight() {
1920
const [email, setEmail] = useState('');
@@ -50,6 +51,11 @@ export function LoginRight() {
5051

5152
const role = res.data.role;
5253
const target = role === 'admin' ? '/admin' : '/home';
54+
posthog.identify(res.data.userId, {
55+
email,
56+
role,
57+
});
58+
posthog.capture('login_completed', { method: 'email' });
5359
router.replace(target);
5460
router.refresh();
5561

frontend/components/auth/LogoutButton.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { axiosInstance } from '@/lib/axiosInstance';
33
import { useRouter } from 'next/navigation';
44
import { toast } from 'sonner';
55
import { socket } from '@/lib/socket';
6+
import { posthog } from '@/lib/posthog';
67

78
export default function LogoutButton() {
89
const router = useRouter();
@@ -17,6 +18,7 @@ export default function LogoutButton() {
1718
}
1819

1920
setTimeout(() => {
21+
posthog.reset();
2022
router.push('/login');
2123
}, 1200);
2224
};

frontend/components/auth/SignUpForm.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { Button } from '../ui/button';
1010
import { axiosInstance } from '@/lib/axiosInstance';
1111
import Link from 'next/link';
1212
import axios from 'axios';
13+
import { posthog } from '@/lib/posthog';
1314

1415
export function SignUpForm() {
1516
const router = useRouter();
@@ -51,6 +52,7 @@ export function SignUpForm() {
5152
const temp_token = res.data.verificationToken;
5253

5354
localStorage.setItem('temp_token', temp_token);
55+
posthog.capture('signup_completed');
5456
router.push('/verifyotp');
5557
} catch (error: unknown) {
5658
if (axios.isAxiosError(error)) {

frontend/lib/posthog.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import posthog from 'posthog-js';
2+
3+
export const initPostHog = () => {
4+
if (typeof window === 'undefined') return;
5+
6+
posthog.init(process.env.NEXT_PUBLIC_POSTHOG_KEY!, {
7+
api_host:
8+
process.env.NEXT_PUBLIC_POSTHOG_HOST ?? 'https://us.i.posthog.com',
9+
capture_pageview: false,
10+
capture_pageleave: true,
11+
session_recording: {
12+
maskAllInputs: true,
13+
},
14+
});
15+
};
16+
17+
export { posthog };

frontend/lib/providers.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,22 @@
11
'use client';
22

3+
import { useEffect, Suspense } from 'react';
34
import { GoogleOAuthProvider } from '@react-oauth/google';
5+
import { Toaster } from '@/components/ui/sonner';
6+
import { initPostHog } from '@/lib/posthog';
7+
import { PostHogPageView } from '@/components/PostHogPageView';
48

59
export default function Providers({ children }: { children: React.ReactNode }) {
10+
useEffect(() => {
11+
initPostHog();
12+
}, []);
13+
614
return (
715
<GoogleOAuthProvider clientId={process.env.NEXT_PUBLIC_GOOGLE_CLIENT_ID!}>
16+
<Suspense fallback={null}>
17+
<PostHogPageView />
18+
</Suspense>
19+
<Toaster richColors position="top-right" />
820
{children}
921
</GoogleOAuthProvider>
1022
);

0 commit comments

Comments
 (0)