feat(core): all docs tracks (#12556)

<!-- This is an auto-generated comment: release notes by coderabbit.ai -->
## Summary by CodeRabbit

- **New Features**
  - Added enhanced tracking for user interactions across document lists, navigation, display menus, quick actions, and collection operations.
  - User actions such as opening documents, editing collections, toggling favorites, changing view modes, and navigating collections are now logged for analytics.

- **Chores**
  - Expanded internal event tracking capabilities to support more detailed analytics on user interactions throughout the interface.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
EYHN
2025-05-27 08:17:14 +00:00
parent 8d3b20ecc7
commit 5033142a77
16 changed files with 110 additions and 16 deletions
@@ -2,6 +2,7 @@ import { Divider, MenuItem } from '@affine/component';
import type { GroupByParams } from '@affine/core/modules/collection-rules/types';
import { WorkspacePropertyService } from '@affine/core/modules/workspace-property';
import { useI18n } from '@affine/i18n';
import track from '@affine/track';
import { DoneIcon } from '@blocksuite/icons/rc';
import { useLiveData, useService } from '@toeverything/infra';
import { cssVarV2 } from '@toeverything/theme/v2';
@@ -128,6 +129,10 @@ const GroupByListItem = ({
<MenuItem
onClick={e => {
e.preventDefault();
track.allDocs.header.displayMenu.editDisplayMenu({
control: 'groupBy',
type: property.systemProperty?.type ?? 'custom-property',
});
if (value) {
onChange?.(value);
}
@@ -2,6 +2,7 @@ import { MenuItem } from '@affine/component';
import type { OrderByParams } from '@affine/core/modules/collection-rules/types';
import { WorkspacePropertyService } from '@affine/core/modules/workspace-property';
import { useI18n } from '@affine/i18n';
import track from '@affine/track';
import { SortDownIcon, SortUpIcon } from '@blocksuite/icons/rc';
import { useLiveData, useService } from '@toeverything/infra';
import { cssVarV2 } from '@toeverything/theme/v2';
@@ -125,6 +126,10 @@ const OrderByListItem = ({
<MenuItem
onClick={e => {
e.preventDefault();
track.allDocs.header.displayMenu.editDisplayMenu({
control: 'orderBy',
type: property.systemProperty?.type ?? 'custom-property',
});
if (value) {
onChange?.(value);
}
@@ -1,6 +1,7 @@
import { Button, Divider } from '@affine/component';
import { WorkspacePropertyService } from '@affine/core/modules/workspace-property';
import { useI18n } from '@affine/i18n';
import track from '@affine/track';
import { useLiveData, useService } from '@toeverything/infra';
import { useCallback, useMemo } from 'react';
@@ -160,7 +161,13 @@ const PropertyRenderer = ({
<Button
key={key}
data-show={isActive}
onClick={() => handlePropertyClick(key)}
onClick={() => {
track.allDocs.header.displayMenu.editDisplayMenu({
control: 'displayProperties',
type: systemProperty?.type ?? 'custom-property',
});
handlePropertyClick(key);
}}
className={styles.property}
data-key={key}
>
@@ -1,5 +1,6 @@
import { Checkbox, MenuItem, MenuSub } from '@affine/component';
import { useI18n } from '@affine/i18n';
import track from '@affine/track';
import { useCallback } from 'react';
import { type QuickAction, quickActions } from '../quick-actions.constants';
@@ -27,6 +28,10 @@ export const QuickActionsConfig = ({
action={action}
active={displayPreference[`${action.key}`] ?? false}
onClick={() => {
track.allDocs.header.displayMenu.editDisplayMenu({
control: 'quickActions',
type: action.key,
});
onDisplayPreferenceChange({
...displayPreference,
[action.key]: !displayPreference[action.key],
@@ -1,4 +1,5 @@
import { RadioGroup, type RadioItem } from '@affine/component';
import track from '@affine/track';
import { useCallback } from 'react';
import {
@@ -34,6 +35,9 @@ export const ViewToggle = ({
}) => {
const handleViewChange = useCallback(
(view: DocListItemView) => {
track.allDocs.header.viewMode.editDisplayMenu({
type: view,
});
onViewChange(view);
},
[onViewChange]
@@ -10,6 +10,7 @@ import { DocDisplayMetaService } from '@affine/core/modules/doc-display-meta';
import { WorkbenchLink } from '@affine/core/modules/workbench';
import type { AffineDNDData } from '@affine/core/types/dnd';
import { useI18n } from '@affine/i18n';
import track from '@affine/track';
import {
AutoTidyUpIcon,
PropertyIcon,
@@ -139,6 +140,7 @@ export const DocListItem = ({ ...props }: DocListItemProps) => {
return;
} else {
// as link
track.allDocs.list.doc.openDoc();
return;
}
}
@@ -42,6 +42,7 @@ const ToggleFavorite = ({ docId }: DocOperationProps) => {
const toggleFavorite = useCallback(() => {
favAdapter.toggle(docId, 'doc');
track.allDocs.list.docMenu.toggleFavorite();
}, [docId, favAdapter]);
return (
@@ -66,7 +67,7 @@ const DocInfo = ({ docId }: DocOperationProps) => {
const onOpenInfoModal = useCallback(() => {
if (docId) {
track.$.docInfoPanel.$.open();
track.allDocs.list.docMenu.openDocInfo();
workspaceDialogService.open('doc-info', { docId });
}
}, [docId, workspaceDialogService]);
@@ -85,6 +86,8 @@ const NewTab = ({ docId }: DocOperationProps) => {
const t = useI18n();
const workbench = useService(WorkbenchService).workbench;
const onOpenInNewTab = useCallback(() => {
track.allDocs.list.doc.openDoc();
track.allDocs.list.docMenu.openInNewTab();
workbench.openDoc(docId, { at: 'new-tab' });
}, [docId, workbench]);
@@ -103,6 +106,7 @@ const SplitView = ({ docId }: DocOperationProps) => {
const workbench = useService(WorkbenchService).workbench;
const onOpenInSplitView = useCallback(() => {
track.allDocs.list.doc.openDoc();
track.allDocs.list.docMenu.openInSplitView();
workbench.openDoc(docId, { at: 'tail' });
}, [docId, workbench]);
@@ -45,6 +45,7 @@ export const QuickFavorite = memo(function QuickFavorite({
onClick?.(e);
e.stopPropagation();
e.preventDefault();
track.allDocs.list.docMenu.toggleFavorite();
favAdapter.toggle(doc.id, 'doc');
},
[doc.id, favAdapter, onClick]
@@ -77,6 +78,8 @@ export const QuickTab = memo(function QuickTab({
onClick?.(e);
e.stopPropagation();
e.preventDefault();
track.allDocs.list.doc.openDoc();
track.allDocs.list.docMenu.openInNewTab();
workbench.openDoc(doc.id, { at: 'new-tab' });
},
[doc.id, onClick, workbench]
@@ -109,6 +112,7 @@ export const QuickSplit = memo(function QuickSplit({
onClick?.(e);
e.stopPropagation();
e.preventDefault();
track.allDocs.list.doc.openDoc();
track.allDocs.list.docMenu.openInSplitView();
workbench.openDoc(doc.id, { at: 'tail' });
},
@@ -1,5 +1,6 @@
import { WorkbenchLink } from '@affine/core/modules/workbench';
import { useI18n } from '@affine/i18n';
import track from '@affine/track';
import * as styles from './navigation.css';
@@ -37,6 +38,11 @@ export const ExplorerNavigation = ({ active }: { active: NavigationKey }) => {
data-testid={item.testId}
data-active={active === item.value}
to={item.to}
onClick={() => {
track.allDocs.header.navigation.navigateAllDocsRouter({
control: item.value,
});
}}
className={styles.item}
>
{t[item.label]()}
@@ -4,6 +4,7 @@ import { WorkspaceDialogService } from '@affine/core/modules/dialogs';
import { CompatibleFavoriteItemsAdapter } from '@affine/core/modules/favorite';
import { WorkbenchService } from '@affine/core/modules/workbench';
import { useI18n } from '@affine/i18n';
import track from '@affine/track';
import {
DeleteIcon,
EditIcon,
@@ -71,6 +72,7 @@ export const CollectionOperations = ({
}, [openRenameModal, openPromptModal, t, service, collection]);
const showEdit = useCallback(() => {
track.collection.collection.$.editCollection();
workspaceDialogService.open('collection-editor', {
collectionId: collection.id,
});