chore(core): add mixpanel track (#6202)

This commit is contained in:
Brooooooklyn
2024-03-22 09:24:40 +00:00
parent 10af0ab48d
commit 150c22936d
21 changed files with 229 additions and 67 deletions

View File

@@ -1,59 +1,81 @@
import * as Sentry from '@sentry/react';
import { wrapCreateBrowserRouter } from '@sentry/react';
import { useEffect } from 'react';
import type { RouteObject } from 'react-router-dom';
import { createBrowserRouter as reactRouterCreateBrowserRouter } from 'react-router-dom';
import {
createBrowserRouter as reactRouterCreateBrowserRouter,
Outlet,
useLocation,
} from 'react-router-dom';
export const workbenchRoutes = [
import { mixpanel } from './utils';
function RootRouter() {
const location = useLocation();
useEffect(() => {
mixpanel.track_pageview({
page: location.pathname,
});
}, [location]);
return <Outlet />;
}
export const topLevelRoutes = [
{
path: '/',
lazy: () => import('./pages/index'),
},
{
path: '/workspace/:workspaceId/*',
lazy: () => import('./pages/workspace/index'),
},
{
path: '/share/:workspaceId/:pageId',
lazy: () => import('./pages/share/share-detail-page'),
},
{
path: '/404',
lazy: () => import('./pages/404'),
},
{
path: '/auth/:authType',
lazy: () => import('./pages/auth'),
},
{
path: '/expired',
lazy: () => import('./pages/expired'),
},
{
path: '/invite/:inviteId',
lazy: () => import('./pages/invite'),
},
{
path: '/signIn',
lazy: () => import('./pages/sign-in'),
},
{
path: '/open-app/:action',
lazy: () => import('./pages/open-app'),
},
{
path: '/upgrade-success',
lazy: () => import('./pages/upgrade-success'),
},
{
path: '/desktop-signin',
lazy: () => import('./pages/desktop-signin'),
},
{
path: '/onboarding',
lazy: () => import('./pages/onboarding'),
},
{
path: '*',
lazy: () => import('./pages/404'),
element: <RootRouter />,
children: [
{
path: '/',
lazy: () => import('./pages/index'),
},
{
path: '/workspace/:workspaceId/*',
lazy: () => import('./pages/workspace/index'),
},
{
path: '/share/:workspaceId/:pageId',
lazy: () => import('./pages/share/share-detail-page'),
},
{
path: '/404',
lazy: () => import('./pages/404'),
},
{
path: '/auth/:authType',
lazy: () => import('./pages/auth'),
},
{
path: '/expired',
lazy: () => import('./pages/expired'),
},
{
path: '/invite/:inviteId',
lazy: () => import('./pages/invite'),
},
{
path: '/signIn',
lazy: () => import('./pages/sign-in'),
},
{
path: '/open-app/:action',
lazy: () => import('./pages/open-app'),
},
{
path: '/upgrade-success',
lazy: () => import('./pages/upgrade-success'),
},
{
path: '/desktop-signin',
lazy: () => import('./pages/desktop-signin'),
},
{
path: '/onboarding',
lazy: () => import('./pages/onboarding'),
},
{
path: '*',
lazy: () => import('./pages/404'),
},
],
},
] satisfies [RouteObject, ...RouteObject[]];
@@ -92,10 +114,10 @@ export const viewRoutes = [
},
] satisfies [RouteObject, ...RouteObject[]];
const createBrowserRouter = Sentry.wrapCreateBrowserRouter(
const createBrowserRouter = wrapCreateBrowserRouter(
reactRouterCreateBrowserRouter
);
export const router = createBrowserRouter(workbenchRoutes, {
export const router = createBrowserRouter(topLevelRoutes, {
future: {
v7_normalizeFormMethod: true,
},