提交 ef6c3f24 编写于 作者: M mehaotian

feat(stat): 新增 odid 属性,uuid 替换为新api获取的 deciceid

上级 83c55249
...@@ -14,6 +14,46 @@ const APP_PVER_TIME = 300; // 应用在后台结束访问时间 单位s ...@@ -14,6 +14,46 @@ const APP_PVER_TIME = 300; // 应用在后台结束访问时间 单位s
const OPERATING_TIME = 10; // 数据上报时间 单位s const OPERATING_TIME = 10; // 数据上报时间 单位s
const DIFF_TIME = 60 * 1000 * 60 * 24; 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 中统计配置 // 获取 manifest.json 中统计配置
const uniStatisticsConfig = process.env.UNI_STATISTICS_CONFIG; const uniStatisticsConfig = process.env.UNI_STATISTICS_CONFIG;
let statConfig = { let statConfig = {
...@@ -82,6 +122,24 @@ const get_uuid = (statData) => { ...@@ -82,6 +122,24 @@ const get_uuid = (statData) => {
return sys.deviceId || getUuid() 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 * 获取配置信息 如 appid
*/ */
...@@ -542,46 +600,17 @@ const is_push_clientid = () => { ...@@ -542,46 +600,17 @@ const is_push_clientid = () => {
return typeof ClientID === 'boolean' ? ClientID : false return typeof ClientID === 'boolean' ? ClientID : false
} }
return 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) || {}; * 是否已处理设备 DeviceId
if (data[name]) { * 如果值为 1 则表示已处理
delete data[name]; */
uni.setStorageSync('$$STAT__DBDATA:'+appid, data); const IS_HANDLE_DEVECE_ID = 'is_handle_device_id';
} else { const is_handle_device = () => {
data = uni.getStorageSync('$$STAT__DBDATA:'+appid); let isHandleDevice = dbGet(IS_HANDLE_DEVECE_ID) || '';
if (data[name]) { dbSet(IS_HANDLE_DEVECE_ID, '1');
delete data[name]; return isHandleDevice === '1'
uni.setStorageSync('$$STAT__DBDATA:'+appid, data);
}
}
}; };
// 首次访问时间 // 首次访问时间
...@@ -968,13 +997,28 @@ class Report { ...@@ -968,13 +997,28 @@ class Report {
this._navigationBarTitle.config = get_page_name(options.path); this._navigationBarTitle.config = get_page_name(options.path);
let is_opt = options.query && JSON.stringify(options.query) !== '{}'; let is_opt = options.query && JSON.stringify(options.query) !== '{}';
let query = is_opt ? '?' + 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, { Object.assign(this.statData, {
lt: '1', lt: '1',
url: options.path + query || '', url: options.path + query || '',
t: get_time(), t: get_time(),
sc: get_scene(options.scene), sc: get_scene(options.scene),
fvts: get_first_visit_time(), fvts: get_first_visit_time(),
lvts: get_last_visit_time(), lvts: last_time,
tvc: get_total_visit_count(), tvc: get_total_visit_count(),
// create session type 上报类型 ,1 应用进入 2.后台30min进入 3.页面30min进入 // create session type 上报类型 ,1 应用进入 2.后台30min进入 3.页面30min进入
cst: options.cst || 1, cst: options.cst || 1,
......
...@@ -12,6 +12,46 @@ const APP_PVER_TIME = 300; // 应用在后台结束访问时间 单位s ...@@ -12,6 +12,46 @@ const APP_PVER_TIME = 300; // 应用在后台结束访问时间 单位s
const OPERATING_TIME = 10; // 数据上报时间 单位s const OPERATING_TIME = 10; // 数据上报时间 单位s
const DIFF_TIME = 60 * 1000 * 60 * 24; 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 中统计配置 // 获取 manifest.json 中统计配置
const uniStatisticsConfig = process.env.UNI_STATISTICS_CONFIG; const uniStatisticsConfig = process.env.UNI_STATISTICS_CONFIG;
let statConfig = { let statConfig = {
...@@ -80,6 +120,24 @@ const get_uuid = (statData) => { ...@@ -80,6 +120,24 @@ const get_uuid = (statData) => {
return sys.deviceId || getUuid() 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 * 获取配置信息 如 appid
*/ */
...@@ -540,46 +598,17 @@ const is_push_clientid = () => { ...@@ -540,46 +598,17 @@ const is_push_clientid = () => {
return typeof ClientID === 'boolean' ? ClientID : false return typeof ClientID === 'boolean' ? ClientID : false
} }
return 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) || {}; * 是否已处理设备 DeviceId
if (data[name]) { * 如果值为 1 则表示已处理
delete data[name]; */
uni.setStorageSync('$$STAT__DBDATA:'+appid, data); const IS_HANDLE_DEVECE_ID = 'is_handle_device_id';
} else { const is_handle_device = () => {
data = uni.getStorageSync('$$STAT__DBDATA:'+appid); let isHandleDevice = dbGet(IS_HANDLE_DEVECE_ID) || '';
if (data[name]) { dbSet(IS_HANDLE_DEVECE_ID, '1');
delete data[name]; return isHandleDevice === '1'
uni.setStorageSync('$$STAT__DBDATA:'+appid, data);
}
}
}; };
// 首次访问时间 // 首次访问时间
...@@ -966,13 +995,28 @@ class Report { ...@@ -966,13 +995,28 @@ class Report {
this._navigationBarTitle.config = get_page_name(options.path); this._navigationBarTitle.config = get_page_name(options.path);
let is_opt = options.query && JSON.stringify(options.query) !== '{}'; let is_opt = options.query && JSON.stringify(options.query) !== '{}';
let query = is_opt ? '?' + 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, { Object.assign(this.statData, {
lt: '1', lt: '1',
url: options.path + query || '', url: options.path + query || '',
t: get_time(), t: get_time(),
sc: get_scene(options.scene), sc: get_scene(options.scene),
fvts: get_first_visit_time(), fvts: get_first_visit_time(),
lvts: get_last_visit_time(), lvts: last_time,
tvc: get_total_visit_count(), tvc: get_total_visit_count(),
// create session type 上报类型 ,1 应用进入 2.后台30min进入 3.页面30min进入 // create session type 上报类型 ,1 应用进入 2.后台30min进入 3.页面30min进入
cst: options.cst || 1, cst: options.cst || 1,
......
...@@ -14,6 +14,46 @@ const APP_PVER_TIME = 300; // 应用在后台结束访问时间 单位s ...@@ -14,6 +14,46 @@ const APP_PVER_TIME = 300; // 应用在后台结束访问时间 单位s
const OPERATING_TIME = 10; // 数据上报时间 单位s const OPERATING_TIME = 10; // 数据上报时间 单位s
const DIFF_TIME = 60 * 1000 * 60 * 24; 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 中统计配置 // 获取 manifest.json 中统计配置
const uniStatisticsConfig = process.env.UNI_STATISTICS_CONFIG; const uniStatisticsConfig = process.env.UNI_STATISTICS_CONFIG;
let statConfig = { let statConfig = {
...@@ -82,6 +122,24 @@ const get_uuid = (statData) => { ...@@ -82,6 +122,24 @@ const get_uuid = (statData) => {
return sys.deviceId || getUuid() 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 * 获取配置信息 如 appid
*/ */
...@@ -523,46 +581,6 @@ const is_push_clientid = () => { ...@@ -523,46 +581,6 @@ const is_push_clientid = () => {
return 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);
}
}
};
// 首次访问时间 // 首次访问时间
const FIRST_VISIT_TIME_KEY = '__first__visit__time'; const FIRST_VISIT_TIME_KEY = '__first__visit__time';
// 最后访问时间 // 最后访问时间
...@@ -947,13 +965,23 @@ class Report { ...@@ -947,13 +965,23 @@ class Report {
this._navigationBarTitle.config = get_page_name(options.path); this._navigationBarTitle.config = get_page_name(options.path);
let is_opt = options.query && JSON.stringify(options.query) !== '{}'; let is_opt = options.query && JSON.stringify(options.query) !== '{}';
let query = is_opt ? '?' + 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, { Object.assign(this.statData, {
lt: '1', lt: '1',
url: options.path + query || '', url: options.path + query || '',
t: get_time(), t: get_time(),
sc: get_scene(options.scene), sc: get_scene(options.scene),
fvts: get_first_visit_time(), fvts: get_first_visit_time(),
lvts: get_last_visit_time(), lvts: last_time,
tvc: get_total_visit_count(), tvc: get_total_visit_count(),
// create session type 上报类型 ,1 应用进入 2.后台30min进入 3.页面30min进入 // create session type 上报类型 ,1 应用进入 2.后台30min进入 3.页面30min进入
cst: options.cst || 1, cst: options.cst || 1,
......
...@@ -12,6 +12,46 @@ const APP_PVER_TIME = 300; // 应用在后台结束访问时间 单位s ...@@ -12,6 +12,46 @@ const APP_PVER_TIME = 300; // 应用在后台结束访问时间 单位s
const OPERATING_TIME = 10; // 数据上报时间 单位s const OPERATING_TIME = 10; // 数据上报时间 单位s
const DIFF_TIME = 60 * 1000 * 60 * 24; 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 中统计配置 // 获取 manifest.json 中统计配置
const uniStatisticsConfig = process.env.UNI_STATISTICS_CONFIG; const uniStatisticsConfig = process.env.UNI_STATISTICS_CONFIG;
let statConfig = { let statConfig = {
...@@ -80,6 +120,24 @@ const get_uuid = (statData) => { ...@@ -80,6 +120,24 @@ const get_uuid = (statData) => {
return sys.deviceId || getUuid() 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 * 获取配置信息 如 appid
*/ */
...@@ -521,46 +579,6 @@ const is_push_clientid = () => { ...@@ -521,46 +579,6 @@ const is_push_clientid = () => {
return 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);
}
}
};
// 首次访问时间 // 首次访问时间
const FIRST_VISIT_TIME_KEY = '__first__visit__time'; const FIRST_VISIT_TIME_KEY = '__first__visit__time';
// 最后访问时间 // 最后访问时间
...@@ -945,13 +963,23 @@ class Report { ...@@ -945,13 +963,23 @@ class Report {
this._navigationBarTitle.config = get_page_name(options.path); this._navigationBarTitle.config = get_page_name(options.path);
let is_opt = options.query && JSON.stringify(options.query) !== '{}'; let is_opt = options.query && JSON.stringify(options.query) !== '{}';
let query = is_opt ? '?' + 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, { Object.assign(this.statData, {
lt: '1', lt: '1',
url: options.path + query || '', url: options.path + query || '',
t: get_time(), t: get_time(),
sc: get_scene(options.scene), sc: get_scene(options.scene),
fvts: get_first_visit_time(), fvts: get_first_visit_time(),
lvts: get_last_visit_time(), lvts: last_time,
tvc: get_total_visit_count(), tvc: get_total_visit_count(),
// create session type 上报类型 ,1 应用进入 2.后台30min进入 3.页面30min进入 // create session type 上报类型 ,1 应用进入 2.后台30min进入 3.页面30min进入
cst: options.cst || 1, cst: options.cst || 1,
......
...@@ -23,6 +23,11 @@ const uniStatLog = once((text) => { ...@@ -23,6 +23,11 @@ const uniStatLog = once((text) => {
console.warn(text); console.warn(text);
console.log(); console.log();
}); });
const uniStatDeviceLog = once((text) => {
console.log();
console.warn(text);
console.log();
});
var index = () => [ var index = () => [
uniCliShared.defineUniMainJsPlugin((opts) => { uniCliShared.defineUniMainJsPlugin((opts) => {
let statVersion = '1'; let statVersion = '1';
...@@ -75,6 +80,9 @@ var index = () => [ ...@@ -75,6 +80,9 @@ var index = () => [
} }
else { else {
uniStatLog(`已开启 uni统计${statVersion}.0 版本`); uniStatLog(`已开启 uni统计${statVersion}.0 版本`);
if (statVersion === '2') {
uniStatDeviceLog('1【重要】因 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');
}
} }
} }
} }
...@@ -84,6 +92,9 @@ var index = () => [ ...@@ -84,6 +92,9 @@ var index = () => [
} }
else { else {
uniStatLog(uniCliShared.M['stat.warn.tip'].replace('{version}', `${statVersion}.0`)); uniStatLog(uniCliShared.M['stat.warn.tip'].replace('{version}', `${statVersion}.0`));
if (statVersion === '2') {
uniStatDeviceLog('【重要】因 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');
}
} }
} }
} }
......
...@@ -12,6 +12,7 @@ import { ...@@ -12,6 +12,7 @@ import {
import { import {
stat_config, stat_config,
get_uuid, get_uuid,
get_odid,
get_platform_name, get_platform_name,
get_pack_name, get_pack_name,
get_scene, get_scene,
...@@ -30,6 +31,7 @@ import { ...@@ -30,6 +31,7 @@ import {
is_debug, is_debug,
log, log,
get_report_Interval, get_report_Interval,
is_handle_device
} from '../utils/pageInfo.js' } from '../utils/pageInfo.js'
import { sys } from '../utils/util.js' import { sys } from '../utils/util.js'
...@@ -295,13 +297,32 @@ export default class Report { ...@@ -295,13 +297,32 @@ export default class Report {
this._navigationBarTitle.config = get_page_name(options.path) this._navigationBarTitle.config = get_page_name(options.path)
let is_opt = options.query && JSON.stringify(options.query) !== '{}' let is_opt = options.query && JSON.stringify(options.query) !== '{}'
let query = is_opt ? '?' + 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 处理规则
if (__STAT_VERSION__ === '1') {
this.statData.odid = odid
}
// 2.0 处理规则
if (__STAT_VERSION__ === '2') {
const have_device = is_handle_device()
// 如果没有上报过设备信息 ,则需要上报设备信息
if(!have_device) {
this.statData.odid = odid
}
}
}
Object.assign(this.statData, { Object.assign(this.statData, {
lt: '1', lt: '1',
url: options.path + query || '', url: options.path + query || '',
t: get_time(), t: get_time(),
sc: get_scene(options.scene), sc: get_scene(options.scene),
fvts: get_first_visit_time(), fvts: get_first_visit_time(),
lvts: get_last_visit_time(), lvts: last_time,
tvc: get_total_visit_count(), tvc: get_total_visit_count(),
// create session type 上报类型 ,1 应用进入 2.后台30min进入 3.页面30min进入 // create session type 上报类型 ,1 应用进入 2.后台30min进入 3.页面30min进入
cst: options.cst || 1, cst: options.cst || 1,
......
...@@ -17,6 +17,12 @@ const uniStatLog = once((text: string) => { ...@@ -17,6 +17,12 @@ const uniStatLog = once((text: string) => {
console.log() console.log()
}) })
const uniStatDeviceLog = once((text: string) => {
console.log()
console.warn(text)
console.log()
})
export default () => [ export default () => [
defineUniMainJsPlugin((opts) => { defineUniMainJsPlugin((opts) => {
let statVersion: '1' | '2' = '1' let statVersion: '1' | '2' = '1'
...@@ -71,6 +77,9 @@ export default () => [ ...@@ -71,6 +77,9 @@ export default () => [
uniStatLog(M['stat.warn.version']) uniStatLog(M['stat.warn.version'])
} else { } else {
uniStatLog(`已开启 uni统计${statVersion}.0 版本`) uniStatLog(`已开启 uni统计${statVersion}.0 版本`)
if(statVersion === '2') {
uniStatDeviceLog('【重要】因 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 { } else {
...@@ -80,6 +89,9 @@ export default () => [ ...@@ -80,6 +89,9 @@ export default () => [
uniStatLog( uniStatLog(
M['stat.warn.tip'].replace('{version}', `${statVersion}.0`) M['stat.warn.tip'].replace('{version}', `${statVersion}.0`)
) )
if(statVersion === '2') {
uniStatDeviceLog('【重要】因 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')
}
} }
} }
} }
......
import { sys } from './util.js' import { sys } from './util.js'
import { STAT_URL, STAT_VERSION, DIFF_TIME } from '../config.ts' import { STAT_URL, STAT_VERSION, DIFF_TIME } from '../config.ts'
import {
dbGet,
dbSet,
} from './db.js'
// 获取 manifest.json 中统计配置 // 获取 manifest.json 中统计配置
const uniStatisticsConfig = process.env.UNI_STATISTICS_CONFIG const uniStatisticsConfig = process.env.UNI_STATISTICS_CONFIG
let statConfig = { let statConfig = {
...@@ -70,6 +73,24 @@ export const get_uuid = (statData) => { ...@@ -70,6 +73,24 @@ export const get_uuid = (statData) => {
return sys.deviceId || getUuid() return sys.deviceId || getUuid()
} }
/**
* 获取老版的 deviceid ,兼容以前的错误 deviceid
* @param {*} statData
* @returns
*/
export 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 * 获取配置信息 如 appid
*/ */
...@@ -550,3 +571,14 @@ export const is_push_clientid = () => { ...@@ -550,3 +571,14 @@ export const is_push_clientid = () => {
} }
return false return false
} }
/**
* 是否已处理设备 DeviceId
* 如果值为 1 则表示已处理
*/
const IS_HANDLE_DEVECE_ID = 'is_handle_device_id'
export const is_handle_device = () => {
let isHandleDevice = dbGet(IS_HANDLE_DEVECE_ID) || ''
dbSet(IS_HANDLE_DEVECE_ID, '1')
return isHandleDevice === '1'
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册