Skip to content

Commit

Permalink
feat(core): add track events for cmdk
Browse files Browse the repository at this point in the history
  • Loading branch information
JimmFly committed Aug 1, 2024
1 parent 6b7eb92 commit a10f0f2
Show file tree
Hide file tree
Showing 13 changed files with 327 additions and 13 deletions.
27 changes: 27 additions & 0 deletions packages/frontend/core/src/commands/affine-creation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,19 @@ import type { createStore } from 'jotai';

import { openCreateWorkspaceModalAtom } from '../atoms';
import type { usePageHelper } from '../components/blocksuite/block-suite-page-list/utils';
import { mixpanel } from '../mixpanel';
import { registerAffineCommand } from './registry';

export function registerAffineCreationCommands({
store,
pageHelper,
t,
moduleName,
}: {
t: ReturnType<typeof useI18n>;
store: ReturnType<typeof createStore>;
pageHelper: ReturnType<typeof usePageHelper>;
moduleName: string;
}) {
const unsubs: Array<() => void> = [];
unsubs.push(
Expand All @@ -29,6 +32,12 @@ export function registerAffineCreationCommands({
}
: undefined,
run() {
mixpanel.track('QuickSearchOptionClick', {
page: moduleName,
segment: moduleName,
module: moduleName,
control: 'new page',
});
pageHelper.createPage();
},
})
Expand All @@ -41,6 +50,12 @@ export function registerAffineCreationCommands({
icon: <PlusIcon />,
label: t['com.affine.cmdk.affine.new-edgeless-page'](),
run() {
mixpanel.track('QuickSearchOptionClick', {
page: moduleName,
segment: moduleName,
module: moduleName,
control: 'new edgeless',
});
pageHelper.createEdgeless();
},
})
Expand All @@ -53,6 +68,12 @@ export function registerAffineCreationCommands({
icon: <PlusIcon />,
label: t['com.affine.cmdk.affine.new-workspace'](),
run() {
mixpanel.track('QuickSearchOptionClick', {
page: moduleName,
segment: moduleName,
module: moduleName,
control: 'new workspace',
});
store.set(openCreateWorkspaceModalAtom, 'new');
},
})
Expand All @@ -67,6 +88,12 @@ export function registerAffineCreationCommands({
return environment.isDesktop;
},
run() {
mixpanel.track('QuickSearchOptionClick', {
page: moduleName,
segment: moduleName,
module: moduleName,
control: 'import workspace',
});
store.set(openCreateWorkspaceModalAtom, 'add');
},
})
Expand Down
15 changes: 15 additions & 0 deletions packages/frontend/core/src/commands/affine-help.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,18 @@ import { ContactWithUsIcon, NewIcon } from '@blocksuite/icons/rc';
import type { createStore } from 'jotai';

import { openSettingModalAtom } from '../atoms';
import { mixpanel } from '../mixpanel';
import { popupWindow } from '../utils';
import { registerAffineCommand } from './registry';

