Skip to content

Commit 792fa7f

Browse files
committed
feat: posthog
1 parent d9827f7 commit 792fa7f

File tree

5 files changed

+73
-1
lines changed

5 files changed

+73
-1
lines changed

apps/frontend/src/app/layout.tsx

+7-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import PlausibleProvider from 'next-plausible';
1111
import clsx from 'clsx';
1212
import { VariableContextComponent } from '@gitroom/react/helpers/variable.context';
1313
import { Fragment } from 'react';
14+
import { PHProvider } from '@gitroom/react/helpers/posthog';
1415

1516
const chakra = Chakra_Petch({ weight: '400', subsets: ['latin'] });
1617

@@ -44,7 +45,12 @@ export default async function AppLayout({ children }: { children: ReactNode }) {
4445
<Plausible
4546
domain={!!process.env.IS_GENERAL ? 'postiz.com' : 'gitroom.com'}
4647
>
47-
<LayoutContext>{children}</LayoutContext>
48+
<PHProvider
49+
key={process.env.NEXT_PUBLIC_POSTHOG_KEY}
50+
host={process.env.NEXT_PUBLIC_POSTHOG_HOST}
51+
>
52+
<LayoutContext>{children}</LayoutContext>
53+
</PHProvider>
4854
</Plausible>
4955
</VariableContextComponent>
5056
</body>
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
11
import { usePlausible } from 'next-plausible';
22
import { useCallback } from 'react';
33
import { useVariables } from '@gitroom/react/helpers/variable.context';
4+
import { usePostHog } from 'posthog-js/react';
45

56
export const useFireEvents = () => {
67
const { billingEnabled } = useVariables();
78
const plausible = usePlausible();
9+
const posthog = usePostHog();
10+
811
return useCallback((name: string, props?: any) => {
912
if (!billingEnabled) {
1013
return;
1114
}
15+
16+
posthog.capture(name, props);
1217
plausible(name, { props });
1318
}, []);
1419
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
'use client';
2+
3+
import posthog from 'posthog-js';
4+
import { PostHogProvider } from 'posthog-js/react';
5+
import { FC, ReactNode, useEffect } from 'react';
6+
7+
export const PHProvider: FC<{
8+
children: ReactNode;
9+
key?: string;
10+
host?: string;
11+
}> = ({ children, key, host }) => {
12+
useEffect(() => {
13+
if (!key || !host) {
14+
return;
15+
}
16+
17+
posthog.init(key, {
18+
api_host: host,
19+
person_profiles: 'identified_only',
20+
capture_pageview: false, // Disable automatic pageview capture, as we capture manually
21+
});
22+
}, []);
23+
24+
if (!key || !host) {
25+
return <>{children}</>;
26+
}
27+
return <PostHogProvider client={posthog}>{children}</PostHogProvider>;
28+
};

package-lock.json

+32
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@
121121
"nx": "19.7.2",
122122
"openai": "^4.47.1",
123123
"polotno": "^2.10.5",
124+
"posthog-js": "^1.178.0",
124125
"react": "18.3.1",
125126
"react-colorful": "^5.6.1",
126127
"react-dnd": "^16.0.1",

0 commit comments

Comments
 (0)