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
@@ -3,8 +3,7 @@ import { WorkspaceManager } from '@toeverything/infra';
import { useService } from '@toeverything/infra/di';
import { useLiveData } from '@toeverything/infra/livedata';
import { useAtom } from 'jotai';
import type { ReactElement } from 'react';
import { lazy, Suspense, useCallback } from 'react';
import { lazy, type ReactElement, Suspense, useCallback } from 'react';
import {
authAtom,
@@ -19,6 +18,7 @@ import { useAsyncCallback } from '../hooks/affine-async-hooks';
import { useNavigateHelper } from '../hooks/use-navigate-helper';
import { CurrentWorkspaceService } from '../modules/workspace/current-workspace';
import { WorkspaceSubPath } from '../shared';
import { mixpanel } from '../utils';
import { signOutCloud } from '../utils/cloud-utils';
const SettingModal = lazy(() =>
@@ -218,6 +218,8 @@ export const SignOutConfirmModal = () => {
setOpen(false);
await signOutCloud();
mixpanel.reset();
// if current workspace is affine cloud, switch to local workspace
if (currentWorkspace?.flavour === WorkspaceFlavour.AFFINE_CLOUD) {
const localWorkspace = workspaces.find(
@@ -13,6 +13,7 @@ import {
} from 'react';
import { useOnceSignedInEvents } from '../atoms/event';
import { mixpanel } from '../utils';
export const CloudSessionProvider = (props: PropsWithChildren) => {
const session = useSession();
@@ -28,6 +29,12 @@ export const CloudSessionProvider = (props: PropsWithChildren) => {
).postMessage(1);
}, [onceSignedInEvents]);
useEffect(() => {
if (session.user?.id) {
mixpanel.identify(session.user.id);
}
}, [session]);
useEffect(() => {
if (prevSession.current !== session && session.status !== 'loading') {
// unauthenticated -> authenticated