diff --git a/web/app/account/(commonLayout)/avatar.tsx b/web/app/account/(commonLayout)/avatar.tsx index d8943b7879..ef8f6334f1 100644 --- a/web/app/account/(commonLayout)/avatar.tsx +++ b/web/app/account/(commonLayout)/avatar.tsx @@ -12,6 +12,7 @@ import { useProviderContext } from '@/context/provider-context' import { LogOut01 } from '@/app/components/base/icons/src/vender/line/general' import PremiumBadge from '@/app/components/base/premium-badge' import { useLogout } from '@/service/use-common' +import { resetUser } from '@/app/components/base/amplitude/utils' export type IAppSelector = { isMobile: boolean @@ -28,6 +29,7 @@ export default function AppSelector() { await logout() localStorage.removeItem('setup_status') + resetUser() // Tokens are now stored in cookies and cleared by backend router.push('/signin') diff --git a/web/app/components/app/create-app-dialog/app-list/index.tsx b/web/app/components/app/create-app-dialog/app-list/index.tsx index 456f65d7c2..51b6874d52 100644 --- a/web/app/components/app/create-app-dialog/app-list/index.tsx +++ b/web/app/components/app/create-app-dialog/app-list/index.tsx @@ -148,8 +148,7 @@ const Apps = ({ app_mode: mode, template_id: currApp?.app.id, template_name: currApp?.app.name, - time: new Date().toLocaleString('zh-CN', { timeZone: 'Asia/Shanghai' }), - has_description: description, + description, }) setIsShowCreateModal(false) diff --git a/web/app/components/app/create-app-modal/index.tsx b/web/app/components/app/create-app-modal/index.tsx index 8947c2fb37..a449ec8ef2 100644 --- a/web/app/components/app/create-app-modal/index.tsx +++ b/web/app/components/app/create-app-modal/index.tsx @@ -87,7 +87,6 @@ function CreateApp({ onClose, onSuccess, onCreateFromTemplate, defaultAppMode }: // Track app creation success trackEvent('create_app', { app_mode: appMode, - time: new Date().toLocaleString('zh-CN', { timeZone: 'Asia/Shanghai' }), description, }) diff --git a/web/app/components/app/workflow-log/filter.tsx b/web/app/components/app/workflow-log/filter.tsx index c792bb8a48..0c8d72c1be 100644 --- a/web/app/components/app/workflow-log/filter.tsx +++ b/web/app/components/app/workflow-log/filter.tsx @@ -8,7 +8,7 @@ import quarterOfYear from 'dayjs/plugin/quarterOfYear' import type { QueryParam } from './index' import Chip from '@/app/components/base/chip' import Input from '@/app/components/base/input' -import { trackEvent } from '../../base/amplitude/utils' +import { trackEvent } from '@/app/components/base/amplitude/utils' dayjs.extend(quarterOfYear) const today = dayjs() diff --git a/web/app/components/base/amplitude/AmplitudeProvider.tsx b/web/app/components/base/amplitude/AmplitudeProvider.tsx index 49b77fb980..826535d5d4 100644 --- a/web/app/components/base/amplitude/AmplitudeProvider.tsx +++ b/web/app/components/base/amplitude/AmplitudeProvider.tsx @@ -12,11 +12,11 @@ export type IAmplitudeProps = { } const AmplitudeProvider: FC = ({ - apiKey = '702e89332ab88a7f14e665f417244e9d', + apiKey = process.env.NEXT_PUBLIC_AMPLITUDE_API_KEY ?? '', sessionReplaySampleRate = 1, }) => { useEffect(() => { - // // Only enable in non-CE edition + // Only enable in non-CE edition if (IS_CE_EDITION) { console.warn('[Amplitude] Amplitude is disabled in CE edition') return @@ -39,7 +39,7 @@ const AmplitudeProvider: FC = ({ sampleRate: sessionReplaySampleRate, }) amplitude.add(sessionReplay) - }, [apiKey, sessionReplaySampleRate]) + }, []) // This is a client component that renders nothing return null diff --git a/web/app/components/header/account-dropdown/index.tsx b/web/app/components/header/account-dropdown/index.tsx index d00cddc693..a9fc37aec9 100644 --- a/web/app/components/header/account-dropdown/index.tsx +++ b/web/app/components/header/account-dropdown/index.tsx @@ -34,6 +34,7 @@ import { useGlobalPublicStore } from '@/context/global-public-context' import { useDocLink } from '@/context/i18n' import { useLogout } from '@/service/use-common' import { ACCOUNT_SETTING_TAB } from '@/app/components/header/account-setting/constants' +import { resetUser } from '@/app/components/base/amplitude/utils' export default function AppSelector() { const itemClassName = ` @@ -53,7 +54,7 @@ export default function AppSelector() { const { mutateAsync: logout } = useLogout() const handleLogout = async () => { await logout() - + resetUser() localStorage.removeItem('setup_status') // Tokens are now stored in cookies and cleared by backend diff --git a/web/app/signin/check-code/page.tsx b/web/app/signin/check-code/page.tsx index 7055eabc75..4af2bdd1cc 100644 --- a/web/app/signin/check-code/page.tsx +++ b/web/app/signin/check-code/page.tsx @@ -48,7 +48,6 @@ export default function CheckCode() { // Track login success event trackEvent('user_login_success', { method: 'email_code', - time: new Date().toLocaleString('zh-CN', { timeZone: 'Asia/Shanghai' }), is_invite: !!invite_token, }) diff --git a/web/app/signin/components/mail-and-password-auth.tsx b/web/app/signin/components/mail-and-password-auth.tsx index f6fb8e3664..ba37087719 100644 --- a/web/app/signin/components/mail-and-password-auth.tsx +++ b/web/app/signin/components/mail-and-password-auth.tsx @@ -67,7 +67,6 @@ export default function MailAndPasswordAuth({ isInvite, isEmailSetup, allowRegis // Track login success event trackEvent('user_login_success', { method: 'email_password', - time: new Date().toLocaleString('zh-CN', { timeZone: 'Asia/Shanghai' }), is_invite: isInvite, }) diff --git a/web/app/signup/set-password/page.tsx b/web/app/signup/set-password/page.tsx index 71b59d3e7c..1e176b8d2f 100644 --- a/web/app/signup/set-password/page.tsx +++ b/web/app/signup/set-password/page.tsx @@ -58,7 +58,6 @@ const ChangePasswordForm = () => { // Track registration success event trackEvent('user_registration_success', { method: 'email', - time: new Date().toLocaleString('zh-CN', { timeZone: 'Asia/Shanghai' }), }) Toast.notify({ diff --git a/web/context/app-context.tsx b/web/context/app-context.tsx index f1f0042909..426ef2217e 100644 --- a/web/context/app-context.tsx +++ b/web/context/app-context.tsx @@ -160,32 +160,27 @@ export const AppContextProvider: FC = ({ children }) => }, [currentWorkspace?.id]) // #endregion Zendesk conversation fields - // #region Amplitude user tracking useEffect(() => { - // Report user info to Amplitude when loaded + // Report user and workspace info to Amplitude when loaded if (userProfile?.id) { setUserId(userProfile.email) - setUserProperties({ + const properties: Record = { email: userProfile.email, name: userProfile.name, has_password: userProfile.is_password_set, - }) - } - }, [userProfile?.id, userProfile?.email, userProfile?.name, userProfile?.is_password_set]) + } - useEffect(() => { - // Report workspace info to Amplitude when loaded - if (currentWorkspace?.id && userProfile?.id) { - setUserProperties({ - workspace_id: currentWorkspace.id, - workspace_name: currentWorkspace.name, - workspace_plan: currentWorkspace.plan, - workspace_status: currentWorkspace.status, - workspace_role: currentWorkspace.role, - }) + if (currentWorkspace?.id) { + properties.workspace_id = currentWorkspace.id + properties.workspace_name = currentWorkspace.name + properties.workspace_plan = currentWorkspace.plan + properties.workspace_status = currentWorkspace.status + properties.workspace_role = currentWorkspace.role + } + + setUserProperties(properties) } - }, [currentWorkspace?.id, currentWorkspace?.name, currentWorkspace?.plan, currentWorkspace?.status, currentWorkspace?.role, userProfile?.id]) - // #endregion Amplitude user tracking + }, [userProfile, currentWorkspace]) return (