diff --git a/app.js b/app.js index 7702d4a..f947c3b 100644 --- a/app.js +++ b/app.js @@ -1,8 +1,11 @@ // app.js +const api = require('./utils/api'); + App({ globalData: { userInfo: null, - currentTab: 'index' + currentTab: 'index', + sessionStartTime: null }, // 事件总线,用于页面间通信 @@ -33,15 +36,41 @@ App({ this.globalData.currentTab = tabName; }, + // 记录用户踪迹 + recordUserTrace(action, additionalData = {}) { + const traceData = { + action: action, + timestamp: new Date().toISOString(), + ...additionalData + }; + api.addUserTrace(traceData); + }, + onLaunch() { console.log('App launched'); + // 记录用户进入小程序 + this.recordUserTrace('app_launch'); + this.globalData.sessionStartTime = new Date().toISOString(); }, onShow() { console.log('App shown'); + // 记录用户显示小程序 + this.recordUserTrace('app_show'); + if (!this.globalData.sessionStartTime) { + this.globalData.sessionStartTime = new Date().toISOString(); + } }, onHide() { console.log('App hidden'); + // 记录用户隐藏小程序,包含会话时长 + const sessionEndTime = new Date().toISOString(); + this.recordUserTrace('app_hide', { + sessionStartTime: this.globalData.sessionStartTime, + sessionEndTime: sessionEndTime, + sessionDuration: new Date(sessionEndTime) - new Date(this.globalData.sessionStartTime) + }); + this.globalData.sessionStartTime = null; } }); diff --git a/pages/goods-detail/goods-detail.js b/pages/goods-detail/goods-detail.js index f0da71f..315d4df 100644 --- a/pages/goods-detail/goods-detail.js +++ b/pages/goods-detail/goods-detail.js @@ -1613,6 +1613,15 @@ Page({ return; } + // 记录用户收藏行为 + API.addUserTrace({ + action: 'add_favorite', + productId: productId, + productName: this.data.goodsDetail.name || '' + }).catch(err => { + console.error('记录收藏踪迹失败:', err); + }); + wx.showLoading({ title: '正在收藏...' }); // 调用API添加收藏 @@ -1673,6 +1682,15 @@ Page({ return; } + // 记录用户取消收藏行为 + API.addUserTrace({ + action: 'cancel_favorite', + productId: productId, + productName: this.data.goodsDetail.name || '' + }).catch(err => { + console.error('记录取消收藏踪迹失败:', err); + }); + wx.showLoading({ title: '正在取消收藏...' }); // 调用API取消收藏 diff --git a/pages/index/index.js b/pages/index/index.js index f306c42..6136f5f 100644 --- a/pages/index/index.js +++ b/pages/index/index.js @@ -1980,6 +1980,15 @@ Page({ console.log('searchGoods - 开始搜索,关键词:', this.data.searchKeyword); console.log('searchGoods - 本地已有商品数量:', this.data.goods.length); + + // 记录用户搜索行为 + API.addUserTrace({ + action: 'search', + keyword: this.data.searchKeyword, + region: this.data.selectedRegion + }).catch(err => { + console.error('记录搜索踪迹失败:', err); + }); // 先对本地已加载的商品进行过滤 const filteredGoods = this.applyFilters(this.data.goods, true); diff --git a/project.config.json b/project.config.json index 3404946..d3e2757 100644 --- a/project.config.json +++ b/project.config.json @@ -18,6 +18,7 @@ "http://localhost:3000", "http://8.137.125.67:3000", "http://localhost:3001", + "http://localhost:3003", "https://youniao.icu" ], "compileWorklet": false, diff --git a/project.private.config.json b/project.private.config.json index 67dfd8e..f4f0e67 100644 --- a/project.private.config.json +++ b/project.private.config.json @@ -1,6 +1,6 @@ { "libVersion": "3.10.3", - "projectname": "Mini-Program", + "projectname": "xcx22", "setting": { "urlCheck": false, "coverView": true,