Skip to content

Commit

Permalink
Merge pull request #413 from gitroomhq/feat/posthog
Browse files Browse the repository at this point in the history
identification
  • Loading branch information
nevo-david authored Oct 31, 2024
2 parents 458448f + 8a4a397 commit 86d0d24
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions libraries/helpers/src/utils/use.fire.events.ts
Original file line number Diff line number Diff line change
@@ -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;
}
if (user) {
posthog.identify(user.id, { email: user.email, name: user.name });
}

posthog.capture(name, props);
plausible(name, { props });
}, []);
posthog.capture(name, props);
plausible(name, { props });
},
[user]
);
};

0 comments on commit 86d0d24

Please sign in to comment.