feat: 集成导航上报

This commit is contained in:
zdl
2025-10-29 12:52:34 +08:00
parent 02cd234def
commit 173b13bc70

View File

@@ -51,6 +51,7 @@ import SubscriptionButton from '../Subscription/SubscriptionButton';
import SubscriptionModal from '../Subscription/SubscriptionModal';
import { CrownIcon, TooltipContent } from '../Subscription/CrownTooltip';
import InvestmentCalendar from '../../views/Community/components/InvestmentCalendar';
import { useNavigationEvents } from '../../hooks/useNavigationEvents';
/** 二级导航栏组件 - 显示当前一级菜单下的所有二级菜单项 */
const SecondaryNav = ({ showCompletenessAlert }) => {
@@ -61,6 +62,9 @@ const SecondaryNav = ({ showCompletenessAlert }) => {
// ⚠️ 必须在组件顶层调用所有Hooks不能在JSX中调用
const borderColorValue = useColorModeValue('gray.200', 'gray.600');
// 🎯 初始化导航埋点Hook
const navEvents = useNavigationEvents({ component: 'secondary_nav' });
// 定义二级导航结构
const secondaryNavConfig = {
'/community': {
@@ -162,7 +166,11 @@ const SecondaryNav = ({ showCompletenessAlert }) => {
) : (
<Button
key={index}
onClick={() => navigate(item.path)}
onClick={() => {
// 🎯 追踪侧边栏菜单点击
navEvents.trackSidebarMenuClicked(item.label, item.path, 2, false);
navigate(item.path);
}}
size="sm"
variant="ghost"
bg={isActive ? 'blue.50' : 'transparent'}
@@ -313,6 +321,9 @@ const NavItems = ({ isAuthenticated, user }) => {
// ⚠️ 必须在组件顶层调用所有Hooks不能在JSX中调用
const contactTextColor = useColorModeValue('gray.500', 'gray.300');
// 🎯 初始化导航埋点Hook
const navEvents = useNavigationEvents({ component: 'top_nav' });
// 辅助函数:判断导航项是否激活
const isActive = useCallback((paths) => {
return paths.some(path => location.pathname.includes(path));
@@ -337,7 +348,11 @@ const NavItems = ({ isAuthenticated, user }) => {
</MenuButton>
<MenuList minW="260px" p={2}>
<MenuItem
onClick={() => navigate('/community')}
onClick={() => {
// 🎯 追踪菜单项点击
navEvents.trackMenuItemClicked('事件中心', 'dropdown', '/community');
navigate('/community');
}}
borderRadius="md"
bg={location.pathname.includes('/community') ? 'blue.50' : 'transparent'}
borderLeft={location.pathname.includes('/community') ? '3px solid' : 'none'}
@@ -353,7 +368,11 @@ const NavItems = ({ isAuthenticated, user }) => {
</Flex>
</MenuItem>
<MenuItem
onClick={() => navigate('/concepts')}
onClick={() => {
// 🎯 追踪菜单项点击
navEvents.trackMenuItemClicked('概念中心', 'dropdown', '/concepts');
navigate('/concepts');
}}
borderRadius="md"
bg={location.pathname.includes('/concepts') ? 'blue.50' : 'transparent'}
borderLeft={location.pathname.includes('/concepts') ? '3px solid' : 'none'}
@@ -489,6 +508,9 @@ export default function HomeNavbar() {
const brandHover = useColorModeValue('blue.600', 'blue.300');
const toast = useToast();
// 🎯 初始化导航埋点Hook
const navEvents = useNavigationEvents({ component: 'main_navbar' });
// ⚡ 提取 userId 为独立变量,避免 user 对象引用变化导致无限循环
const userId = user?.id;
const prevUserIdRef = React.useRef(userId);
@@ -882,7 +904,11 @@ export default function HomeNavbar() {
color={brandText}
cursor="pointer"
_hover={{ color: brandHover }}
onClick={() => navigate('/home')}
onClick={() => {
// 🎯 追踪Logo点击
navEvents.trackLogoClicked();
navigate('/home');
}}
style={{ minWidth: isMobile ? '100px' : '140px' }}
noOfLines={1}
>
@@ -912,7 +938,13 @@ export default function HomeNavbar() {
<IconButton
aria-label="切换主题"
icon={colorMode === 'light' ? <MoonIcon /> : <SunIcon />}
onClick={toggleColorMode}
onClick={() => {
// 🎯 追踪主题切换
const fromTheme = colorMode;
const toTheme = colorMode === 'light' ? 'dark' : 'light';
navEvents.trackThemeChanged(fromTheme, toTheme);
toggleColorMode();
}}
variant="ghost"
size="sm"
minW={{ base: '36px', md: '40px' }}