Skip to content

Commit 86d0d24

Browse files
authored
Merge pull request #413 from gitroomhq/feat/posthog
identification
2 parents 458448f + 8a4a397 commit 86d0d24

File tree

1 file changed

+17
-8
lines changed

1 file changed

+17
-8
lines changed
Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,28 @@
11
import { usePlausible } from 'next-plausible';
22
import { useCallback } from 'react';
3-
import { useVariables } from '@gitroom/react/helpers/variable.context';
43
import { usePostHog } from 'posthog-js/react';
4+
import { useVariables } from '@gitroom/react/helpers/variable.context';
5+
import { useUser } from '@gitroom/frontend/components/layout/user.context';
56

67
export const useFireEvents = () => {
78
const { billingEnabled } = useVariables();
89
const plausible = usePlausible();
910
const posthog = usePostHog();
11+
const user = useUser();
12+
13+
return useCallback(
14+
(name: string, props?: any) => {
15+
if (!billingEnabled) {
16+
return;
17+
}
1018

11-
return useCallback((name: string, props?: any) => {
12-
if (!billingEnabled) {
13-
return;
14-
}
19+
if (user) {
20+
posthog.identify(user.id, { email: user.email, name: user.name });
21+
}
1522

16-
posthog.capture(name, props);
17-
plausible(name, { props });
18-
}, []);
23+
posthog.capture(name, props);
24+
plausible(name, { props });
25+
},
26+
[user]
27+
);
1928
};

0 commit comments

Comments
 (0)