Hey is a decentralized and permissionless social media app built with Lens Protocol 🌿

feat: log pageview events in Layout component

yoginth.com 52b0069b 1aac7755

verified
+22 -1
+1 -1
apps/api/src/routes/events.ts
··· 7 7 try { 8 8 const body = await ctx.req.json(); 9 9 const event = body.event?.trim(); 10 - const address = body.address?.trim() || zeroAddress; 10 + const address = ctx.get("account") ?? zeroAddress; 11 11 12 12 if (!event) { 13 13 ctx.status(400);
+5
apps/web/src/components/Common/Layout.tsx
··· 12 12 import Navbar from "@/components/Shared/Navbar"; 13 13 import BottomNavigation from "@/components/Shared/Navbar/BottomNavigation"; 14 14 import { Spinner } from "@/components/Shared/UI"; 15 + import logEvent from "@/helpers/logEvent"; 15 16 import reloadAllTabs from "@/helpers/reloadAllTabs"; 16 17 import { useTheme } from "@/hooks/useTheme"; 17 18 import { useAccountStore } from "@/store/persisted/useAccountStore"; ··· 30 31 // Disable scroll restoration on route change 31 32 useEffect(() => { 32 33 window.scrollTo(0, 0); 34 + }, [pathname]); 35 + 36 + useEffect(() => { 37 + void logEvent(`Pageview: ${pathname}`); 33 38 }, [pathname]); 34 39 35 40 const onError = useCallback(() => {
+7
apps/web/src/helpers/fetcher.ts
··· 69 69 method: "POST" 70 70 }) 71 71 }, 72 + events: { 73 + create: async (payload: { event: string }) => 74 + fetchApi<{ ok: boolean; skipped?: boolean }>("/events", { 75 + body: JSON.stringify(payload), 76 + method: "POST" 77 + }) 78 + }, 72 79 likes: { 73 80 create: async (payload: { slug: string }) => 74 81 fetchApi<{ ok: boolean; skipped?: boolean }>("/likes", {
+9
apps/web/src/helpers/logEvent.ts
··· 1 + import { hono } from "@/helpers/fetcher"; 2 + 3 + const logEvent = async (eventName: string) => { 4 + try { 5 + await hono.events.create({ event: eventName }); 6 + } catch {} 7 + }; 8 + 9 + export default logEvent;