Skip to content

Commit 3eebe81

Browse files
committed
posthog migration part 2
1 parent 8ac2523 commit 3eebe81

File tree

8 files changed

+135
-0
lines changed

8 files changed

+135
-0
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",
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
"use client";
2+
3+
import posthog from "posthog-js";
4+
import { useEffect } from "react";
5+
6+
export function useIdentifyAccount(opts?: {
7+
accountId: string;
8+
email?: string;
9+
}) {
10+
// eslint-disable-next-line no-restricted-syntax
11+
useEffect(() => {
12+
if (!posthog.__loaded) {
13+
// posthog is not loaded yet, so we can't identify the account
14+
return;
15+
}
16+
// if no accountId, don't identify
17+
if (!opts?.accountId) {
18+
return;
19+
}
20+
21+
// if email is provided, add it to the identify
22+
posthog.identify(opts.accountId, opts.email ? { email: opts.email } : {});
23+
}, [opts?.accountId, opts?.email]);
24+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
"use client";
2+
3+
import posthog from "posthog-js";
4+
import { useEffect } from "react";
5+
6+
export function useIdentifyTeam(opts?: {
7+
teamId: string;
8+
}) {
9+
// eslint-disable-next-line no-restricted-syntax
10+
useEffect(() => {
11+
if (!posthog.__loaded) {
12+
// posthog is not loaded yet, so we can't identify the team
13+
return;
14+
}
15+
// if no teamId, don't identify
16+
if (!opts?.teamId) {
17+
return;
18+
}
19+
20+
// identify the team
21+
posthog.group("team", opts.teamId);
22+
}, [opts?.teamId]);
23+
}

apps/dashboard/src/app/(app)/team/components/TeamHeader/team-header-logged-in.client.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ import type { ThirdwebClient } from "thirdweb";
1313
import { useActiveWallet, useDisconnect } from "thirdweb/react";
1414
import { doLogout } from "../../../login/auth-actions";
1515

16+
import { useIdentifyAccount } from "../../../../../@/analytics/hooks/identify-account";
17+
import { useIdentifyTeam } from "../../../../../@/analytics/hooks/identify-team";
1618
import {
1719
type TeamHeaderCompProps,
1820
TeamHeaderDesktopUI,
@@ -27,6 +29,16 @@ export function TeamHeaderLoggedIn(props: {
2729
accountAddress: string;
2830
client: ThirdwebClient;
2931
}) {
32+
// identify the account
33+
useIdentifyAccount({
34+
accountId: props.account.id,
35+
email: props.account.email,
36+
});
37+
38+
// identify the team
39+
useIdentifyTeam({
40+
teamId: props.currentTeam.id,
41+
});
3042
const [createProjectDialogState, setCreateProjectDialogState] = useState<
3143
{ team: Team; isOpen: true } | { isOpen: false }
3244
>({ isOpen: false });

apps/nebula/next.config.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,22 @@ const baseNextConfig: NextConfig = {
4949
taint: true,
5050
},
5151
serverExternalPackages: ["pino-pretty"],
52+
async rewrites() {
53+
return [
54+
{
55+
source: "/_ph/static/:path*",
56+
destination: "https://us-assets.i.posthog.com/static/:path*",
57+
},
58+
{
59+
source: "/_ph/:path*",
60+
destination: "https://us.i.posthog.com/:path*",
61+
},
62+
{
63+
source: "/_ph/decide",
64+
destination: "https://us.i.posthog.com/decide",
65+
},
66+
];
67+
},
5268
async headers() {
5369
return [
5470
{

apps/playground-web/next.config.mjs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,22 @@ const nextConfig = {
5858
config.externals.push("pino-pretty", "lokijs", "encoding");
5959
return config;
6060
},
61+
async rewrites() {
62+
return [
63+
{
64+
source: "/_ph/static/:path*",
65+
destination: "https://us-assets.i.posthog.com/static/:path*",
66+
},
67+
{
68+
source: "/_ph/:path*",
69+
destination: "https://us.i.posthog.com/:path*",
70+
},
71+
{
72+
source: "/_ph/decide",
73+
destination: "https://us.i.posthog.com/decide",
74+
},
75+
];
76+
},
6177
async redirects() {
6278
return [
6379
{

apps/portal/next.config.mjs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,22 @@ const nextConfig = {
5858
},
5959
pageExtensions: ["mdx", "tsx", "ts"],
6060
redirects,
61+
async rewrites() {
62+
return [
63+
{
64+
source: "/_ph/static/:path*",
65+
destination: "https://us-assets.i.posthog.com/static/:path*",
66+
},
67+
{
68+
source: "/_ph/:path*",
69+
destination: "https://us.i.posthog.com/:path*",
70+
},
71+
{
72+
source: "/_ph/decide",
73+
destination: "https://us.i.posthog.com/decide",
74+
},
75+
];
76+
},
6177
webpack: (config) => {
6278
config.externals.push("pino-pretty", "lokijs", "encoding");
6379
return config;

apps/wallet-ui/next.config.mjs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,22 @@ const nextConfig = {
5555
webpackMemoryOptimizations: true,
5656
serverSourceMaps: false,
5757
},
58+
async rewrites() {
59+
return [
60+
{
61+
source: "/_ph/static/:path*",
62+
destination: "https://us-assets.i.posthog.com/static/:path*",
63+
},
64+
{
65+
source: "/_ph/:path*",
66+
destination: "https://us.i.posthog.com/:path*",
67+
},
68+
{
69+
source: "/_ph/decide",
70+
destination: "https://us.i.posthog.com/decide",
71+
},
72+
];
73+
},
5874
webpack: (config) => {
5975
config.externals.push("pino-pretty", "lokijs", "encoding");
6076
return config;

0 commit comments

Comments
 (0)