diff --git a/packages/uni-stat/dist/uni-cloud-stat.cjs.js b/packages/uni-stat/dist/uni-cloud-stat.cjs.js index 0cdd2579549c0119327e4369cfb2f611ca0a44f1..23e8c4a6127ca6a876597550c38968b0bebeac77 100644 --- a/packages/uni-stat/dist/uni-cloud-stat.cjs.js +++ b/packages/uni-stat/dist/uni-cloud-stat.cjs.js @@ -490,6 +490,9 @@ const log = (data) => { case '31': msg_type = '应用错误'; break + case '101': + msg_type = 'PUSH'; + break } if (msg_type) { console.log(`=== 统计数据采集:${msg_type} ===`); @@ -914,8 +917,9 @@ class Report { /** * 发送请求,应用维度上报 * @param {Object} options 页面信息 + * @param {Boolean} type 是否立即上报 */ - sendReportRequest(options) { + sendReportRequest(options, type) { this._navigationBarTitle.lt = '1'; this._navigationBarTitle.config = get_page_name(options.path); let is_opt = options.query && JSON.stringify(options.query) !== '{}'; @@ -932,9 +936,9 @@ class Report { cst: options.cst || 1, }); if (get_platform_name() === 'n') { - this.getProperty(); + this.getProperty(type); } else { - this.getNetworkInfo(); + this.getNetworkInfo(type); } } @@ -1015,24 +1019,59 @@ class Report { this.request(options); } + sendPushRequest(options, cid) { + let time = get_time(); + + const statData = { + lt: '101', + cid: cid, + t: time, + ut: this.statData.ut, + }; + + // debug 打印打点信息 + if (is_debug) { + log(statData); + } + + const stat_data = handle_data({ + 101: [statData], + }); + let optionsData = { + usv: STAT_VERSION, //统计 SDK 版本号 + t: time, //发送请求时的时间戮 + requests: stat_data, + }; + + // XXX 安卓需要延迟上报 ,否则会有未知错误,需要验证处理 + if (get_platform_name() === 'n' && this.statData.p === 'a') { + setTimeout(() => { + this.sendRequest(optionsData); + }, 200); + return + } + + this.sendRequest(optionsData); + } + /** * 获取wgt资源版本 */ - getProperty() { + getProperty(type) { plus.runtime.getProperty(plus.runtime.appid, (wgtinfo) => { this.statData.v = wgtinfo.version || ''; - this.getNetworkInfo(); + this.getNetworkInfo(type); }); } /** * 获取网络信息 */ - getNetworkInfo() { + getNetworkInfo(type) { uni.getNetworkType({ success: (result) => { this.statData.net = result.networkType; - this.getLocation(); + this.getLocation(type); }, }); } @@ -1040,7 +1079,7 @@ class Report { /** * 获取位置信息 */ - getLocation() { + getLocation(type) { if (stat_config.getLocation) { uni.getLocation({ type: 'wgs84', @@ -1054,13 +1093,13 @@ class Report { this.statData.lat = result.latitude; this.statData.lng = result.longitude; - this.request(this.statData); + this.request(this.statData, type); }, }); } else { this.statData.lat = 0; this.statData.lng = 0; - this.request(this.statData); + this.request(this.statData, type); } } @@ -1205,9 +1244,9 @@ class Stat extends Report { let spaceData = { provider: space.provider, spaceId: space.spaceId, - clientSecret: space.clientSecret + clientSecret: space.clientSecret, }; - if(space.endpoint){ + if (space.endpoint) { spaceData.endpoint = space.endpoint; } uni.__stat_uniCloud_space = uniCloud.init(spaceData); @@ -1216,7 +1255,9 @@ class Stat extends Report { // uni.__stat_uniCloud_space.config.spaceId // ) } else { - console.error('当前尚未关联统计服务空间,请先在manifest.json中配置服务空间!'); + console.error( + '当前尚未关联统计服务空间,请先在manifest.json中配置服务空间!' + ); } } } @@ -1227,6 +1268,23 @@ class Stat extends Report { super(); } + /** + * 获取推送id + */ + pushEvent(options) { + if (uni.getPushClientId) { + uni.getPushClientId({ + success: (res) => { + const cid = res.cid || false; + // 只有获取到才会上传 + if (cid) { + this.sendPushRequest(options,cid); + } + }, + }); + } + } + /** * 进入应用 * @param {Object} options 页面参数 @@ -1237,7 +1295,7 @@ class Stat extends Report { set_page_residence_time(); this.__licationShow = true; dbSet('__launch_options', options); - // 应用初始上报参数为1 + // 应用初始上报参数为1 options.cst = 1; this.sendReportRequest(options, true); } @@ -1313,8 +1371,8 @@ class Stat extends Report { let route = ''; try { - route = get_route(); - }catch(e){ + route = get_route(); + } catch (e) { // 未获取到页面路径 route = ''; } @@ -1324,7 +1382,7 @@ class Stat extends Report { uuid: this.statData.uuid, p: this.statData.p, lt: '31', - url:route, + url: route, ut: this.statData.ut, ch: this.statData.ch, mpsdk: this.statData.mpsdk, @@ -1348,6 +1406,8 @@ const lifecycle = { onLaunch(options) { // 进入应用上报数据 stat.launch(options, this); + // 上报push推送id + stat.pushEvent(options); }, onLoad(options) { stat.load(options, this); diff --git a/packages/uni-stat/dist/uni-cloud-stat.es.js b/packages/uni-stat/dist/uni-cloud-stat.es.js index 7da4867d1801b0ff16288f6b0b022ad6901294ea..a6842d89c35482b28d1eb248d8ec7af796e49ecf 100644 --- a/packages/uni-stat/dist/uni-cloud-stat.es.js +++ b/packages/uni-stat/dist/uni-cloud-stat.es.js @@ -488,6 +488,9 @@ const log = (data) => { case '31': msg_type = '应用错误'; break + case '101': + msg_type = 'PUSH'; + break } if (msg_type) { console.log(`=== 统计数据采集:${msg_type} ===`); @@ -912,8 +915,9 @@ class Report { /** * 发送请求,应用维度上报 * @param {Object} options 页面信息 + * @param {Boolean} type 是否立即上报 */ - sendReportRequest(options) { + sendReportRequest(options, type) { this._navigationBarTitle.lt = '1'; this._navigationBarTitle.config = get_page_name(options.path); let is_opt = options.query && JSON.stringify(options.query) !== '{}'; @@ -930,9 +934,9 @@ class Report { cst: options.cst || 1, }); if (get_platform_name() === 'n') { - this.getProperty(); + this.getProperty(type); } else { - this.getNetworkInfo(); + this.getNetworkInfo(type); } } @@ -1013,24 +1017,59 @@ class Report { this.request(options); } + sendPushRequest(options, cid) { + let time = get_time(); + + const statData = { + lt: '101', + cid: cid, + t: time, + ut: this.statData.ut, + }; + + // debug 打印打点信息 + if (is_debug) { + log(statData); + } + + const stat_data = handle_data({ + 101: [statData], + }); + let optionsData = { + usv: STAT_VERSION, //统计 SDK 版本号 + t: time, //发送请求时的时间戮 + requests: stat_data, + }; + + // XXX 安卓需要延迟上报 ,否则会有未知错误,需要验证处理 + if (get_platform_name() === 'n' && this.statData.p === 'a') { + setTimeout(() => { + this.sendRequest(optionsData); + }, 200); + return + } + + this.sendRequest(optionsData); + } + /** * 获取wgt资源版本 */ - getProperty() { + getProperty(type) { plus.runtime.getProperty(plus.runtime.appid, (wgtinfo) => { this.statData.v = wgtinfo.version || ''; - this.getNetworkInfo(); + this.getNetworkInfo(type); }); } /** * 获取网络信息 */ - getNetworkInfo() { + getNetworkInfo(type) { uni.getNetworkType({ success: (result) => { this.statData.net = result.networkType; - this.getLocation(); + this.getLocation(type); }, }); } @@ -1038,7 +1077,7 @@ class Report { /** * 获取位置信息 */ - getLocation() { + getLocation(type) { if (stat_config.getLocation) { uni.getLocation({ type: 'wgs84', @@ -1052,13 +1091,13 @@ class Report { this.statData.lat = result.latitude; this.statData.lng = result.longitude; - this.request(this.statData); + this.request(this.statData, type); }, }); } else { this.statData.lat = 0; this.statData.lng = 0; - this.request(this.statData); + this.request(this.statData, type); } } @@ -1203,9 +1242,9 @@ class Stat extends Report { let spaceData = { provider: space.provider, spaceId: space.spaceId, - clientSecret: space.clientSecret + clientSecret: space.clientSecret, }; - if(space.endpoint){ + if (space.endpoint) { spaceData.endpoint = space.endpoint; } uni.__stat_uniCloud_space = uniCloud.init(spaceData); @@ -1214,7 +1253,9 @@ class Stat extends Report { // uni.__stat_uniCloud_space.config.spaceId // ) } else { - console.error('当前尚未关联统计服务空间,请先在manifest.json中配置服务空间!'); + console.error( + '当前尚未关联统计服务空间,请先在manifest.json中配置服务空间!' + ); } } } @@ -1225,6 +1266,23 @@ class Stat extends Report { super(); } + /** + * 获取推送id + */ + pushEvent(options) { + if (uni.getPushClientId) { + uni.getPushClientId({ + success: (res) => { + const cid = res.cid || false; + // 只有获取到才会上传 + if (cid) { + this.sendPushRequest(options,cid); + } + }, + }); + } + } + /** * 进入应用 * @param {Object} options 页面参数 @@ -1235,7 +1293,7 @@ class Stat extends Report { set_page_residence_time(); this.__licationShow = true; dbSet('__launch_options', options); - // 应用初始上报参数为1 + // 应用初始上报参数为1 options.cst = 1; this.sendReportRequest(options, true); } @@ -1311,8 +1369,8 @@ class Stat extends Report { let route = ''; try { - route = get_route(); - }catch(e){ + route = get_route(); + } catch (e) { // 未获取到页面路径 route = ''; } @@ -1322,7 +1380,7 @@ class Stat extends Report { uuid: this.statData.uuid, p: this.statData.p, lt: '31', - url:route, + url: route, ut: this.statData.ut, ch: this.statData.ch, mpsdk: this.statData.mpsdk, @@ -1346,6 +1404,8 @@ const lifecycle = { onLaunch(options) { // 进入应用上报数据 stat.launch(options, this); + // 上报push推送id + stat.pushEvent(options); }, onLoad(options) { stat.load(options, this); diff --git a/packages/uni-stat/dist/uni-stat.cjs.js b/packages/uni-stat/dist/uni-stat.cjs.js index 94863d14e30d3ff2b34cc21ab4d593064d01526d..9c85d79844719f2cfefab06eac95b9ac569f0925 100644 --- a/packages/uni-stat/dist/uni-stat.cjs.js +++ b/packages/uni-stat/dist/uni-stat.cjs.js @@ -292,7 +292,7 @@ const handle_data = (statData) => { rd.forEach((elm) => { let newData = ''; { - newData = get_splicing(elm); + newData = get_splicing(elm); } if (i === 0) { firstArr.push(newData); @@ -469,6 +469,9 @@ const log = (data) => { case '31': msg_type = '应用错误'; break + case '101': + msg_type = 'PUSH'; + break } if (msg_type) { console.log(`=== 统计数据采集:${msg_type} ===`); @@ -893,8 +896,9 @@ class Report { /** * 发送请求,应用维度上报 * @param {Object} options 页面信息 + * @param {Boolean} type 是否立即上报 */ - sendReportRequest(options) { + sendReportRequest(options, type) { this._navigationBarTitle.lt = '1'; this._navigationBarTitle.config = get_page_name(options.path); let is_opt = options.query && JSON.stringify(options.query) !== '{}'; @@ -911,9 +915,9 @@ class Report { cst: options.cst || 1, }); if (get_platform_name() === 'n') { - this.getProperty(); + this.getProperty(type); } else { - this.getNetworkInfo(); + this.getNetworkInfo(type); } } @@ -994,24 +998,66 @@ class Report { this.request(options); } + sendPushRequest(options, cid) { + let time = get_time(); + + const statData = { + lt: '101', + cid: cid, + t: time, + ut: this.statData.ut, + }; + + // debug 打印打点信息 + if (is_debug) { + log(statData); + } + + const stat_data = handle_data({ + 101: [statData], + }); + let optionsData = { + usv: STAT_VERSION, //统计 SDK 版本号 + t: time, //发送请求时的时间戮 + requests: stat_data, + }; + + { + if (statData.ut === 'h5') { + this.imageRequest(optionsData); + return + } + } + + // XXX 安卓需要延迟上报 ,否则会有未知错误,需要验证处理 + if (get_platform_name() === 'n' && this.statData.p === 'a') { + setTimeout(() => { + this.sendRequest(optionsData); + }, 200); + return + } + + this.sendRequest(optionsData); + } + /** * 获取wgt资源版本 */ - getProperty() { + getProperty(type) { plus.runtime.getProperty(plus.runtime.appid, (wgtinfo) => { this.statData.v = wgtinfo.version || ''; - this.getNetworkInfo(); + this.getNetworkInfo(type); }); } /** * 获取网络信息 */ - getNetworkInfo() { + getNetworkInfo(type) { uni.getNetworkType({ success: (result) => { this.statData.net = result.networkType; - this.getLocation(); + this.getLocation(type); }, }); } @@ -1019,7 +1065,7 @@ class Report { /** * 获取位置信息 */ - getLocation() { + getLocation(type) { if (stat_config.getLocation) { uni.getLocation({ type: 'wgs84', @@ -1033,13 +1079,13 @@ class Report { this.statData.lat = result.latitude; this.statData.lng = result.longitude; - this.request(this.statData); + this.request(this.statData, type); }, }); } else { this.statData.lat = 0; this.statData.lng = 0; - this.request(this.statData); + this.request(this.statData, type); } } @@ -1188,6 +1234,23 @@ class Stat extends Report { super(); } + /** + * 获取推送id + */ + pushEvent(options) { + if (uni.getPushClientId) { + uni.getPushClientId({ + success: (res) => { + const cid = res.cid || false; + // 只有获取到才会上传 + if (cid) { + this.sendPushRequest(options,cid); + } + }, + }); + } + } + /** * 进入应用 * @param {Object} options 页面参数 @@ -1198,7 +1261,7 @@ class Stat extends Report { set_page_residence_time(); this.__licationShow = true; dbSet('__launch_options', options); - // 应用初始上报参数为1 + // 应用初始上报参数为1 options.cst = 1; this.sendReportRequest(options, true); } @@ -1274,8 +1337,8 @@ class Stat extends Report { let route = ''; try { - route = get_route(); - }catch(e){ + route = get_route(); + } catch (e) { // 未获取到页面路径 route = ''; } @@ -1285,7 +1348,7 @@ class Stat extends Report { uuid: this.statData.uuid, p: this.statData.p, lt: '31', - url:route, + url: route, ut: this.statData.ut, ch: this.statData.ch, mpsdk: this.statData.mpsdk, @@ -1309,6 +1372,8 @@ const lifecycle = { onLaunch(options) { // 进入应用上报数据 stat.launch(options, this); + // 上报push推送id + stat.pushEvent(options); }, onLoad(options) { stat.load(options, this); diff --git a/packages/uni-stat/dist/uni-stat.es.js b/packages/uni-stat/dist/uni-stat.es.js index 78b405a09706fef148c11f7f45e4ff34d1602c1a..666e22fc6c8c5aaf19a4c18aef192bf1f5a874f8 100644 --- a/packages/uni-stat/dist/uni-stat.es.js +++ b/packages/uni-stat/dist/uni-stat.es.js @@ -290,7 +290,7 @@ const handle_data = (statData) => { rd.forEach((elm) => { let newData = ''; { - newData = get_splicing(elm); + newData = get_splicing(elm); } if (i === 0) { firstArr.push(newData); @@ -467,6 +467,9 @@ const log = (data) => { case '31': msg_type = '应用错误'; break + case '101': + msg_type = 'PUSH'; + break } if (msg_type) { console.log(`=== 统计数据采集:${msg_type} ===`); @@ -891,8 +894,9 @@ class Report { /** * 发送请求,应用维度上报 * @param {Object} options 页面信息 + * @param {Boolean} type 是否立即上报 */ - sendReportRequest(options) { + sendReportRequest(options, type) { this._navigationBarTitle.lt = '1'; this._navigationBarTitle.config = get_page_name(options.path); let is_opt = options.query && JSON.stringify(options.query) !== '{}'; @@ -909,9 +913,9 @@ class Report { cst: options.cst || 1, }); if (get_platform_name() === 'n') { - this.getProperty(); + this.getProperty(type); } else { - this.getNetworkInfo(); + this.getNetworkInfo(type); } } @@ -992,24 +996,66 @@ class Report { this.request(options); } + sendPushRequest(options, cid) { + let time = get_time(); + + const statData = { + lt: '101', + cid: cid, + t: time, + ut: this.statData.ut, + }; + + // debug 打印打点信息 + if (is_debug) { + log(statData); + } + + const stat_data = handle_data({ + 101: [statData], + }); + let optionsData = { + usv: STAT_VERSION, //统计 SDK 版本号 + t: time, //发送请求时的时间戮 + requests: stat_data, + }; + + { + if (statData.ut === 'h5') { + this.imageRequest(optionsData); + return + } + } + + // XXX 安卓需要延迟上报 ,否则会有未知错误,需要验证处理 + if (get_platform_name() === 'n' && this.statData.p === 'a') { + setTimeout(() => { + this.sendRequest(optionsData); + }, 200); + return + } + + this.sendRequest(optionsData); + } + /** * 获取wgt资源版本 */ - getProperty() { + getProperty(type) { plus.runtime.getProperty(plus.runtime.appid, (wgtinfo) => { this.statData.v = wgtinfo.version || ''; - this.getNetworkInfo(); + this.getNetworkInfo(type); }); } /** * 获取网络信息 */ - getNetworkInfo() { + getNetworkInfo(type) { uni.getNetworkType({ success: (result) => { this.statData.net = result.networkType; - this.getLocation(); + this.getLocation(type); }, }); } @@ -1017,7 +1063,7 @@ class Report { /** * 获取位置信息 */ - getLocation() { + getLocation(type) { if (stat_config.getLocation) { uni.getLocation({ type: 'wgs84', @@ -1031,13 +1077,13 @@ class Report { this.statData.lat = result.latitude; this.statData.lng = result.longitude; - this.request(this.statData); + this.request(this.statData, type); }, }); } else { this.statData.lat = 0; this.statData.lng = 0; - this.request(this.statData); + this.request(this.statData, type); } } @@ -1186,6 +1232,23 @@ class Stat extends Report { super(); } + /** + * 获取推送id + */ + pushEvent(options) { + if (uni.getPushClientId) { + uni.getPushClientId({ + success: (res) => { + const cid = res.cid || false; + // 只有获取到才会上传 + if (cid) { + this.sendPushRequest(options,cid); + } + }, + }); + } + } + /** * 进入应用 * @param {Object} options 页面参数 @@ -1196,7 +1259,7 @@ class Stat extends Report { set_page_residence_time(); this.__licationShow = true; dbSet('__launch_options', options); - // 应用初始上报参数为1 + // 应用初始上报参数为1 options.cst = 1; this.sendReportRequest(options, true); } @@ -1272,8 +1335,8 @@ class Stat extends Report { let route = ''; try { - route = get_route(); - }catch(e){ + route = get_route(); + } catch (e) { // 未获取到页面路径 route = ''; } @@ -1283,7 +1346,7 @@ class Stat extends Report { uuid: this.statData.uuid, p: this.statData.p, lt: '31', - url:route, + url: route, ut: this.statData.ut, ch: this.statData.ch, mpsdk: this.statData.mpsdk, @@ -1307,6 +1370,8 @@ const lifecycle = { onLaunch(options) { // 进入应用上报数据 stat.launch(options, this); + // 上报push推送id + stat.pushEvent(options); }, onLoad(options) { stat.load(options, this);