Skip to content

Commit 38cb3c9

Browse files
committed
posthog migration: part 1
1 parent cc3fbba commit 38cb3c9

38 files changed

+287
-534
lines changed

apps/dashboard/next.config.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,18 @@ const baseNextConfig: NextConfig = {
146146
},
147147
async rewrites() {
148148
return [
149+
{
150+
source: "/_ph/static/:path*",
151+
destination: "https://us-assets.i.posthog.com/static/:path*",
152+
},
153+
{
154+
source: "/_ph/:path*",
155+
destination: "https://us.i.posthog.com/:path*",
156+
},
157+
{
158+
source: "/_ph/decide",
159+
destination: "https://us.i.posthog.com/decide",
160+
},
149161
{
150162
source: "/thirdweb.eth",
151163
destination: "/deployer.thirdweb.eth",

apps/dashboard/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@
6262
"compare-versions": "^6.1.0",
6363
"date-fns": "4.1.0",
6464
"fast-xml-parser": "^5.2.5",
65-
"flat": "^6.0.1",
6665
"framer-motion": "12.17.0",
6766
"fuse.js": "7.1.0",
6867
"input-otp": "^1.4.1",
@@ -77,7 +76,7 @@
7776
"p-limit": "^6.2.0",
7877
"papaparse": "^5.5.3",
7978
"pluralize": "^8.0.0",
80-
"posthog-js": "1.67.1",
79+
"posthog-js": "1.252.0",
8180
"prettier": "3.5.3",
8281
"qrcode": "^1.5.3",
8382
"react": "19.1.0",

apps/dashboard/src/app/(app)/layout.tsx

Lines changed: 13 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
import "../../global.css";
22
import { DashboardRouterTopProgressBar } from "@/lib/DashboardRouter";
33
import { cn } from "@/lib/utils";
4-
import { PHProvider } from "lib/posthog/Posthog";
5-
import { PosthogHeadSetup } from "lib/posthog/PosthogHeadSetup";
6-
import { PostHogPageView } from "lib/posthog/PosthogPageView";
74
import type { Metadata } from "next";
85
import PlausibleProvider from "next-plausible";
96
import { Inter } from "next/font/google";
@@ -61,26 +58,20 @@ export default function RootLayout({
6158
customDomain="https://pl.thirdweb.com"
6259
selfHosted
6360
/>
64-
<PosthogHeadSetup />
6561
</head>
66-
<PHProvider disable_session_recording={true}>
67-
<PostHogPageView />
68-
<body
69-
className={cn(
70-
"bg-background font-sans antialiased",
71-
fontSans.variable,
72-
)}
73-
>
74-
<AppRouterProviders>{children}</AppRouterProviders>
75-
<DashboardRouterTopProgressBar />
76-
<NextTopLoader
77-
color="hsl(var(--foreground))"
78-
height={3}
79-
shadow={false}
80-
showSpinner={false}
81-
/>
82-
</body>
83-
</PHProvider>
62+
63+
<body
64+
className={cn("bg-background font-sans antialiased", fontSans.variable)}
65+
>
66+
<AppRouterProviders>{children}</AppRouterProviders>
67+
<DashboardRouterTopProgressBar />
68+
<NextTopLoader
69+
color="hsl(var(--foreground))"
70+
height={3}
71+
shadow={false}
72+
showSpinner={false}
73+
/>
74+
</body>
8475
</html>
8576
);
8677
}

apps/dashboard/src/app/(app)/team/[team_slug]/layout.tsx

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { getTeamBySlug, hasToCompleteTeamOnboarding } from "@/api/team";
2-
import { PosthogIdentifierServer } from "components/wallets/PosthogIdentifierServer";
32
import { redirect } from "next/navigation";
43
import { Suspense } from "react";
54
import { getAuthToken } from "../../api/lib/getAuthToken";
@@ -60,9 +59,6 @@ export default async function RootTeamLayout(props: {
6059
<Suspense fallback={null}>
6160
<EnsureValidConnectedWalletLoginServer />
6261
</Suspense>
63-
<Suspense fallback={null}>
64-
<PosthogIdentifierServer />
65-
</Suspense>
6662
</div>
6763
);
6864
}

apps/dashboard/src/app/bridge/components/client/Providers.client.tsx

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
import { ThemeProvider } from "next-themes";
33
import { Toaster } from "sonner";
44
import { ThirdwebProvider } from "thirdweb/react";
5-
import { PHProvider } from "../../../../lib/posthog/Posthog";
6-
import { PostHogPageView } from "../../../../lib/posthog/PosthogPageView";
75

86
export function BridgeProviders({ children }: { children: React.ReactNode }) {
97
return (
@@ -14,11 +12,8 @@ export function BridgeProviders({ children }: { children: React.ReactNode }) {
1412
enableSystem={false}
1513
defaultTheme="dark"
1614
>
17-
<PHProvider disable_session_recording={true}>
18-
<PostHogPageView />
19-
{children}
20-
<Toaster richColors theme="dark" />
21-
</PHProvider>
15+
{children}
16+
<Toaster richColors theme="dark" />
2217
</ThemeProvider>
2318
</ThirdwebProvider>
2419
);
Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,12 @@
11
"use client";
22
import { Toaster } from "sonner";
33
import { ThirdwebProvider } from "thirdweb/react";
4-
import { PHProvider } from "../../../../lib/posthog/Posthog";
5-
import { PostHogPageView } from "../../../../lib/posthog/PosthogPageView";
64

75
export function PayProviders({ children }: { children: React.ReactNode }) {
86
return (
97
<ThirdwebProvider>
10-
<PHProvider disable_session_recording={true}>
11-
<PostHogPageView />
12-
{children}
13-
<Toaster richColors theme="dark" />
14-
</PHProvider>
8+
{children}
9+
<Toaster richColors theme="dark" />
1510
</ThirdwebProvider>
1611
);
1712
}

apps/dashboard/src/components/wallets/PosthogIdentifier.tsx

Lines changed: 0 additions & 81 deletions
This file was deleted.

apps/dashboard/src/components/wallets/PosthogIdentifierServer.tsx

Lines changed: 0 additions & 17 deletions
This file was deleted.
Lines changed: 10 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import { flatten } from "flat";
2-
import { usePostHog } from "posthog-js/react";
31
import { useCallback } from "react";
42

53
export type TrackingParams = {
@@ -9,37 +7,15 @@ export type TrackingParams = {
97
// biome-ignore lint/suspicious/noExplicitAny: FIXME
108
[key: string]: any;
119
};
12-
10+
// TODO: remove this hook entirely
1311
export function useTrack() {
14-
const posthog = usePostHog();
15-
return useCallback(
16-
(trackingData: TrackingParams) => {
17-
const { category, action, label, ...restData } = trackingData;
18-
const catActLab = label
19-
? `${category}.${action}.${label}`
20-
: `${category}.${action}`;
21-
if (process.env.NODE_ENV !== "production") {
22-
console.debug(`[PH.capture]:${catActLab}`, restData);
23-
}
24-
25-
const restDataSafe = Object.fromEntries(
26-
Object.entries(restData).map(([key, value]) => {
27-
if (value instanceof Error) {
28-
return [
29-
key,
30-
{ message: value.message, stack: value.stack?.toString() },
31-
];
32-
}
33-
return [key, value];
34-
}),
35-
);
36-
37-
try {
38-
posthog?.capture(catActLab, flatten(restDataSafe));
39-
} catch {
40-
// ignore - we just don't want to trigger an error in the app if posthog fails
41-
}
42-
},
43-
[posthog],
44-
);
12+
return useCallback((trackingData: TrackingParams) => {
13+
const { category, action, label, ...restData } = trackingData;
14+
const catActLab = label
15+
? `${category}.${action}.${label}`
16+
: `${category}.${action}`;
17+
if (process.env.NODE_ENV !== "production") {
18+
console.debug(`[PH.capture]:${catActLab}`, restData);
19+
}
20+
}, []);
4521
}
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+
const NEXT_PUBLIC_POSTHOG_KEY = process.env.NEXT_PUBLIC_POSTHOG_KEY;
4+
5+
if (NEXT_PUBLIC_POSTHOG_KEY) {
6+
posthog.init(NEXT_PUBLIC_POSTHOG_KEY, {
7+
api_host: "/_ph",
8+
ui_host: "https://us.posthog.com",
9+
capture_pageview: "history_change",
10+
capture_pageleave: "if_capture_pageview",
11+
// disable exception capture (for now)
12+
capture_exceptions: false,
13+
// specifically disable autocapture (does not affect pageview capture)
14+
autocapture: false,
15+
debug: process.env.NODE_ENV === "development",
16+
});
17+
}

apps/dashboard/src/lib/posthog/Posthog.tsx

Lines changed: 0 additions & 27 deletions
This file was deleted.

apps/dashboard/src/lib/posthog/PosthogHeadSetup.tsx

Lines changed: 0 additions & 10 deletions
This file was deleted.

apps/dashboard/src/lib/posthog/PosthogPageView.tsx

Lines changed: 0 additions & 34 deletions
This file was deleted.

0 commit comments

Comments
 (0)