Skip to content

Commit

Permalink
chore(core): replace with new track impl
Browse files Browse the repository at this point in the history
  • Loading branch information
forehalo committed Aug 5, 2024
1 parent cb396d2 commit da5e9c8
Show file tree
Hide file tree
Showing 58 changed files with 429 additions and 752 deletions.
7 changes: 2 additions & 5 deletions packages/frontend/core/src/commands/affine-navigation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import type { createStore } from 'jotai';

import { openSettingModalAtom, openWorkspaceListModalAtom } from '../atoms';
import type { useNavigateHelper } from '../hooks/use-navigate-helper';
import { mixpanel, track } from '../mixpanel';
import { track } from '../mixpanel';
import { registerAffineCommand } from './registry';

export function registerAffineNavigationCommands({
Expand Down Expand Up @@ -93,10 +93,7 @@ export function registerAffineNavigationCommands({
icon: <ArrowRightBigIcon />,
label: t['com.affine.cmdk.affine.navigation.open-account-settings'](),
run() {
mixpanel.track('AccountSettingsViewed', {
// page:
segment: 'cmdk',
});
track.$.cmdk.settings.openAccountSettings();
store.set(openSettingModalAtom, s => ({
activeTab: 'account',
open: !s.open,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Button, FlexWrapper, notify } from '@affine/component';
import { openSettingModalAtom } from '@affine/core/atoms';
import { mixpanel } from '@affine/core/mixpanel';
import { track } from '@affine/core/mixpanel';
import { SubscriptionService } from '@affine/core/modules/cloud';
import { useI18n } from '@affine/i18n';
import { AiIcon } from '@blocksuite/icons/rc';
Expand Down Expand Up @@ -65,11 +65,7 @@ export const AIOnboardingEdgeless = () => {
const mode = useLiveData(doc.mode$);

const goToPricingPlans = useCallback(() => {
mixpanel.track('PlansViewed', {
page: 'whiteboard editor',
segment: 'ai onboarding',
module: 'whiteboard dialog',
});
track.$.aiOnboarding.dialog.viewPlans();
setSettingModal({
open: true,
activeTab: 'plans',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Button, IconButton, Modal } from '@affine/component';
import { openSettingModalAtom } from '@affine/core/atoms';
import { useBlurRoot } from '@affine/core/hooks/use-blur-root';
import { mixpanel } from '@affine/core/mixpanel';
import { track } from '@affine/core/mixpanel';
import { AuthService, SubscriptionService } from '@affine/core/modules/cloud';
import { Trans, useI18n } from '@affine/i18n';
import { ArrowLeftSmallIcon } from '@blocksuite/icons/rc';
Expand Down Expand Up @@ -116,11 +116,7 @@ export const AIOnboardingGeneral = () => {
activeTab: 'plans',
scrollAnchor: 'aiPricingPlan',
});
mixpanel.track('PlansViewed', {
page: 'whiteboard editor',
segment: 'ai onboarding',
module: 'general',
});
track.$.aiOnboarding.dialog.viewPlans();
closeAndDismiss();
}, [closeAndDismiss, setSettingModal]);
const onPrev = useCallback(() => {
Expand Down
4 changes: 2 additions & 2 deletions packages/frontend/core/src/components/affine/auth/oauth.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { notify, Skeleton } from '@affine/component';
import { Button } from '@affine/component/ui/button';
import { useAsyncCallback } from '@affine/core/hooks/affine-async-hooks';
import { mixpanel } from '@affine/core/mixpanel';
import { track } from '@affine/core/mixpanel';
import { OAuthProviderType } from '@affine/graphql';
import { GithubIcon, GoogleDuotoneIcon } from '@blocksuite/icons/rc';
import { useLiveData, useService } from '@toeverything/infra';
Expand Down Expand Up @@ -75,7 +75,7 @@ function OAuthProvider({
notify.error({ title: 'Failed to sign in, please try again.' });
} finally {
setIsConnecting(false);
mixpanel.track('OAuth', { provider });
track.$.$.auth.oauth(provider);
}
}, [authService, provider, redirectUri]);

Expand Down
10 changes: 3 additions & 7 deletions packages/frontend/core/src/components/affine/auth/sign-in.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { AuthInput, ModalHeader } from '@affine/component/auth-components';
import { Button } from '@affine/component/ui/button';
import { authAtom } from '@affine/core/atoms';
import { useAsyncCallback } from '@affine/core/hooks/affine-async-hooks';
import { mixpanel } from '@affine/core/mixpanel';
import { track } from '@affine/core/mixpanel';
import { Trans, useI18n } from '@affine/i18n';
import { ArrowRightBigIcon } from '@blocksuite/icons/rc';
import { useLiveData, useService } from '@toeverything/infra';
Expand Down Expand Up @@ -75,9 +75,7 @@ export const SignIn: FC<AuthPanelProps> = ({
if (hasPassword) {
setAuthState('signInWithPassword');
} else {
mixpanel.track('SignIn', {
email,
});
track.$.$.auth.signIn();
await authService.sendEmailMagicLink(
email,
verifyToken,
Expand All @@ -93,9 +91,7 @@ export const SignIn: FC<AuthPanelProps> = ({
challenge,
searchParams.get('redirect_uri')
);
mixpanel.track('SignUp', {
email,
});
track.$.$.auth.signUp();
setAuthState('afterSignUpSendEmail');
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Tooltip } from '@affine/component/ui/tooltip';
import { mixpanel } from '@affine/core/mixpanel';
import { SubscriptionPlan } from '@affine/graphql';
import { useI18n } from '@affine/i18n';
import { useLiveData, useServices } from '@toeverything/infra';
Expand Down Expand Up @@ -44,10 +43,6 @@ export const UserPlanButton = () => {
activeTab: 'plans',
scrollAnchor: 'cloudPricingPlan',
});
mixpanel.track('PlansViewed', {
segment: 'settings panel',
module: 'profile and badge',
});
},
[setSettingModalAtom]
);
Expand All @@ -64,14 +59,15 @@ export const UserPlanButton = () => {
return;
}

const planLabel = isBeliever ? 'Believer' : (plan ?? SubscriptionPlan.Free);
const planLabel = isBeliever ? 'Believer' : plan ?? SubscriptionPlan.Free;

return (
<Tooltip content={t['com.affine.payment.tag-tooltips']()} side="top">
<div
data-is-believer={isBeliever ? 'true' : undefined}
className={styles.userPlanButton}
onClick={handleClick}
data-event-props="$.settingsPanel.profileAndBadge.viewPlans"
>
{planLabel}
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type { ConfirmModalProps } from '@affine/component/ui/modal';
import { ConfirmModal, Modal } from '@affine/component/ui/modal';
import { authAtom } from '@affine/core/atoms';
import { useAsyncCallback } from '@affine/core/hooks/affine-async-hooks';
import { mixpanel } from '@affine/core/mixpanel';
import { track } from '@affine/core/mixpanel';
import { DebugLogger } from '@affine/debug';
import { apis } from '@affine/electron-api';
import { WorkspaceFlavour } from '@affine/env/workspace';
Expand Down Expand Up @@ -221,9 +221,7 @@ export const CreateWorkspaceModal = ({

const onConfirmName = useAsyncCallback(
async (name: string, workspaceFlavour: WorkspaceFlavour) => {
mixpanel.track('CreateWorkspace', {
workspaceFlavour,
});
track.$.$.$.createWorkspace(workspaceFlavour);
if (loading) return;
setLoading(true);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Button, IconButton } from '@affine/component/ui/button';
import { Modal, useConfirmModal } from '@affine/component/ui/modal';
import { openSettingModalAtom } from '@affine/core/atoms';
import { useDocCollectionPageTitle } from '@affine/core/hooks/use-block-suite-workspace-page-title';
import { mixpanel } from '@affine/core/mixpanel';
import { track } from '@affine/core/mixpanel';
import { WorkspacePermissionService } from '@affine/core/modules/permissions';
import { WorkspaceQuotaService } from '@affine/core/modules/quota';
import { i18nTime, Trans, useI18n } from '@affine/i18n';
Expand Down Expand Up @@ -108,18 +108,17 @@ const HistoryEditorPreview = ({
mode,
title,
}: HistoryEditorPreviewProps) => {
const onSwitchToPageMode = useCallback(() => {
mixpanel.track('Button', {
resolve: 'HistorySwitchToPageMode',
});
onModeChange('page');
}, [onModeChange]);
const onSwitchToEdgelessMode = useCallback(() => {
mixpanel.track('Button', {
resolve: 'HistorySwitchToEdgelessMode',
});
onModeChange('edgeless');
}, [onModeChange]);
const { onSwitchToPageMode, onSwitchToEdgelessMode } = useMemo(
() => ({
onSwitchToPageMode: () => {
onModeChange('page');
},
onSwitchToEdgelessMode: () => {
onModeChange('edgeless');
},
}),
[onModeChange]
);

const content = useMemo(() => {
return (
Expand All @@ -129,11 +128,15 @@ const HistoryEditorPreview = ({
<PageSwitchItem
data-testid="switch-page-mode-button"
active={mode === 'page'}
data-event-props="$.docHistory.$.switchPageMode"
data-event-args-type="page"
onClick={onSwitchToPageMode}
/>
<EdgelessSwitchItem
data-testid="switch-edgeless-mode-button"
active={mode === 'edgeless'}
data-event-props="$.docHistory.$.switchPageMode"
data-event-args-type="edgeless"
onClick={onSwitchToEdgelessMode}
/>
</StyledEditorModeSwitch>
Expand Down Expand Up @@ -229,9 +232,7 @@ const PlanPrompt = () => {
activeTab: 'plans',
scrollAnchor: 'cloudPricingPlan',
});
mixpanel.track('PlansViewed', {
segment: 'doc history',
});
track.$.docHistory.$.viewPlans();
}, [setSettingModalAtom]);

const t = useI18n();
Expand Down Expand Up @@ -562,9 +563,7 @@ export const GlobalPageHistoryModal = () => {
const workspace = useService(WorkspaceService).workspace;
const handleOpenChange = useCallback(
(open: boolean) => {
mixpanel.track('Button', {
resolve: open ? 'OpenPageHistoryModal' : 'ClosePageHistoryModal',
});
track.$.docHistory.$[open ? 'open' : 'close']();
setState(prev => ({
...prev,
open,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ConfirmModal } from '@affine/component/ui/modal';
import { openQuotaModalAtom, openSettingModalAtom } from '@affine/core/atoms';
import { mixpanel } from '@affine/core/mixpanel';
import { track } from '@affine/core/mixpanel';
import { UserQuotaService } from '@affine/core/modules/cloud';
import { WorkspacePermissionService } from '@affine/core/modules/permissions';
import { WorkspaceQuotaService } from '@affine/core/modules/quota';
Expand Down Expand Up @@ -50,11 +50,7 @@ export const CloudQuotaModal = () => {
scrollAnchor: 'cloudPricingPlan',
});

mixpanel.track('PlansViewed', {
segment: 'payment wall',
category: 'payment wall storage',
});

track.$.paywall.storage.viewPlans();
setOpen(false);
}, [setOpen, setSettingModalAtom]);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Button, ErrorMessage, Skeleton } from '@affine/component';
import { SettingRow } from '@affine/component/setting-components';
import { openSettingModalAtom } from '@affine/core/atoms';
import { mixpanel } from '@affine/core/mixpanel';
import { track } from '@affine/core/mixpanel';
import {
ServerConfigService,
SubscriptionService,
Expand Down Expand Up @@ -47,12 +47,7 @@ export const AIUsagePanel = () => {
open: true,
activeTab: 'billing',
});
mixpanel.track('BillingViewed', {
segment: 'settings panel',
module: 'account usage list',
control: 'change plan button',
type: 'ai subscription',
});
track.$.settingsPanel.accountUsage.changePlan({ type: 'ai' });
}, [setOpenSettingModal]);

if (loading) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
import { Avatar } from '@affine/component/ui/avatar';
import { Button } from '@affine/component/ui/button';
import { useAsyncCallback } from '@affine/core/hooks/affine-async-hooks';
import { mixpanel } from '@affine/core/mixpanel';
import { track } from '@affine/core/mixpanel';
import { useI18n } from '@affine/i18n';
import { ArrowRightSmallIcon, CameraIcon } from '@blocksuite/icons/rc';
import {
Expand Down Expand Up @@ -38,9 +38,7 @@ export const UserAvatar = () => {
const handleUpdateUserAvatar = useAsyncCallback(
async (file: File) => {
try {
mixpanel.track('UploadAvatar', {
userId: account.id,
});
track.$.settingsPanel.accountSettings.uploadAvatar();
await session.uploadAvatar(file);
notify.success({ title: 'Update user avatar success' });
} catch (e) {
Expand All @@ -51,18 +49,16 @@ export const UserAvatar = () => {
});
}
},
[account, session]
[session]
);

const handleRemoveUserAvatar = useAsyncCallback(
async (e: MouseEvent<HTMLButtonElement>) => {
mixpanel.track('RemoveAvatar', {
userId: account.id,
});
track.$.settingsPanel.accountSettings.removeAvatar();
e.stopPropagation();
await session.removeAvatar();
},
[account, session]
[session]
);

return (
Expand Down Expand Up @@ -104,9 +100,7 @@ export const AvatarAndName = () => {
}

try {
mixpanel.track('UpdateUsername', {
userId: account.id,
});
track.$.settingsPanel.accountSettings.updateUserName();
await session.updateLabel(input);
} catch (e) {
notify.error({
Expand Down Expand Up @@ -161,12 +155,7 @@ const StoragePanel = () => {

const setSettingModalAtom = useSetAtom(openSettingModalAtom);
const onUpgrade = useCallback(() => {
mixpanel.track('PlansViewed', {
segment: 'settings panel',
module: 'account usage list',
control: 'cloud storage upgrade button',
type: 'cloud subscription',
});
track.$.settingsPanel.accountUsage.changePlan({ type: 'pro' });
setSettingModalAtom({
open: true,
activeTab: 'plans',
Expand Down
Loading

0 comments on commit da5e9c8

Please sign in to comment.