feat:2.5.0初始化专注启蒙项目
This commit is contained in:
@@ -123,8 +123,7 @@ class Tracker {
|
||||
try {
|
||||
const params = this.getCommonEventParams('share_click', pageName);
|
||||
|
||||
this.printLog('分享事件', params);
|
||||
wx.reportEvent('share_click', params);
|
||||
this.sendEvent('share_click', params);
|
||||
} catch (error) {
|
||||
console.error('上报分享事件失败:', error);
|
||||
}
|
||||
@@ -141,12 +140,35 @@ class Tracker {
|
||||
...(mode && { mode }),
|
||||
});
|
||||
|
||||
this.printLog('下载事件', params);
|
||||
wx.reportEvent('download', params);
|
||||
this.sendEvent('download', params);
|
||||
} catch (error) {
|
||||
console.error('上报下载事件失败:', error);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送事件(仅在线上环境上报)
|
||||
* @param eventName 事件名称
|
||||
* @param params 事件参数
|
||||
*/
|
||||
sendEvent(eventName: string, params: Record<string, any>): void {
|
||||
try {
|
||||
// 获取当前环境,只在 release 环境下上报
|
||||
const accountInfo = wx.getAccountInfoSync();
|
||||
const env = accountInfo.miniProgram.envVersion || 'release';
|
||||
|
||||
if (env === 'release') {
|
||||
this.printLog(`[${env}] 事件上报`, { eventName, params });
|
||||
wx.reportEvent(eventName, params);
|
||||
} else {
|
||||
// 非线上环境,只打印日志,不上报
|
||||
this.printLog(`[${env}] 事件上报已跳过`, { eventName, params });
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('获取环境信息失败:', error);
|
||||
// 如果获取环境信息失败,为了安全起见不上报
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 导出 Tracker 单例实例
|
||||
|
||||
Reference in New Issue
Block a user