diff --git a/packages/uni-stat/dist/uni-cloud-stat.cjs.js b/packages/uni-stat/dist/uni-cloud-stat.cjs.js index 10eeafa2cc08fad9403107fd0445a065f4743edc..3b2768f6adb319210ff7a9e5e1961afe8f2b9538 100644 --- a/packages/uni-stat/dist/uni-cloud-stat.cjs.js +++ b/packages/uni-stat/dist/uni-cloud-stat.cjs.js @@ -14,6 +14,46 @@ const APP_PVER_TIME = 300; // 应用在后台结束访问时间 单位s const OPERATING_TIME = 10; // 数据上报时间 单位s const DIFF_TIME = 60 * 1000 * 60 * 24; +const appid = process.env.UNI_APP_ID; // 做应用隔离 +const dbSet = (name, value) => { + let data = uni.getStorageSync('$$STAT__DBDATA:'+appid) || {}; + + if (!data) { + data = {}; + } + data[name] = value; + uni.setStorageSync('$$STAT__DBDATA:'+appid, data); +}; + +const dbGet = (name) => { + let data = uni.getStorageSync('$$STAT__DBDATA:'+appid) || {}; + if (!data[name]) { + let dbdata = uni.getStorageSync('$$STAT__DBDATA:'+appid); + if (!dbdata) { + dbdata = {}; + } + if (!dbdata[name]) { + return undefined + } + data[name] = dbdata[name]; + } + return data[name] +}; + +const dbRemove = (name) => { + let data = uni.getStorageSync('$$STAT__DBDATA:'+appid) || {}; + if (data[name]) { + delete data[name]; + uni.setStorageSync('$$STAT__DBDATA:'+appid, data); + } else { + data = uni.getStorageSync('$$STAT__DBDATA:'+appid); + if (data[name]) { + delete data[name]; + uni.setStorageSync('$$STAT__DBDATA:'+appid, data); + } + } +}; + // 获取 manifest.json 中统计配置 const uniStatisticsConfig = process.env.UNI_STATISTICS_CONFIG; let statConfig = { @@ -82,6 +122,24 @@ const get_uuid = (statData) => { return sys.deviceId || getUuid() }; +/** + * 获取老版的 deviceid ,兼容以前的错误 deviceid + * @param {*} statData + * @returns + */ +const get_odid = (statData) => { + let odid = ''; + if (get_platform_name() === 'n') { + try { + odid = plus.device.uuid; + } catch (e) { + odid = ''; + } + return odid + } + return sys.deviceId || getUuid() +}; + /** * 获取配置信息 如 appid */ @@ -542,46 +600,17 @@ const is_push_clientid = () => { return typeof ClientID === 'boolean' ? ClientID : false } return false -}; - -const appid = process.env.UNI_APP_ID; // 做应用隔离 -const dbSet = (name, value) => { - let data = uni.getStorageSync('$$STAT__DBDATA:'+appid) || {}; - - if (!data) { - data = {}; - } - data[name] = value; - uni.setStorageSync('$$STAT__DBDATA:'+appid, data); -}; - -const dbGet = (name) => { - let data = uni.getStorageSync('$$STAT__DBDATA:'+appid) || {}; - if (!data[name]) { - let dbdata = uni.getStorageSync('$$STAT__DBDATA:'+appid); - if (!dbdata) { - dbdata = {}; - } - if (!dbdata[name]) { - return undefined - } - data[name] = dbdata[name]; - } - return data[name] }; -const dbRemove = (name) => { - let data = uni.getStorageSync('$$STAT__DBDATA:'+appid) || {}; - if (data[name]) { - delete data[name]; - uni.setStorageSync('$$STAT__DBDATA:'+appid, data); - } else { - data = uni.getStorageSync('$$STAT__DBDATA:'+appid); - if (data[name]) { - delete data[name]; - uni.setStorageSync('$$STAT__DBDATA:'+appid, data); - } - } +/** + * 是否已处理设备 DeviceId + * 如果值为 1 则表示已处理 + */ +const IS_HANDLE_DEVECE_ID = 'is_handle_device_id'; +const is_handle_device = () => { + let isHandleDevice = dbGet(IS_HANDLE_DEVECE_ID) || ''; + dbSet(IS_HANDLE_DEVECE_ID, '1'); + return isHandleDevice === '1' }; // 首次访问时间 @@ -968,13 +997,28 @@ class Report { this._navigationBarTitle.config = get_page_name(options.path); let is_opt = options.query && JSON.stringify(options.query) !== '{}'; let query = is_opt ? '?' + JSON.stringify(options.query) : ''; + const last_time = get_last_visit_time(); + // 非老用户 + if(last_time !== 0 || !last_time){ + const odid = get_odid(); + + // 2.0 处理规则 + { + const have_device = is_handle_device(); + // 如果没有上报过设备信息 ,则需要上报设备信息 + if(!have_device) { + this.statData.odid = odid; + } + } + } + Object.assign(this.statData, { lt: '1', url: options.path + query || '', t: get_time(), sc: get_scene(options.scene), fvts: get_first_visit_time(), - lvts: get_last_visit_time(), + lvts: last_time, tvc: get_total_visit_count(), // create session type 上报类型 ,1 应用进入 2.后台30min进入 3.页面30min进入 cst: options.cst || 1, diff --git a/packages/uni-stat/dist/uni-cloud-stat.es.js b/packages/uni-stat/dist/uni-cloud-stat.es.js index bb5e3c572689b20d37559faee4c3ff8e7f8ff340..bac4e88cd4c19de35f639d4e26253678c233d028 100644 --- a/packages/uni-stat/dist/uni-cloud-stat.es.js +++ b/packages/uni-stat/dist/uni-cloud-stat.es.js @@ -12,6 +12,46 @@ const APP_PVER_TIME = 300; // 应用在后台结束访问时间 单位s const OPERATING_TIME = 10; // 数据上报时间 单位s const DIFF_TIME = 60 * 1000 * 60 * 24; +const appid = process.env.UNI_APP_ID; // 做应用隔离 +const dbSet = (name, value) => { + let data = uni.getStorageSync('$$STAT__DBDATA:'+appid) || {}; + + if (!data) { + data = {}; + } + data[name] = value; + uni.setStorageSync('$$STAT__DBDATA:'+appid, data); +}; + +const dbGet = (name) => { + let data = uni.getStorageSync('$$STAT__DBDATA:'+appid) || {}; + if (!data[name]) { + let dbdata = uni.getStorageSync('$$STAT__DBDATA:'+appid); + if (!dbdata) { + dbdata = {}; + } + if (!dbdata[name]) { + return undefined + } + data[name] = dbdata[name]; + } + return data[name] +}; + +const dbRemove = (name) => { + let data = uni.getStorageSync('$$STAT__DBDATA:'+appid) || {}; + if (data[name]) { + delete data[name]; + uni.setStorageSync('$$STAT__DBDATA:'+appid, data); + } else { + data = uni.getStorageSync('$$STAT__DBDATA:'+appid); + if (data[name]) { + delete data[name]; + uni.setStorageSync('$$STAT__DBDATA:'+appid, data); + } + } +}; + // 获取 manifest.json 中统计配置 const uniStatisticsConfig = process.env.UNI_STATISTICS_CONFIG; let statConfig = { @@ -80,6 +120,24 @@ const get_uuid = (statData) => { return sys.deviceId || getUuid() }; +/** + * 获取老版的 deviceid ,兼容以前的错误 deviceid + * @param {*} statData + * @returns + */ +const get_odid = (statData) => { + let odid = ''; + if (get_platform_name() === 'n') { + try { + odid = plus.device.uuid; + } catch (e) { + odid = ''; + } + return odid + } + return sys.deviceId || getUuid() +}; + /** * 获取配置信息 如 appid */ @@ -540,46 +598,17 @@ const is_push_clientid = () => { return typeof ClientID === 'boolean' ? ClientID : false } return false -}; - -const appid = process.env.UNI_APP_ID; // 做应用隔离 -const dbSet = (name, value) => { - let data = uni.getStorageSync('$$STAT__DBDATA:'+appid) || {}; - - if (!data) { - data = {}; - } - data[name] = value; - uni.setStorageSync('$$STAT__DBDATA:'+appid, data); -}; - -const dbGet = (name) => { - let data = uni.getStorageSync('$$STAT__DBDATA:'+appid) || {}; - if (!data[name]) { - let dbdata = uni.getStorageSync('$$STAT__DBDATA:'+appid); - if (!dbdata) { - dbdata = {}; - } - if (!dbdata[name]) { - return undefined - } - data[name] = dbdata[name]; - } - return data[name] }; -const dbRemove = (name) => { - let data = uni.getStorageSync('$$STAT__DBDATA:'+appid) || {}; - if (data[name]) { - delete data[name]; - uni.setStorageSync('$$STAT__DBDATA:'+appid, data); - } else { - data = uni.getStorageSync('$$STAT__DBDATA:'+appid); - if (data[name]) { - delete data[name]; - uni.setStorageSync('$$STAT__DBDATA:'+appid, data); - } - } +/** + * 是否已处理设备 DeviceId + * 如果值为 1 则表示已处理 + */ +const IS_HANDLE_DEVECE_ID = 'is_handle_device_id'; +const is_handle_device = () => { + let isHandleDevice = dbGet(IS_HANDLE_DEVECE_ID) || ''; + dbSet(IS_HANDLE_DEVECE_ID, '1'); + return isHandleDevice === '1' }; // 首次访问时间 @@ -966,13 +995,28 @@ class Report { this._navigationBarTitle.config = get_page_name(options.path); let is_opt = options.query && JSON.stringify(options.query) !== '{}'; let query = is_opt ? '?' + JSON.stringify(options.query) : ''; + const last_time = get_last_visit_time(); + // 非老用户 + if(last_time !== 0 || !last_time){ + const odid = get_odid(); + + // 2.0 处理规则 + { + const have_device = is_handle_device(); + // 如果没有上报过设备信息 ,则需要上报设备信息 + if(!have_device) { + this.statData.odid = odid; + } + } + } + Object.assign(this.statData, { lt: '1', url: options.path + query || '', t: get_time(), sc: get_scene(options.scene), fvts: get_first_visit_time(), - lvts: get_last_visit_time(), + lvts: last_time, tvc: get_total_visit_count(), // create session type 上报类型 ,1 应用进入 2.后台30min进入 3.页面30min进入 cst: options.cst || 1, diff --git a/packages/uni-stat/dist/uni-stat.cjs.js b/packages/uni-stat/dist/uni-stat.cjs.js index 4b720b853fe5ca4871731f07c732ee9efc85cefb..4c59ad4ccb6b122de479520aef3e28619ed7b42f 100644 --- a/packages/uni-stat/dist/uni-stat.cjs.js +++ b/packages/uni-stat/dist/uni-stat.cjs.js @@ -14,6 +14,46 @@ const APP_PVER_TIME = 300; // 应用在后台结束访问时间 单位s const OPERATING_TIME = 10; // 数据上报时间 单位s const DIFF_TIME = 60 * 1000 * 60 * 24; +const appid = process.env.UNI_APP_ID; // 做应用隔离 +const dbSet = (name, value) => { + let data = uni.getStorageSync('$$STAT__DBDATA:'+appid) || {}; + + if (!data) { + data = {}; + } + data[name] = value; + uni.setStorageSync('$$STAT__DBDATA:'+appid, data); +}; + +const dbGet = (name) => { + let data = uni.getStorageSync('$$STAT__DBDATA:'+appid) || {}; + if (!data[name]) { + let dbdata = uni.getStorageSync('$$STAT__DBDATA:'+appid); + if (!dbdata) { + dbdata = {}; + } + if (!dbdata[name]) { + return undefined + } + data[name] = dbdata[name]; + } + return data[name] +}; + +const dbRemove = (name) => { + let data = uni.getStorageSync('$$STAT__DBDATA:'+appid) || {}; + if (data[name]) { + delete data[name]; + uni.setStorageSync('$$STAT__DBDATA:'+appid, data); + } else { + data = uni.getStorageSync('$$STAT__DBDATA:'+appid); + if (data[name]) { + delete data[name]; + uni.setStorageSync('$$STAT__DBDATA:'+appid, data); + } + } +}; + // 获取 manifest.json 中统计配置 const uniStatisticsConfig = process.env.UNI_STATISTICS_CONFIG; let statConfig = { @@ -82,6 +122,24 @@ const get_uuid = (statData) => { return sys.deviceId || getUuid() }; +/** + * 获取老版的 deviceid ,兼容以前的错误 deviceid + * @param {*} statData + * @returns + */ +const get_odid = (statData) => { + let odid = ''; + if (get_platform_name() === 'n') { + try { + odid = plus.device.uuid; + } catch (e) { + odid = ''; + } + return odid + } + return sys.deviceId || getUuid() +}; + /** * 获取配置信息 如 appid */ @@ -523,46 +581,6 @@ const is_push_clientid = () => { return false }; -const appid = process.env.UNI_APP_ID; // 做应用隔离 -const dbSet = (name, value) => { - let data = uni.getStorageSync('$$STAT__DBDATA:'+appid) || {}; - - if (!data) { - data = {}; - } - data[name] = value; - uni.setStorageSync('$$STAT__DBDATA:'+appid, data); -}; - -const dbGet = (name) => { - let data = uni.getStorageSync('$$STAT__DBDATA:'+appid) || {}; - if (!data[name]) { - let dbdata = uni.getStorageSync('$$STAT__DBDATA:'+appid); - if (!dbdata) { - dbdata = {}; - } - if (!dbdata[name]) { - return undefined - } - data[name] = dbdata[name]; - } - return data[name] -}; - -const dbRemove = (name) => { - let data = uni.getStorageSync('$$STAT__DBDATA:'+appid) || {}; - if (data[name]) { - delete data[name]; - uni.setStorageSync('$$STAT__DBDATA:'+appid, data); - } else { - data = uni.getStorageSync('$$STAT__DBDATA:'+appid); - if (data[name]) { - delete data[name]; - uni.setStorageSync('$$STAT__DBDATA:'+appid, data); - } - } -}; - // 首次访问时间 const FIRST_VISIT_TIME_KEY = '__first__visit__time'; // 最后访问时间 @@ -947,13 +965,23 @@ class Report { this._navigationBarTitle.config = get_page_name(options.path); let is_opt = options.query && JSON.stringify(options.query) !== '{}'; let query = is_opt ? '?' + JSON.stringify(options.query) : ''; + const last_time = get_last_visit_time(); + // 非老用户 + if(last_time !== 0 || !last_time){ + const odid = get_odid(); + // 1.0 处理规则 + { + this.statData.odid = odid; + } + } + Object.assign(this.statData, { lt: '1', url: options.path + query || '', t: get_time(), sc: get_scene(options.scene), fvts: get_first_visit_time(), - lvts: get_last_visit_time(), + lvts: last_time, tvc: get_total_visit_count(), // create session type 上报类型 ,1 应用进入 2.后台30min进入 3.页面30min进入 cst: options.cst || 1, diff --git a/packages/uni-stat/dist/uni-stat.es.js b/packages/uni-stat/dist/uni-stat.es.js index 9cc9dea8d8205189d7495bb5cc7bf19570da727d..cfbed69fccfd9562e6a13579af682af4a3d3713a 100644 --- a/packages/uni-stat/dist/uni-stat.es.js +++ b/packages/uni-stat/dist/uni-stat.es.js @@ -12,6 +12,46 @@ const APP_PVER_TIME = 300; // 应用在后台结束访问时间 单位s const OPERATING_TIME = 10; // 数据上报时间 单位s const DIFF_TIME = 60 * 1000 * 60 * 24; +const appid = process.env.UNI_APP_ID; // 做应用隔离 +const dbSet = (name, value) => { + let data = uni.getStorageSync('$$STAT__DBDATA:'+appid) || {}; + + if (!data) { + data = {}; + } + data[name] = value; + uni.setStorageSync('$$STAT__DBDATA:'+appid, data); +}; + +const dbGet = (name) => { + let data = uni.getStorageSync('$$STAT__DBDATA:'+appid) || {}; + if (!data[name]) { + let dbdata = uni.getStorageSync('$$STAT__DBDATA:'+appid); + if (!dbdata) { + dbdata = {}; + } + if (!dbdata[name]) { + return undefined + } + data[name] = dbdata[name]; + } + return data[name] +}; + +const dbRemove = (name) => { + let data = uni.getStorageSync('$$STAT__DBDATA:'+appid) || {}; + if (data[name]) { + delete data[name]; + uni.setStorageSync('$$STAT__DBDATA:'+appid, data); + } else { + data = uni.getStorageSync('$$STAT__DBDATA:'+appid); + if (data[name]) { + delete data[name]; + uni.setStorageSync('$$STAT__DBDATA:'+appid, data); + } + } +}; + // 获取 manifest.json 中统计配置 const uniStatisticsConfig = process.env.UNI_STATISTICS_CONFIG; let statConfig = { @@ -80,6 +120,24 @@ const get_uuid = (statData) => { return sys.deviceId || getUuid() }; +/** + * 获取老版的 deviceid ,兼容以前的错误 deviceid + * @param {*} statData + * @returns + */ +const get_odid = (statData) => { + let odid = ''; + if (get_platform_name() === 'n') { + try { + odid = plus.device.uuid; + } catch (e) { + odid = ''; + } + return odid + } + return sys.deviceId || getUuid() +}; + /** * 获取配置信息 如 appid */ @@ -521,46 +579,6 @@ const is_push_clientid = () => { return false }; -const appid = process.env.UNI_APP_ID; // 做应用隔离 -const dbSet = (name, value) => { - let data = uni.getStorageSync('$$STAT__DBDATA:'+appid) || {}; - - if (!data) { - data = {}; - } - data[name] = value; - uni.setStorageSync('$$STAT__DBDATA:'+appid, data); -}; - -const dbGet = (name) => { - let data = uni.getStorageSync('$$STAT__DBDATA:'+appid) || {}; - if (!data[name]) { - let dbdata = uni.getStorageSync('$$STAT__DBDATA:'+appid); - if (!dbdata) { - dbdata = {}; - } - if (!dbdata[name]) { - return undefined - } - data[name] = dbdata[name]; - } - return data[name] -}; - -const dbRemove = (name) => { - let data = uni.getStorageSync('$$STAT__DBDATA:'+appid) || {}; - if (data[name]) { - delete data[name]; - uni.setStorageSync('$$STAT__DBDATA:'+appid, data); - } else { - data = uni.getStorageSync('$$STAT__DBDATA:'+appid); - if (data[name]) { - delete data[name]; - uni.setStorageSync('$$STAT__DBDATA:'+appid, data); - } - } -}; - // 首次访问时间 const FIRST_VISIT_TIME_KEY = '__first__visit__time'; // 最后访问时间 @@ -945,13 +963,23 @@ class Report { this._navigationBarTitle.config = get_page_name(options.path); let is_opt = options.query && JSON.stringify(options.query) !== '{}'; let query = is_opt ? '?' + JSON.stringify(options.query) : ''; + const last_time = get_last_visit_time(); + // 非老用户 + if(last_time !== 0 || !last_time){ + const odid = get_odid(); + // 1.0 处理规则 + { + this.statData.odid = odid; + } + } + Object.assign(this.statData, { lt: '1', url: options.path + query || '', t: get_time(), sc: get_scene(options.scene), fvts: get_first_visit_time(), - lvts: get_last_visit_time(), + lvts: last_time, tvc: get_total_visit_count(), // create session type 上报类型 ,1 应用进入 2.后台30min进入 3.页面30min进入 cst: options.cst || 1, diff --git a/packages/vue-cli-plugin-uni/lib/env.js b/packages/vue-cli-plugin-uni/lib/env.js index 21cbe12718350a50bda884df1889b676ea820f49..74975b2640949d7477971243d6c12479b54be676 100644 --- a/packages/vue-cli-plugin-uni/lib/env.js +++ b/packages/vue-cli-plugin-uni/lib/env.js @@ -341,7 +341,13 @@ if ( ) if (uniStatistics.enable === true) { - process.env.UNI_USING_STAT = Number(uniStatistics.version) === 2 ? '2' : '1' + const uniStatLog = (text) => { + console.log() + console.warn(text) + console.log() + } + const version = Number(uniStatistics.version) === 2 ? '2' : '1' + process.env.UNI_USING_STAT = version // 获取服务空间配置信息 const uniCloudConfig = uniStatistics.uniCloud || {} process.env.UNI_STATISTICS_CONFIG = JSON.stringify(uniStatistics) @@ -350,35 +356,31 @@ if ( if (process.env.NODE_ENV === 'production') { if (!process.UNI_STAT_CONFIG.appid) { - console.log() - console.warn(uniI18n.__('pluginUni.uniStatisticsNoAppid', { + uniStatLog(uniI18n.__('pluginUni.uniStatisticsNoAppid', { 0: 'https://ask.dcloud.net.cn/article/36303' })) - console.log() } else { if (!uniStatistics.version) { - console.log() - console.warn(uniI18n.__('pluginUni.uniStatisticsNoVersion', { + uniStatLog(uniI18n.__('pluginUni.uniStatisticsNoVersion', { 0: 'https://uniapp.dcloud.io/uni-stat-v2.html' })) - console.log() } else { - console.log() - console.warn(`已开启 uni统计${uniStatistics.version}.0 版本`) - console.log() + uniStatLog(`已开启 uni统计${uniStatistics.version}.0 版本`) + if (version === '2') { + uniStatLog('【重要】因 HBuilderX 3.4.9 版本起,uni统计2.0 调整了安卓端 deviceId 获取方式,导致 uni统计2.0 App-Android平台部分统计数据不准确。如使用了HBuilderX 3.4.9 - 3.6.4版本且开通了uni统计2.0的应用,需要使用HBuilderX3.6.7及以上版本重新发布应用并升级 uniAdmin 云函数解决,详见:https://ask.dcloud.net.cn/article/40097') + } } } } else { if (!uniStatistics.version) { - console.log() - console.warn(uniI18n.__('pluginUni.uniStatisticsNoVersion', { + uniStatLog(uniI18n.__('pluginUni.uniStatisticsNoVersion', { 0: 'https://uniapp.dcloud.io/uni-stat-v2.html' })) - console.log() } else { - console.log() - console.warn(`已开启 uni统计${uniStatistics.version}.0 版本`) - console.log() + uniStatLog(`已开启 uni统计${uniStatistics.version}.0 版本`) + if (version === '2') { + uniStatLog('【重要】因 HBuilderX 3.4.9 版本起,uni统计2.0 调整了安卓端 deviceId 获取方式,导致 uni统计2.0 App-Android平台部分统计数据不准确。如使用了HBuilderX 3.4.9 - 3.6.4版本且开通了uni统计2.0的应用,需要使用HBuilderX3.6.7及以上版本重新发布应用并升级 uniAdmin 云函数解决,详见:https://ask.dcloud.net.cn/article/40097') + } } } }