export function registerAffineHelpCommands({
t,
store,
moduleName,
}: {
t: ReturnType<typeof useI18n>;
store: ReturnType<typeof createStore>;
moduleName: string;
}) {
const unsubs: Array<() => void> = [];
unsubs.push(
Expand All @@ -21,6 +24,12 @@ export function registerAffineHelpCommands({
icon: <NewIcon />,
label: t['com.affine.cmdk.affine.whats-new'](),
run() {
mixpanel.track('QuickSearchOptionClick', {
page: moduleName,
segment: moduleName,
module: moduleName,
control: 'Whats new',
});
popupWindow(runtimeConfig.changelogUrl);
},
})
Expand All @@ -32,6 +41,12 @@ export function registerAffineHelpCommands({
icon: <ContactWithUsIcon />,
label: t['com.affine.cmdk.affine.contact-us'](),
run() {
mixpanel.track('QuickSearchOptionClick', {
page: moduleName,
segment: moduleName,
module: moduleName,
control: 'contact us',
});
store.set(openSettingModalAtom, {
open: true,
activeTab: 'about',
Expand Down
11 changes: 11 additions & 0 deletions packages/frontend/core/src/commands/affine-layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,17 @@ import { SidebarIcon } from '@blocksuite/icons/rc';
import type { createStore } from 'jotai';

import { appSidebarOpenAtom } from '../components/app-sidebar';
import { mixpanel } from '../mixpanel';
import { registerAffineCommand } from './registry';

export function registerAffineLayoutCommands({
t,
store,
moduleName,
}: {
t: ReturnType<typeof useI18n>;
store: ReturnType<typeof createStore>;
moduleName: string;
}) {
const unsubs: Array<() => void> = [];
unsubs.push(
Expand All @@ -27,6 +30,14 @@ export function registerAffineLayoutCommands({
binding: '$mod+/',
},
run() {
mixpanel.track('QuickSearchOptionClick', {
page: moduleName,
segment: moduleName,
module: moduleName,
control: store.get(appSidebarOpenAtom)
? 'collapse left sidebar'
: 'expand left sidebar',
});
store.set(appSidebarOpenAtom, v => !v);
},
})
Expand Down
44 changes: 44 additions & 0 deletions packages/frontend/core/src/commands/affine-navigation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@ export function registerAffineNavigationCommands({
store,
docCollection,
navigationHelper,
moduleName,
}: {
t: ReturnType<typeof useI18n>;
store: ReturnType<typeof createStore>;
navigationHelper: ReturnType<typeof useNavigateHelper>;
docCollection: DocCollection;
moduleName: string;
}) {
const unsubs: Array<() => void> = [];
unsubs.push(
Expand All @@ -28,6 +30,12 @@ export function registerAffineNavigationCommands({
icon: <ArrowRightBigIcon />,
label: t['com.affine.cmdk.affine.navigation.goto-all-pages'](),
run() {
mixpanel.track('QuickSearchOptionClick', {
page: moduleName,
segment: moduleName,
module: moduleName,
control: 'go to all docs',
});
navigationHelper.jumpToSubPath(docCollection.id, WorkspaceSubPath.ALL);
},
})
Expand All @@ -40,6 +48,12 @@ export function registerAffineNavigationCommands({
icon: <ArrowRightBigIcon />,
label: 'Go to Collection List',
run() {
mixpanel.track('QuickSearchOptionClick', {
page: moduleName,
segment: moduleName,
module: moduleName,
control: 'go to collection list',
});
navigationHelper.jumpToCollections(docCollection.id);
},
})
Expand All @@ -52,6 +66,12 @@ export function registerAffineNavigationCommands({
icon: <ArrowRightBigIcon />,
label: 'Go to Tag List',
run() {
mixpanel.track('QuickSearchOptionClick', {
page: moduleName,
segment: moduleName,
module: moduleName,
control: 'go to tag list',
});
navigationHelper.jumpToTags(docCollection.id);
},
})
Expand All @@ -64,6 +84,12 @@ export function registerAffineNavigationCommands({
icon: <ArrowRightBigIcon />,
label: t['com.affine.cmdk.affine.navigation.goto-workspace'](),
run() {
mixpanel.track('QuickSearchOptionClick', {
page: moduleName,
segment: moduleName,
module: moduleName,
control: 'go to workspace',
});
store.set(openWorkspaceListModalAtom, true);
},
})
Expand All @@ -81,6 +107,12 @@ export function registerAffineNavigationCommands({
// page:
segment: 'cmdk',
});
mixpanel.track('QuickSearchOptionClick', {
page: moduleName,
segment: moduleName,
module: moduleName,
control: 'go to settings',
});
store.set(openSettingModalAtom, s => ({
activeTab: 'appearance',
open: !s.open,
Expand All @@ -100,6 +132,12 @@ export function registerAffineNavigationCommands({
// page:
segment: 'cmdk',
});
mixpanel.track('QuickSearchOptionClick', {
page: moduleName,
segment: moduleName,
module: moduleName,
control: 'go to account settings',
});
store.set(openSettingModalAtom, s => ({
activeTab: 'account',
open: !s.open,
Expand All @@ -115,6 +153,12 @@ export function registerAffineNavigationCommands({
icon: <ArrowRightBigIcon />,
label: t['com.affine.cmdk.affine.navigation.goto-trash'](),
run() {
mixpanel.track('QuickSearchOptionClick', {
page: moduleName,
segment: moduleName,
module: moduleName,
control: 'go to trash',
});
navigationHelper.jumpToSubPath(
docCollection.id,
WorkspaceSubPath.TRASH
Expand Down
Loading

0 comments on commit a10f0f2

Please sign in to comment.