Compare commits

...

2 Commits

Author SHA1 Message Date
Akshay Kolli
b0ad1287fb oMerge branch 'master' of http://pluto:3000/lepton/Webserver
All checks were successful
Deploy Website / build-and-deploy (push) Successful in 25s
I made some changes that i forgot to pull
2026-02-08 03:02:32 -05:00
Akshay Kolli
35f7254734 Added visitor analytics 2026-02-08 03:01:52 -05:00
2 changed files with 37 additions and 0 deletions

View File

@@ -15,6 +15,8 @@ export const metadata: Metadata = {
description: "My personal website", description: "My personal website",
}; };
import { Analytics } from "../components/Analytics";
export default function RootLayout({ export default function RootLayout({
children, children,
}: Readonly<{ }: Readonly<{
@@ -30,6 +32,7 @@ export default function RootLayout({
{children} {children}
</main> </main>
<Footer /> <Footer />
<Analytics />
</body> </body>
</html> </html>
); );

34
components/Analytics.tsx Normal file
View File

@@ -0,0 +1,34 @@
'use client';
import { useEffect } from 'react';
import { usePathname } from 'next/navigation';
export function Analytics() {
const pathname = usePathname();
useEffect(() => {
// Send beacon on mount and path change
const sendBeacon = async () => {
try {
// Point to the Admin Dashboard API
// In prod, this URL needs to be the absolute URL of admin_dash
// For local docker, standard localhost access might work if CORS allows,
// or we route through a proxy.
// For this personal setup, let's assume they are on same domain or localhost.
await fetch('http://localhost:3000/api/track', { // TODO: Make this configurable
method: 'POST',
body: JSON.stringify({ path: pathname, timestamp: Date.now() }),
headers: { 'Content-Type': 'application/json' },
keepalive: true,
});
} catch (e) {
// Fail silently
console.error('Analytics fail', e);
}
};
sendBeacon();
}, [pathname]);
return null;
}