Skip to content

posthog migration: part 1 #7363

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions apps/dashboard/next.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,18 @@ const baseNextConfig: NextConfig = {
},
async rewrites() {
return [
{
source: "/_ph/static/:path*",
destination: "https://us-assets.i.posthog.com/static/:path*",
},
{
source: "/_ph/:path*",
destination: "https://us.i.posthog.com/:path*",
},
{
source: "/_ph/decide",
destination: "https://us.i.posthog.com/decide",
},
{
source: "/thirdweb.eth",
destination: "/deployer.thirdweb.eth",
Expand Down
3 changes: 1 addition & 2 deletions apps/dashboard/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@
"compare-versions": "^6.1.0",
"date-fns": "4.1.0",
"fast-xml-parser": "^5.2.5",
"flat": "^6.0.1",
"framer-motion": "12.17.0",
"fuse.js": "7.1.0",
"input-otp": "^1.4.1",
Expand All @@ -77,7 +76,7 @@
"p-limit": "^6.2.0",
"papaparse": "^5.5.3",
"pluralize": "^8.0.0",
"posthog-js": "1.67.1",
"posthog-js": "1.252.0",
"prettier": "3.5.3",
"qrcode": "^1.5.3",
"react": "19.1.0",
Expand Down
35 changes: 13 additions & 22 deletions apps/dashboard/src/app/(app)/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import "../../global.css";
import { DashboardRouterTopProgressBar } from "@/lib/DashboardRouter";
import { cn } from "@/lib/utils";
import { PHProvider } from "lib/posthog/Posthog";
import { PosthogHeadSetup } from "lib/posthog/PosthogHeadSetup";
import { PostHogPageView } from "lib/posthog/PosthogPageView";
import type { Metadata } from "next";
import PlausibleProvider from "next-plausible";
import { Inter } from "next/font/google";
Expand Down Expand Up @@ -61,26 +58,20 @@ export default function RootLayout({
customDomain="https://pl.thirdweb.com"
selfHosted
/>
<PosthogHeadSetup />
</head>
<PHProvider disable_session_recording={true}>
<PostHogPageView />
<body
className={cn(
"bg-background font-sans antialiased",
fontSans.variable,
)}
>
<AppRouterProviders>{children}</AppRouterProviders>
<DashboardRouterTopProgressBar />
<NextTopLoader
color="hsl(var(--foreground))"
height={3}
shadow={false}
showSpinner={false}
/>
</body>
</PHProvider>

<body
className={cn("bg-background font-sans antialiased", fontSans.variable)}
>
<AppRouterProviders>{children}</AppRouterProviders>
<DashboardRouterTopProgressBar />
<NextTopLoader
color="hsl(var(--foreground))"
height={3}
shadow={false}
showSpinner={false}
/>
</body>
</html>
);
}
4 changes: 0 additions & 4 deletions apps/dashboard/src/app/(app)/team/[team_slug]/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { getTeamBySlug, hasToCompleteTeamOnboarding } from "@/api/team";
import { PosthogIdentifierServer } from "components/wallets/PosthogIdentifierServer";
import { redirect } from "next/navigation";
import { Suspense } from "react";
import { getAuthToken } from "../../api/lib/getAuthToken";
Expand Down Expand Up @@ -60,9 +59,6 @@ export default async function RootTeamLayout(props: {
<Suspense fallback={null}>
<EnsureValidConnectedWalletLoginServer />
</Suspense>
<Suspense fallback={null}>
<PosthogIdentifierServer />
</Suspense>
</div>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
import { ThemeProvider } from "next-themes";
import { Toaster } from "sonner";
import { ThirdwebProvider } from "thirdweb/react";
import { PHProvider } from "../../../../lib/posthog/Posthog";
import { PostHogPageView } from "../../../../lib/posthog/PosthogPageView";

export function BridgeProviders({ children }: { children: React.ReactNode }) {
return (
Expand All @@ -14,11 +12,8 @@ export function BridgeProviders({ children }: { children: React.ReactNode }) {
enableSystem={false}
defaultTheme="dark"
>
<PHProvider disable_session_recording={true}>
<PostHogPageView />
{children}
<Toaster richColors theme="dark" />
</PHProvider>
{children}
<Toaster richColors theme="dark" />
</ThemeProvider>
</ThirdwebProvider>
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
"use client";
import { Toaster } from "sonner";
import { ThirdwebProvider } from "thirdweb/react";
import { PHProvider } from "../../../../lib/posthog/Posthog";
import { PostHogPageView } from "../../../../lib/posthog/PosthogPageView";

export function PayProviders({ children }: { children: React.ReactNode }) {
return (
<ThirdwebProvider>
<PHProvider disable_session_recording={true}>
<PostHogPageView />
{children}
<Toaster richColors theme="dark" />
</PHProvider>
{children}
<Toaster richColors theme="dark" />
</ThirdwebProvider>
);
}
81 changes: 0 additions & 81 deletions apps/dashboard/src/components/wallets/PosthogIdentifier.tsx

This file was deleted.

This file was deleted.

44 changes: 10 additions & 34 deletions apps/dashboard/src/hooks/analytics/useTrack.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { flatten } from "flat";
import { usePostHog } from "posthog-js/react";
import { useCallback } from "react";

export type TrackingParams = {
Expand All @@ -9,37 +7,15 @@ export type TrackingParams = {
// biome-ignore lint/suspicious/noExplicitAny: FIXME
[key: string]: any;
};

// TODO: remove this hook entirely
export function useTrack() {
const posthog = usePostHog();
return useCallback(
(trackingData: TrackingParams) => {
const { category, action, label, ...restData } = trackingData;
const catActLab = label
? `${category}.${action}.${label}`
: `${category}.${action}`;
if (process.env.NODE_ENV !== "production") {
console.debug(`[PH.capture]:${catActLab}`, restData);
}

const restDataSafe = Object.fromEntries(
Object.entries(restData).map(([key, value]) => {
if (value instanceof Error) {
return [
key,
{ message: value.message, stack: value.stack?.toString() },
];
}
return [key, value];
}),
);

try {
posthog?.capture(catActLab, flatten(restDataSafe));
} catch {
// ignore - we just don't want to trigger an error in the app if posthog fails
}
},
[posthog],
);
return useCallback((trackingData: TrackingParams) => {
const { category, action, label, ...restData } = trackingData;
const catActLab = label
? `${category}.${action}.${label}`
: `${category}.${action}`;
if (process.env.NODE_ENV !== "production") {
console.debug(`[PH.capture]:${catActLab}`, restData);
}
}, []);
}
17 changes: 17 additions & 0 deletions apps/dashboard/src/instrumentation-client.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import posthog from "posthog-js";

const NEXT_PUBLIC_POSTHOG_KEY = process.env.NEXT_PUBLIC_POSTHOG_KEY;

if (NEXT_PUBLIC_POSTHOG_KEY) {
posthog.init(NEXT_PUBLIC_POSTHOG_KEY, {
api_host: "/_ph",
ui_host: "https://us.posthog.com",
capture_pageview: "history_change",
capture_pageleave: "if_capture_pageview",
// disable exception capture (for now)
capture_exceptions: false,
// specifically disable autocapture (does not affect pageview capture)
autocapture: false,
debug: process.env.NODE_ENV === "development",
});
}
27 changes: 0 additions & 27 deletions apps/dashboard/src/lib/posthog/Posthog.tsx

This file was deleted.

10 changes: 0 additions & 10 deletions apps/dashboard/src/lib/posthog/PosthogHeadSetup.tsx

This file was deleted.

34 changes: 0 additions & 34 deletions apps/dashboard/src/lib/posthog/PosthogPageView.tsx

This file was deleted.

Loading
Loading