feat: 添加post postHog加上

This commit is contained in:
zdl
2025-11-07 15:10:27 +08:00
parent 09f15d2e03
commit b0b42e9d3d
4 changed files with 118 additions and 5 deletions

View File

@@ -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();
};

View File

@@ -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 }) => {
)}
</CardHeader>
<CardBody py={0} px={4}>
<HotEvents events={events} onPageChange={handlePageChange} />
<HotEvents
events={events}
onPageChange={handlePageChange}
onEventClick={onEventClick}
/>
</CardBody>
</Card>
);

View File

@@ -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: '',

View File

@@ -105,7 +105,10 @@ const Community = () => {
{/* 主内容区域 */}
<Container ref={containerRef} maxW="1600px" pt={6} pb={8}>
{/* 热点事件区域 */}
<HotEventsSection events={hotEvents} />
<HotEventsSection
events={hotEvents}
onEventClick={communityEvents.trackNewsArticleClicked}
/>
{/* 实时要闻·动态追踪 - 横向滚动 */}
<DynamicNewsCard
@@ -116,6 +119,14 @@ 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,
}}
/>
</Container>
</Box>