From ea804478a366ee8ee6133c915fc327d5a0b43d4d Mon Sep 17 00:00:00 2001 From: Kaosiso Ezealigo Date: Tue, 12 Dec 2023 10:51:23 +0100 Subject: [PATCH] modifies posthog logic --- agenta-web/src/components/AppSelector/AppSelector.tsx | 6 ++---- agenta-web/src/contexts/profile.context.tsx | 3 +++ agenta-web/src/hooks/useSession.ts | 2 ++ 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/agenta-web/src/components/AppSelector/AppSelector.tsx b/agenta-web/src/components/AppSelector/AppSelector.tsx index b5c274509c..37228bed09 100644 --- a/agenta-web/src/components/AppSelector/AppSelector.tsx +++ b/agenta-web/src/components/AppSelector/AppSelector.tsx @@ -105,7 +105,7 @@ const AppSelector: React.FC = () => { const [isWriteAppModalOpen, setIsWriteAppModalOpen] = useState(false) const [isMaxAppModalOpen, setIsMaxAppModalOpen] = useState(false) const [templates, setTemplates] = useState([]) - + const {user} = useProfileData() const [templateMessage, setTemplateMessage] = useState("") const [templateId, setTemplateId] = useState(undefined) const [isInputTemplateModalOpen, setIsInputTemplateModalOpen] = useState(false) @@ -212,13 +212,11 @@ const AppSelector: React.FC = () => { mutate() if (trackingEnabled) { - const profileRes = await getProfile() - posthog.identify(profileRes?.data?.id) posthog.capture("app_deployment", { properties: { app_id: appId, environment: "UI", - deployed_by: profileRes?.data?.id, + deployed_by: user?.id, }, }) } diff --git a/agenta-web/src/contexts/profile.context.tsx b/agenta-web/src/contexts/profile.context.tsx index a7afb91a65..e15215a0bf 100644 --- a/agenta-web/src/contexts/profile.context.tsx +++ b/agenta-web/src/contexts/profile.context.tsx @@ -4,6 +4,7 @@ import {isDemo} from "@/lib/helpers/utils" import {getOrgsList, getProfile} from "@/lib/services/api" import {Org, User} from "@/lib/Types" import {useRouter} from "next/router" +import { usePostHog } from "posthog-js/react" import { PropsWithChildren, createContext, @@ -54,6 +55,7 @@ const profileContextValues = {...initialValues} export const getProfileValues = () => profileContextValues const ProfileContextProvider: React.FC = ({children}) => { + const posthog = usePostHog() const router = useRouter() const [user, setUser] = useState(null) const [orgs, setOrgs] = useState([]) @@ -65,6 +67,7 @@ const ProfileContextProvider: React.FC = ({children}) => { setLoading(true) Promise.all([getProfile(), getOrgsList()]) .then(([profile, orgs]) => { + posthog.identify(isDemo() ? profile.data.email : profile.data.id) setUser(profile.data) setOrgs(orgs.data) setSelectedOrg( diff --git a/agenta-web/src/hooks/useSession.ts b/agenta-web/src/hooks/useSession.ts index acea322698..196288e246 100644 --- a/agenta-web/src/hooks/useSession.ts +++ b/agenta-web/src/hooks/useSession.ts @@ -1,6 +1,7 @@ import {useProfileData} from "@/contexts/profile.context" import {isDemo} from "@/lib/helpers/utils" import {useRouter} from "next/router" +import posthog from "posthog-js" import {useSessionContext} from "supertokens-auth-react/recipe/session" import {signOut} from "supertokens-auth-react/recipe/thirdpartypasswordless" @@ -17,6 +18,7 @@ export const useSession: () => {loading: boolean; doesSessionExist: boolean; log logout: () => { signOut() .then(() => { + posthog.reset() reset() router.push("/auth") })