From b0b42e9d3d363e6743701ab289eb1c34a4822e8d Mon Sep 17 00:00:00 2001 From: zdl <3489966805@qq.com> Date: Fri, 7 Nov 2025 15:10:27 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0post=20postHog?= =?UTF-8?q?=E5=8A=A0=E4=B8=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/views/Community/components/HotEvents.js | 13 ++- .../Community/components/HotEventsSection.js | 9 +- .../Community/components/UnifiedSearchBox.js | 88 ++++++++++++++++++- src/views/Community/index.js | 13 ++- 4 files changed, 118 insertions(+), 5 deletions(-) diff --git a/src/views/Community/components/HotEvents.js b/src/views/Community/components/HotEvents.js index 39077442..97412830 100644 --- a/src/views/Community/components/HotEvents.js +++ b/src/views/Community/components/HotEvents.js @@ -35,7 +35,7 @@ const CustomArrow = ({ className, style, onClick, direction }) => { ); }; -const HotEvents = ({ events, onPageChange }) => { +const HotEvents = ({ events, onPageChange, onEventClick }) => { const [currentSlide, setCurrentSlide] = useState(0); const { isOpen: isModalOpen, onOpen: onModalOpen, onClose: onModalClose } = useDisclosure(); const [modalEvent, setModalEvent] = useState(null); @@ -67,6 +67,17 @@ const HotEvents = ({ events, onPageChange }) => { }; const handleCardClick = (event) => { + // 🎯 追踪热点事件点击 + if (onEventClick) { + onEventClick({ + eventId: event.id, + eventTitle: event.title, + importance: event.importance, + source: 'hot_events_section', + timestamp: new Date().toISOString(), + }); + } + setModalEvent(event); onModalOpen(); }; diff --git a/src/views/Community/components/HotEventsSection.js b/src/views/Community/components/HotEventsSection.js index 79ed0278..f93851e4 100644 --- a/src/views/Community/components/HotEventsSection.js +++ b/src/views/Community/components/HotEventsSection.js @@ -16,8 +16,9 @@ import HotEvents from './HotEvents'; /** * 热点事件区域组件 * @param {Array} events - 热点事件列表 + * @param {Function} onEventClick - 事件点击追踪回调 */ -const HotEventsSection = ({ events }) => { +const HotEventsSection = ({ events, onEventClick }) => { const cardBg = useColorModeValue('white', 'gray.800'); const [currentPage, setCurrentPage] = useState(1); const [totalPages, setTotalPages] = useState(1); @@ -55,7 +56,11 @@ const HotEventsSection = ({ events }) => { )} - + ); diff --git a/src/views/Community/components/UnifiedSearchBox.js b/src/views/Community/components/UnifiedSearchBox.js index 80b7ac26..a514ba2d 100644 --- a/src/views/Community/components/UnifiedSearchBox.js +++ b/src/views/Community/components/UnifiedSearchBox.js @@ -24,7 +24,8 @@ const UnifiedSearchBox = ({ popularKeywords = [], filters = {}, mode, // 显示模式(如:vertical, horizontal 等) - pageSize // 每页显示数量 + pageSize, // 每页显示数量 + trackingFunctions = {} // PostHog 追踪函数集合 }) => { // 其他状态 @@ -259,6 +260,16 @@ const UnifiedSearchBox = ({ name: stockInfo.name }); + // 🎯 追踪股票点击 + if (trackingFunctions.trackRelatedStockClicked) { + trackingFunctions.trackRelatedStockClicked({ + stockCode: stockInfo.code, + stockName: stockInfo.name, + source: 'search_box_autocomplete', + timestamp: new Date().toISOString(), + }); + } + // 更新输入框显示 setInputValue(`${stockInfo.code} ${stockInfo.name}`); @@ -289,6 +300,15 @@ const UnifiedSearchBox = ({ // 转换为逗号分隔字符串传给后端(空数组表示"全部") const importanceStr = value.length === 0 ? 'all' : value.join(','); + // 🎯 追踪筛选操作 + if (trackingFunctions.trackNewsFilterApplied) { + trackingFunctions.trackNewsFilterApplied({ + filterType: 'importance', + filterValue: importanceStr, + timestamp: new Date().toISOString(), + }); + } + // 立即触发搜索 const params = buildFilterParams({ importance: importanceStr }); logger.debug('UnifiedSearchBox', '重要性改变,立即触发搜索', params); @@ -309,6 +329,15 @@ const UnifiedSearchBox = ({ debouncedSearchRef.current.cancel(); } + // 🎯 追踪排序操作 + if (trackingFunctions.trackNewsSorted) { + trackingFunctions.trackNewsSorted({ + sortBy: value, + previousSortBy: sort, + timestamp: new Date().toISOString(), + }); + } + // 立即触发搜索 const params = buildFilterParams({ sort: value }); logger.debug('UnifiedSearchBox', '排序改变,立即触发搜索', params); @@ -328,6 +357,15 @@ const UnifiedSearchBox = ({ debouncedSearchRef.current.cancel(); } + // 🎯 追踪行业筛选 + if (trackingFunctions.trackNewsFilterApplied) { + trackingFunctions.trackNewsFilterApplied({ + filterType: 'industry', + filterValue: value?.[value.length - 1] || '', + timestamp: new Date().toISOString(), + }); + } + // 立即触发搜索 const params = buildFilterParams({ industry_code: value?.[value.length - 1] || '' @@ -347,6 +385,15 @@ const UnifiedSearchBox = ({ debouncedSearchRef.current.cancel(); } + // 🎯 追踪热门关键词点击 + if (trackingFunctions.trackNewsSearched) { + trackingFunctions.trackNewsSearched({ + searchQuery: keyword, + searchType: 'popular_keyword', + timestamp: new Date().toISOString(), + }); + } + const params = buildFilterParams({ q: keyword, industry_code: '' @@ -363,6 +410,16 @@ const UnifiedSearchBox = ({ if (!timeConfig) { // 清空筛选 setTradingTimeRange(null); + + // 🎯 追踪时间筛选清空 + if (trackingFunctions.trackNewsFilterApplied) { + trackingFunctions.trackNewsFilterApplied({ + filterType: 'time_range', + filterValue: 'cleared', + timestamp: new Date().toISOString(), + }); + } + const params = buildFilterParams({ start_date: '', end_date: '', @@ -389,6 +446,16 @@ const UnifiedSearchBox = ({ setTradingTimeRange({ ...params, label, key }); + // 🎯 追踪时间筛选 + if (trackingFunctions.trackNewsFilterApplied) { + trackingFunctions.trackNewsFilterApplied({ + filterType: 'time_range', + filterValue: label, + timeRangeType: type, + timestamp: new Date().toISOString(), + }); + } + // 立即触发搜索 const searchParams = buildFilterParams({ ...params, mode }); logger.debug('UnifiedSearchBox', '交易时段筛选变化,立即触发搜索', { @@ -411,6 +478,16 @@ const UnifiedSearchBox = ({ industry_code: '' }); + // 🎯 追踪搜索操作 + if (trackingFunctions.trackNewsSearched && inputValue) { + trackingFunctions.trackNewsSearched({ + searchQuery: inputValue, + searchType: 'main_search', + filters: params, + timestamp: new Date().toISOString(), + }); + } + logger.debug('UnifiedSearchBox', '主搜索触发', { inputValue, params @@ -513,6 +590,15 @@ const UnifiedSearchBox = ({ setImportance([]); // 改为空数组 setTradingTimeRange(null); // 清空交易时段筛选 + // 🎯 追踪筛选重置 + if (trackingFunctions.trackNewsFilterApplied) { + trackingFunctions.trackNewsFilterApplied({ + filterType: 'reset', + filterValue: 'all_filters_cleared', + timestamp: new Date().toISOString(), + }); + } + // 输出重置后的完整参数 const resetParams = { q: '', diff --git a/src/views/Community/index.js b/src/views/Community/index.js index c85df408..8f522468 100644 --- a/src/views/Community/index.js +++ b/src/views/Community/index.js @@ -105,7 +105,10 @@ const Community = () => { {/* 主内容区域 */} {/* 热点事件区域 */} - + {/* 实时要闻·动态追踪 - 横向滚动 */} { onSearch={updateFilters} onEventClick={handleEventClick} onViewDetail={handleViewDetail} + trackingFunctions={{ + trackNewsArticleClicked: communityEvents.trackNewsArticleClicked, + trackNewsDetailOpened: communityEvents.trackNewsDetailOpened, + trackNewsFilterApplied: communityEvents.trackNewsFilterApplied, + trackNewsSorted: communityEvents.trackNewsSorted, + trackNewsSearched: communityEvents.trackNewsSearched, + trackRelatedStockClicked: communityEvents.trackRelatedStockClicked, + }} />