tangled
alpha
login
or
join now
yoginth.com
/
hey
1
fork
atom
Hey is a decentralized and permissionless social media app built with Lens Protocol 🌿
1
fork
atom
overview
issues
pulls
pipelines
feat: log pageview events in Layout component
yoginth.com
5 months ago
52b0069b
1aac7755
verified
This commit was signed with the committer's
known signature
.
yoginth.com
SSH Key Fingerprint:
SHA256:SLCGp+xtY+FtXnVKtpl4bpmTttAxnxJ3DBCeikAHlG4=
+22
-1
4 changed files
expand all
collapse all
unified
split
apps
api
src
routes
events.ts
web
src
components
Common
Layout.tsx
helpers
fetcher.ts
logEvent.ts
+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
10
-
const address = body.address?.trim() || zeroAddress;
10
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
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
34
+
}, [pathname]);
35
35
+
36
36
+
useEffect(() => {
37
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
72
+
events: {
73
73
+
create: async (payload: { event: string }) =>
74
74
+
fetchApi<{ ok: boolean; skipped?: boolean }>("/events", {
75
75
+
body: JSON.stringify(payload),
76
76
+
method: "POST"
77
77
+
})
78
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
1
+
import { hono } from "@/helpers/fetcher";
2
2
+
3
3
+
const logEvent = async (eventName: string) => {
4
4
+
try {
5
5
+
await hono.events.create({ event: eventName });
6
6
+
} catch {}
7
7
+
};
8
8
+
9
9
+
export default logEvent;