Merge pull request #413 from gitroomhq/feat/posthog

identification
This commit is contained in:
Nevo David 2024-10-31 11:54:10 +07:00 committed by GitHub
commit 86d0d2490d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 17 additions and 8 deletions

View File

@ -1,19 +1,28 @@
import { usePlausible } from 'next-plausible';
import { useCallback } from 'react';
import { useVariables } from '@gitroom/react/helpers/variable.context';
import { usePostHog } from 'posthog-js/react';
import { useVariables } from '@gitroom/react/helpers/variable.context';
import { useUser } from '@gitroom/frontend/components/layout/user.context';
export const useFireEvents = () => {
const { billingEnabled } = useVariables();
const plausible = usePlausible();
const posthog = usePostHog();
const user = useUser();
return useCallback((name: string, props?: any) => {
if (!billingEnabled) {
return;
}
return useCallback(
(name: string, props?: any) => {
if (!billingEnabled) {
return;
}
posthog.capture(name, props);
plausible(name, { props });
}, []);
if (user) {
posthog.identify(user.id, { email: user.email, name: user.name });
}
posthog.capture(name, props);
plausible(name, { props });
},
[user]
);
};