From 8a4a397d0a7dbdcae30ba75346235bbd3ae4b6e5 Mon Sep 17 00:00:00 2001 From: Nevo David Date: Thu, 31 Oct 2024 11:53:24 +0700 Subject: [PATCH] feat: variables --- .../helpers/src/utils/use.fire.events.ts | 25 +++++++++++++------ 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/libraries/helpers/src/utils/use.fire.events.ts b/libraries/helpers/src/utils/use.fire.events.ts index b23a2e86..2f39fd56 100644 --- a/libraries/helpers/src/utils/use.fire.events.ts +++ b/libraries/helpers/src/utils/use.fire.events.ts @@ -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] + ); };