error track

This commit is contained in:
archer
2023-09-03 18:26:36 +08:00
parent e0b23a26f2
commit 1ace8fb9a3
4 changed files with 38 additions and 6 deletions

View File

@@ -12,6 +12,7 @@ import { clientInitData, feConfigs } from '@/store/static';
import { appWithTranslation, useTranslation } from 'next-i18next';
import { getLangStore, setLangStore } from '@/utils/i18n';
import { useRouter } from 'next/router';
import { useGlobalStore } from '@/store/global';
import 'nprogress/nprogress.css';
import '@/styles/reset.scss';
@@ -37,6 +38,7 @@ function App({ Component, pageProps }: AppProps) {
const router = useRouter();
const { hiId } = router.query as { hiId?: string };
const { i18n } = useTranslation();
const { setLastRoute } = useGlobalStore();
const [scripts, setScripts] = useState<FeConfigsType['scripts']>([]);
const [googleClientVerKey, setGoogleVerKey] = useState<string>();
@@ -75,6 +77,10 @@ function App({ Component, pageProps }: AppProps) {
const lang = getLangStore() || 'zh';
i18n?.changeLanguage?.(lang);
setLangStore(lang);
return () => {
setLastRoute(router.asPath);
};
}, [router.asPath]);
return (

View File

@@ -1,14 +1,22 @@
import { useEffect } from 'react';
import { useRouter } from 'next/router';
import { serviceSideProps } from '@/utils/i18n';
import { useGlobalStore } from '@/store/global';
import { addLog } from '@/service/utils/tools';
import { getErrText } from '@/utils/tools';
function Error() {
const router = useRouter();
const { lastRoute } = useGlobalStore();
useEffect(() => {
setTimeout(() => {
window.umami?.track('pageError', {
userAgent: navigator.userAgent,
platform: navigator.platform,
appName: navigator.appName
appName: navigator.appName,
lastRoute,
route: router.asPath
});
}, 1000);
@@ -26,7 +34,9 @@ function Error() {
}
export async function getServerSideProps(context: any) {
console.log(context);
console.log('[render error]: ', context);
addLog.error(getErrText(context?.res));
return {
props: { ...(await serviceSideProps(context)) }