Skip to content

Commit 9def9f0

Browse files
authored
add posthog + layout rework (#2926)
* add posthog + layout rework * remove posthog node * nit
1 parent 5e01d6b commit 9def9f0

File tree

6 files changed

+218
-122
lines changed

6 files changed

+218
-122
lines changed

web/Dockerfile

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ ENV NEXT_PUBLIC_DISABLE_LOGOUT=${NEXT_PUBLIC_DISABLE_LOGOUT}
6161
ARG NEXT_PUBLIC_CUSTOM_REFRESH_URL
6262
ENV NEXT_PUBLIC_CUSTOM_REFRESH_URL=${NEXT_PUBLIC_CUSTOM_REFRESH_URL}
6363

64+
ARG NEXT_PUBLIC_POSTHOG_KEY
65+
ARG NEXT_PUBLIC_POSTHOG_HOST
66+
ENV NEXT_PUBLIC_POSTHOG_KEY=${NEXT_PUBLIC_POSTHOG_KEY}
67+
ENV NEXT_PUBLIC_POSTHOG_HOST=${NEXT_PUBLIC_POSTHOG_HOST}
6468

6569
RUN npx next build
6670

@@ -122,6 +126,13 @@ ENV NEXT_PUBLIC_DISABLE_LOGOUT=${NEXT_PUBLIC_DISABLE_LOGOUT}
122126
ARG NEXT_PUBLIC_CUSTOM_REFRESH_URL
123127
ENV NEXT_PUBLIC_CUSTOM_REFRESH_URL=${NEXT_PUBLIC_CUSTOM_REFRESH_URL}
124128

129+
130+
ARG NEXT_PUBLIC_POSTHOG_KEY
131+
ARG NEXT_PUBLIC_POSTHOG_HOST
132+
ENV NEXT_PUBLIC_POSTHOG_KEY=${NEXT_PUBLIC_POSTHOG_KEY}
133+
ENV NEXT_PUBLIC_POSTHOG_HOST=${NEXT_PUBLIC_POSTHOG_HOST}
134+
135+
125136
# Note: Don't expose ports here, Compose will handle that for us if necessary.
126137
# If you want to run this without compose, specify the ports to
127138
# expose via cli

web/package-lock.json

Lines changed: 41 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

web/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
"next": "^14.2.3",
3535
"npm": "^10.8.0",
3636
"postcss": "^8.4.31",
37+
"posthog-js": "^1.176.0",
3738
"prismjs": "^1.29.0",
3839
"react": "^18.3.1",
3940
"react-dom": "^18.3.1",

web/src/app/PostHogPageView.tsx

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
"use client";
2+
3+
import { usePathname, useSearchParams } from "next/navigation";
4+
import { useEffect } from "react";
5+
import { usePostHog } from "posthog-js/react";
6+
7+
export default function PostHogPageView(): null {
8+
const pathname = usePathname();
9+
const searchParams = useSearchParams();
10+
const posthog = usePostHog();
11+
12+
useEffect(() => {
13+
if (!posthog) {
14+
return;
15+
}
16+
17+
// Track pageviews
18+
if (pathname) {
19+
let url = window.origin + pathname;
20+
if (searchParams.toString()) {
21+
url = url + `?${searchParams.toString()}`;
22+
}
23+
posthog.capture("$pageview", {
24+
$current_url: url,
25+
});
26+
}
27+
}, [pathname, searchParams, posthog]);
28+
29+
return null;
30+
}

0 commit comments

Comments
 (0)