提交 a9ad3ff8 编写于 作者: M mehaotian

fix(stat): 统计1.0 缺失 ak uuid p 等字段

上级 18d6b554
...@@ -21,9 +21,10 @@ let titleJsons = {}; ...@@ -21,9 +21,10 @@ let titleJsons = {};
let debug = !!process.env.UNI_STAT_DEBUG || false; let debug = !!process.env.UNI_STAT_DEBUG || false;
// #ifdef VUE3 // #ifdef VUE3
titleJsons = process.env.UNI_STAT_TITLE_JSON; titleJsons = process.env.UNI_STAT_TITLE_JSON;
// #endif // #endif
// #ifndef VUE3 // #ifndef VUE3
// eslint-disable-next-line no-restricted-globals // eslint-disable-next-line no-restricted-globals
const pagesTitle = require('uni-pages?{"type":"style"}').default; const pagesTitle = require('uni-pages?{"type":"style"}').default;
let pagesData = pagesTitle.pages; let pagesData = pagesTitle.pages;
...@@ -44,39 +45,40 @@ for (let i in pagesData) { ...@@ -44,39 +45,40 @@ for (let i in pagesData) {
// #endif // #endif
// TODO 在云函数中获取,暂时注释 // TODO 在云函数中获取,暂时注释
// const UUID_KEY = '__DC_STAT_UUID' const UUID_KEY = '__DC_STAT_UUID';
// const UUID_VALUE = '__DC_UUID_VALUE' const UUID_VALUE = '__DC_UUID_VALUE';
// function getUuid() { function getUuid() {
// let uuid = '' let uuid = '';
// if (get_platform_name() === 'n') { if (get_platform_name() === 'n') {
// try { try {
// uuid = plus.runtime.getDCloudId() uuid = plus.runtime.getDCloudId();
// } catch (e) { } catch (e) {
// uuid = '' uuid = '';
// } }
// return uuid return uuid
// } }
// try { try {
// uuid = uni.getStorageSync(UUID_KEY) uuid = uni.getStorageSync(UUID_KEY);
// } catch (e) { } catch (e) {
// uuid = UUID_VALUE uuid = UUID_VALUE;
// } }
// if (!uuid) { if (!uuid) {
// uuid = Date.now() + '' + Math.floor(Math.random() * 1e7) uuid = Date.now() + '' + Math.floor(Math.random() * 1e7);
// try { try {
// uni.setStorageSync(UUID_KEY, uuid) uni.setStorageSync(UUID_KEY, uuid);
// } catch (e) { } catch (e) {
// uni.setStorageSync(UUID_KEY, UUID_VALUE) uni.setStorageSync(UUID_KEY, UUID_VALUE);
// } }
// } }
// return uuid return uuid
// } }
// export const get_uuid = (statData) => {
// // 有可能不存在 deviceId(一般不存在就是出bug了),就自己生成一个 const get_uuid = (statData) => {
// return sys.deviceId || getUuid() // 有可能不存在 deviceId(一般不存在就是出bug了),就自己生成一个
// } return sys.deviceId || getUuid()
};
/** /**
* 获取配置信息 如 appid * 获取配置信息 如 appid
...@@ -561,15 +563,15 @@ const get_first_visit_time = () => { ...@@ -561,15 +563,15 @@ const get_first_visit_time = () => {
time = timeStorge; time = timeStorge;
} else { } else {
time = get_time(); time = get_time();
dbSet(FIRST_VISIT_TIME_KEY, time); dbSet(FIRST_VISIT_TIME_KEY, time);
// 首次访问需要 将最后访问时间置 0 // 首次访问需要 将最后访问时间置 0
dbRemove(LAST_VISIT_TIME_KEY); dbRemove(LAST_VISIT_TIME_KEY);
} }
return time return time
}; };
/** /**
* 最后访问时间 * 最后访问时间
*/ */
const get_last_visit_time = () => { const get_last_visit_time = () => {
const timeStorge = dbGet(LAST_VISIT_TIME_KEY); const timeStorge = dbGet(LAST_VISIT_TIME_KEY);
...@@ -600,20 +602,20 @@ const set_page_residence_time = () => { ...@@ -600,20 +602,20 @@ const set_page_residence_time = () => {
*/ */
const get_page_residence_time = () => { const get_page_residence_time = () => {
Last_Page_Residence_Time = get_time(); Last_Page_Residence_Time = get_time();
First_Page_Residence_Time = dbGet(PAGE_RESIDENCE_TIME); First_Page_Residence_Time = dbGet(PAGE_RESIDENCE_TIME);
return Last_Page_Residence_Time - First_Page_Residence_Time return Last_Page_Residence_Time - First_Page_Residence_Time
}; };
/** /**
* 获取总访问次数 * 获取总访问次数
*/ */
const TOTAL_VISIT_COUNT = '__total__visit__count'; const TOTAL_VISIT_COUNT = '__total__visit__count';
const get_total_visit_count = () => { const get_total_visit_count = () => {
const timeStorge = dbGet(TOTAL_VISIT_COUNT); const timeStorge = dbGet(TOTAL_VISIT_COUNT);
let count = 1; let count = 1;
if (timeStorge) { if (timeStorge) {
count = timeStorge; count = timeStorge;
count++; count++;
} }
dbSet(TOTAL_VISIT_COUNT, count); dbSet(TOTAL_VISIT_COUNT, count);
return count return count
...@@ -621,9 +623,9 @@ const get_total_visit_count = () => { ...@@ -621,9 +623,9 @@ const get_total_visit_count = () => {
let Set__First__Time = 0; let Set__First__Time = 0;
let Set__Last__Time = 0; let Set__Last__Time = 0;
/** /**
* 获取第一次时间 * 获取第一次时间
*/ */
const get_first_time = () => { const get_first_time = () => {
let time = new Date().getTime(); let time = new Date().getTime();
...@@ -632,8 +634,8 @@ const get_first_time = () => { ...@@ -632,8 +634,8 @@ const get_first_time = () => {
return time return time
}; };
/** /**
* 获取最后一次时间 * 获取最后一次时间
*/ */
const get_last_time = () => { const get_last_time = () => {
let time = new Date().getTime(); let time = new Date().getTime();
...@@ -641,16 +643,16 @@ const get_last_time = () => { ...@@ -641,16 +643,16 @@ const get_last_time = () => {
return time return time
}; };
/** /**
* 获取页面 \ 应用停留时间 * 获取页面 \ 应用停留时间
*/ */
const get_residence_time = (type) => { const get_residence_time = (type) => {
let residenceTime = 0; let residenceTime = 0;
if (Set__First__Time !== 0) { if (Set__First__Time !== 0) {
residenceTime = Set__Last__Time - Set__First__Time; residenceTime = Set__Last__Time - Set__First__Time;
} }
residenceTime = parseInt(residenceTime / 1000); residenceTime = parseInt(residenceTime / 1000);
residenceTime = residenceTime < 1 ? 1 : residenceTime; residenceTime = residenceTime < 1 ? 1 : residenceTime;
if (type === 'app') { if (type === 'app') {
let overtime = residenceTime > APP_PVER_TIME ? true : false; let overtime = residenceTime > APP_PVER_TIME ? true : false;
...@@ -673,9 +675,9 @@ const get_residence_time = (type) => { ...@@ -673,9 +675,9 @@ const get_residence_time = (type) => {
// 统计数据默认值 // 统计数据默认值
let statData = { let statData = {
// uuid: get_uuid(), // 设备标识 uuid: get_uuid(), // 设备标识
// ak: stat_config.appid, // uni-app 应用 Appid ak: stat_config.appid, // uni-app 应用 Appid
// p: sys.platform === 'android' ? 'a' : 'i', // 手机系统 p: sys.platform === 'android' ? 'a' : 'i', // 手机系统
ut: get_platform_name(), // 平台类型 ut: get_platform_name(), // 平台类型
mpn: get_pack_name(), // 原生平台包名、小程序 appid mpn: get_pack_name(), // 原生平台包名、小程序 appid
usv: STAT_VERSION, // 统计 sdk 版本 usv: STAT_VERSION, // 统计 sdk 版本
...@@ -948,9 +950,9 @@ class Report { ...@@ -948,9 +950,9 @@ class Report {
let { url, urlref, urlref_ts } = opt; let { url, urlref, urlref_ts } = opt;
this._navigationBarTitle.lt = '11'; this._navigationBarTitle.lt = '11';
let options = { let options = {
// ak: this.statData.ak, ak: this.statData.ak,
// uuid: this.statData.uuid, uuid: this.statData.uuid,
// p: this.statData.p, p: this.statData.p,
lt: '11', lt: '11',
ut: this.statData.ut, ut: this.statData.ut,
url, url,
...@@ -972,9 +974,9 @@ class Report { ...@@ -972,9 +974,9 @@ class Report {
sendHideRequest(opt, type) { sendHideRequest(opt, type) {
let { urlref, urlref_ts } = opt; let { urlref, urlref_ts } = opt;
let options = { let options = {
// ak: this.statData.ak, ak: this.statData.ak,
// uuid: this.statData.uuid, uuid: this.statData.uuid,
// p: this.statData.p, p: this.statData.p,
lt: '3', lt: '3',
ut: this.statData.ut, ut: this.statData.ut,
urlref, urlref,
...@@ -995,9 +997,9 @@ class Report { ...@@ -995,9 +997,9 @@ class Report {
this._navigationBarTitle.config = get_page_name(routepath); this._navigationBarTitle.config = get_page_name(routepath);
this._navigationBarTitle.lt = '21'; this._navigationBarTitle.lt = '21';
let options = { let options = {
// ak: this.statData.ak, ak: this.statData.ak,
// uuid: this.statData.uuid, uuid: this.statData.uuid,
// p: this.statData.p, p: this.statData.p,
lt: '21', lt: '21',
ut: this.statData.ut, ut: this.statData.ut,
url: routepath, url: routepath,
...@@ -1297,9 +1299,9 @@ class Stat extends Report { ...@@ -1297,9 +1299,9 @@ class Stat extends Report {
emVal = em.stack; emVal = em.stack;
} }
let options = { let options = {
// ak: this.statData.ak, ak: this.statData.ak,
// uuid: this.statData.uuid, uuid: this.statData.uuid,
// p: this.statData.p, p: this.statData.p,
lt: '31', lt: '31',
ut: this.statData.ut, ut: this.statData.ut,
ch: this.statData.ch, ch: this.statData.ch,
......
...@@ -19,9 +19,10 @@ let titleJsons = {}; ...@@ -19,9 +19,10 @@ let titleJsons = {};
let debug = !!process.env.UNI_STAT_DEBUG || false; let debug = !!process.env.UNI_STAT_DEBUG || false;
// #ifdef VUE3 // #ifdef VUE3
titleJsons = process.env.UNI_STAT_TITLE_JSON; titleJsons = process.env.UNI_STAT_TITLE_JSON;
// #endif // #endif
// #ifndef VUE3 // #ifndef VUE3
// eslint-disable-next-line no-restricted-globals // eslint-disable-next-line no-restricted-globals
const pagesTitle = require('uni-pages?{"type":"style"}').default; const pagesTitle = require('uni-pages?{"type":"style"}').default;
let pagesData = pagesTitle.pages; let pagesData = pagesTitle.pages;
...@@ -42,39 +43,40 @@ for (let i in pagesData) { ...@@ -42,39 +43,40 @@ for (let i in pagesData) {
// #endif // #endif
// TODO 在云函数中获取,暂时注释 // TODO 在云函数中获取,暂时注释
// const UUID_KEY = '__DC_STAT_UUID' const UUID_KEY = '__DC_STAT_UUID';
// const UUID_VALUE = '__DC_UUID_VALUE' const UUID_VALUE = '__DC_UUID_VALUE';
// function getUuid() { function getUuid() {
// let uuid = '' let uuid = '';
// if (get_platform_name() === 'n') { if (get_platform_name() === 'n') {
// try { try {
// uuid = plus.runtime.getDCloudId() uuid = plus.runtime.getDCloudId();
// } catch (e) { } catch (e) {
// uuid = '' uuid = '';
// } }
// return uuid return uuid
// } }
// try { try {
// uuid = uni.getStorageSync(UUID_KEY) uuid = uni.getStorageSync(UUID_KEY);
// } catch (e) { } catch (e) {
// uuid = UUID_VALUE uuid = UUID_VALUE;
// } }
// if (!uuid) { if (!uuid) {
// uuid = Date.now() + '' + Math.floor(Math.random() * 1e7) uuid = Date.now() + '' + Math.floor(Math.random() * 1e7);
// try { try {
// uni.setStorageSync(UUID_KEY, uuid) uni.setStorageSync(UUID_KEY, uuid);
// } catch (e) { } catch (e) {
// uni.setStorageSync(UUID_KEY, UUID_VALUE) uni.setStorageSync(UUID_KEY, UUID_VALUE);
// } }
// } }
// return uuid return uuid
// } }
// export const get_uuid = (statData) => {
// // 有可能不存在 deviceId(一般不存在就是出bug了),就自己生成一个 const get_uuid = (statData) => {
// return sys.deviceId || getUuid() // 有可能不存在 deviceId(一般不存在就是出bug了),就自己生成一个
// } return sys.deviceId || getUuid()
};
/** /**
* 获取配置信息 如 appid * 获取配置信息 如 appid
...@@ -559,15 +561,15 @@ const get_first_visit_time = () => { ...@@ -559,15 +561,15 @@ const get_first_visit_time = () => {
time = timeStorge; time = timeStorge;
} else { } else {
time = get_time(); time = get_time();
dbSet(FIRST_VISIT_TIME_KEY, time); dbSet(FIRST_VISIT_TIME_KEY, time);
// 首次访问需要 将最后访问时间置 0 // 首次访问需要 将最后访问时间置 0
dbRemove(LAST_VISIT_TIME_KEY); dbRemove(LAST_VISIT_TIME_KEY);
} }
return time return time
}; };
/** /**
* 最后访问时间 * 最后访问时间
*/ */
const get_last_visit_time = () => { const get_last_visit_time = () => {
const timeStorge = dbGet(LAST_VISIT_TIME_KEY); const timeStorge = dbGet(LAST_VISIT_TIME_KEY);
...@@ -598,20 +600,20 @@ const set_page_residence_time = () => { ...@@ -598,20 +600,20 @@ const set_page_residence_time = () => {
*/ */
const get_page_residence_time = () => { const get_page_residence_time = () => {
Last_Page_Residence_Time = get_time(); Last_Page_Residence_Time = get_time();
First_Page_Residence_Time = dbGet(PAGE_RESIDENCE_TIME); First_Page_Residence_Time = dbGet(PAGE_RESIDENCE_TIME);
return Last_Page_Residence_Time - First_Page_Residence_Time return Last_Page_Residence_Time - First_Page_Residence_Time
}; };
/** /**
* 获取总访问次数 * 获取总访问次数
*/ */
const TOTAL_VISIT_COUNT = '__total__visit__count'; const TOTAL_VISIT_COUNT = '__total__visit__count';
const get_total_visit_count = () => { const get_total_visit_count = () => {
const timeStorge = dbGet(TOTAL_VISIT_COUNT); const timeStorge = dbGet(TOTAL_VISIT_COUNT);
let count = 1; let count = 1;
if (timeStorge) { if (timeStorge) {
count = timeStorge; count = timeStorge;
count++; count++;
} }
dbSet(TOTAL_VISIT_COUNT, count); dbSet(TOTAL_VISIT_COUNT, count);
return count return count
...@@ -619,9 +621,9 @@ const get_total_visit_count = () => { ...@@ -619,9 +621,9 @@ const get_total_visit_count = () => {
let Set__First__Time = 0; let Set__First__Time = 0;
let Set__Last__Time = 0; let Set__Last__Time = 0;
/** /**
* 获取第一次时间 * 获取第一次时间
*/ */
const get_first_time = () => { const get_first_time = () => {
let time = new Date().getTime(); let time = new Date().getTime();
...@@ -630,8 +632,8 @@ const get_first_time = () => { ...@@ -630,8 +632,8 @@ const get_first_time = () => {
return time return time
}; };
/** /**
* 获取最后一次时间 * 获取最后一次时间
*/ */
const get_last_time = () => { const get_last_time = () => {
let time = new Date().getTime(); let time = new Date().getTime();
...@@ -639,16 +641,16 @@ const get_last_time = () => { ...@@ -639,16 +641,16 @@ const get_last_time = () => {
return time return time
}; };
/** /**
* 获取页面 \ 应用停留时间 * 获取页面 \ 应用停留时间
*/ */
const get_residence_time = (type) => { const get_residence_time = (type) => {
let residenceTime = 0; let residenceTime = 0;
if (Set__First__Time !== 0) { if (Set__First__Time !== 0) {
residenceTime = Set__Last__Time - Set__First__Time; residenceTime = Set__Last__Time - Set__First__Time;
} }
residenceTime = parseInt(residenceTime / 1000); residenceTime = parseInt(residenceTime / 1000);
residenceTime = residenceTime < 1 ? 1 : residenceTime; residenceTime = residenceTime < 1 ? 1 : residenceTime;
if (type === 'app') { if (type === 'app') {
let overtime = residenceTime > APP_PVER_TIME ? true : false; let overtime = residenceTime > APP_PVER_TIME ? true : false;
...@@ -671,9 +673,9 @@ const get_residence_time = (type) => { ...@@ -671,9 +673,9 @@ const get_residence_time = (type) => {
// 统计数据默认值 // 统计数据默认值
let statData = { let statData = {
// uuid: get_uuid(), // 设备标识 uuid: get_uuid(), // 设备标识
// ak: stat_config.appid, // uni-app 应用 Appid ak: stat_config.appid, // uni-app 应用 Appid
// p: sys.platform === 'android' ? 'a' : 'i', // 手机系统 p: sys.platform === 'android' ? 'a' : 'i', // 手机系统
ut: get_platform_name(), // 平台类型 ut: get_platform_name(), // 平台类型
mpn: get_pack_name(), // 原生平台包名、小程序 appid mpn: get_pack_name(), // 原生平台包名、小程序 appid
usv: STAT_VERSION, // 统计 sdk 版本 usv: STAT_VERSION, // 统计 sdk 版本
...@@ -946,9 +948,9 @@ class Report { ...@@ -946,9 +948,9 @@ class Report {
let { url, urlref, urlref_ts } = opt; let { url, urlref, urlref_ts } = opt;
this._navigationBarTitle.lt = '11'; this._navigationBarTitle.lt = '11';
let options = { let options = {
// ak: this.statData.ak, ak: this.statData.ak,
// uuid: this.statData.uuid, uuid: this.statData.uuid,
// p: this.statData.p, p: this.statData.p,
lt: '11', lt: '11',
ut: this.statData.ut, ut: this.statData.ut,
url, url,
...@@ -970,9 +972,9 @@ class Report { ...@@ -970,9 +972,9 @@ class Report {
sendHideRequest(opt, type) { sendHideRequest(opt, type) {
let { urlref, urlref_ts } = opt; let { urlref, urlref_ts } = opt;
let options = { let options = {
// ak: this.statData.ak, ak: this.statData.ak,
// uuid: this.statData.uuid, uuid: this.statData.uuid,
// p: this.statData.p, p: this.statData.p,
lt: '3', lt: '3',
ut: this.statData.ut, ut: this.statData.ut,
urlref, urlref,
...@@ -993,9 +995,9 @@ class Report { ...@@ -993,9 +995,9 @@ class Report {
this._navigationBarTitle.config = get_page_name(routepath); this._navigationBarTitle.config = get_page_name(routepath);
this._navigationBarTitle.lt = '21'; this._navigationBarTitle.lt = '21';
let options = { let options = {
// ak: this.statData.ak, ak: this.statData.ak,
// uuid: this.statData.uuid, uuid: this.statData.uuid,
// p: this.statData.p, p: this.statData.p,
lt: '21', lt: '21',
ut: this.statData.ut, ut: this.statData.ut,
url: routepath, url: routepath,
...@@ -1295,9 +1297,9 @@ class Stat extends Report { ...@@ -1295,9 +1297,9 @@ class Stat extends Report {
emVal = em.stack; emVal = em.stack;
} }
let options = { let options = {
// ak: this.statData.ak, ak: this.statData.ak,
// uuid: this.statData.uuid, uuid: this.statData.uuid,
// p: this.statData.p, p: this.statData.p,
lt: '31', lt: '31',
ut: this.statData.ut, ut: this.statData.ut,
ch: this.statData.ch, ch: this.statData.ch,
......
...@@ -21,9 +21,10 @@ let titleJsons = {}; ...@@ -21,9 +21,10 @@ let titleJsons = {};
let debug = !!process.env.UNI_STAT_DEBUG || false; let debug = !!process.env.UNI_STAT_DEBUG || false;
// #ifdef VUE3 // #ifdef VUE3
titleJsons = process.env.UNI_STAT_TITLE_JSON; titleJsons = process.env.UNI_STAT_TITLE_JSON;
// #endif // #endif
// #ifndef VUE3 // #ifndef VUE3
// eslint-disable-next-line no-restricted-globals // eslint-disable-next-line no-restricted-globals
const pagesTitle = require('uni-pages?{"type":"style"}').default; const pagesTitle = require('uni-pages?{"type":"style"}').default;
let pagesData = pagesTitle.pages; let pagesData = pagesTitle.pages;
...@@ -44,39 +45,40 @@ for (let i in pagesData) { ...@@ -44,39 +45,40 @@ for (let i in pagesData) {
// #endif // #endif
// TODO 在云函数中获取,暂时注释 // TODO 在云函数中获取,暂时注释
// const UUID_KEY = '__DC_STAT_UUID' const UUID_KEY = '__DC_STAT_UUID';
// const UUID_VALUE = '__DC_UUID_VALUE' const UUID_VALUE = '__DC_UUID_VALUE';
// function getUuid() { function getUuid() {
// let uuid = '' let uuid = '';
// if (get_platform_name() === 'n') { if (get_platform_name() === 'n') {
// try { try {
// uuid = plus.runtime.getDCloudId() uuid = plus.runtime.getDCloudId();
// } catch (e) { } catch (e) {
// uuid = '' uuid = '';
// } }
// return uuid return uuid
// } }
// try { try {
// uuid = uni.getStorageSync(UUID_KEY) uuid = uni.getStorageSync(UUID_KEY);
// } catch (e) { } catch (e) {
// uuid = UUID_VALUE uuid = UUID_VALUE;
// } }
// if (!uuid) { if (!uuid) {
// uuid = Date.now() + '' + Math.floor(Math.random() * 1e7) uuid = Date.now() + '' + Math.floor(Math.random() * 1e7);
// try { try {
// uni.setStorageSync(UUID_KEY, uuid) uni.setStorageSync(UUID_KEY, uuid);
// } catch (e) { } catch (e) {
// uni.setStorageSync(UUID_KEY, UUID_VALUE) uni.setStorageSync(UUID_KEY, UUID_VALUE);
// } }
// } }
// return uuid return uuid
// } }
// export const get_uuid = (statData) => {
// // 有可能不存在 deviceId(一般不存在就是出bug了),就自己生成一个 const get_uuid = (statData) => {
// return sys.deviceId || getUuid() // 有可能不存在 deviceId(一般不存在就是出bug了),就自己生成一个
// } return sys.deviceId || getUuid()
};
/** /**
* 获取配置信息 如 appid * 获取配置信息 如 appid
...@@ -529,15 +531,15 @@ const get_first_visit_time = () => { ...@@ -529,15 +531,15 @@ const get_first_visit_time = () => {
time = timeStorge; time = timeStorge;
} else { } else {
time = get_time(); time = get_time();
dbSet(FIRST_VISIT_TIME_KEY, time); dbSet(FIRST_VISIT_TIME_KEY, time);
// 首次访问需要 将最后访问时间置 0 // 首次访问需要 将最后访问时间置 0
dbRemove(LAST_VISIT_TIME_KEY); dbRemove(LAST_VISIT_TIME_KEY);
} }
return time return time
}; };
/** /**
* 最后访问时间 * 最后访问时间
*/ */
const get_last_visit_time = () => { const get_last_visit_time = () => {
const timeStorge = dbGet(LAST_VISIT_TIME_KEY); const timeStorge = dbGet(LAST_VISIT_TIME_KEY);
...@@ -568,20 +570,20 @@ const set_page_residence_time = () => { ...@@ -568,20 +570,20 @@ const set_page_residence_time = () => {
*/ */
const get_page_residence_time = () => { const get_page_residence_time = () => {
Last_Page_Residence_Time = get_time(); Last_Page_Residence_Time = get_time();
First_Page_Residence_Time = dbGet(PAGE_RESIDENCE_TIME); First_Page_Residence_Time = dbGet(PAGE_RESIDENCE_TIME);
return Last_Page_Residence_Time - First_Page_Residence_Time return Last_Page_Residence_Time - First_Page_Residence_Time
}; };
/** /**
* 获取总访问次数 * 获取总访问次数
*/ */
const TOTAL_VISIT_COUNT = '__total__visit__count'; const TOTAL_VISIT_COUNT = '__total__visit__count';
const get_total_visit_count = () => { const get_total_visit_count = () => {
const timeStorge = dbGet(TOTAL_VISIT_COUNT); const timeStorge = dbGet(TOTAL_VISIT_COUNT);
let count = 1; let count = 1;
if (timeStorge) { if (timeStorge) {
count = timeStorge; count = timeStorge;
count++; count++;
} }
dbSet(TOTAL_VISIT_COUNT, count); dbSet(TOTAL_VISIT_COUNT, count);
return count return count
...@@ -589,9 +591,9 @@ const get_total_visit_count = () => { ...@@ -589,9 +591,9 @@ const get_total_visit_count = () => {
let Set__First__Time = 0; let Set__First__Time = 0;
let Set__Last__Time = 0; let Set__Last__Time = 0;
/** /**
* 获取第一次时间 * 获取第一次时间
*/ */
const get_first_time = () => { const get_first_time = () => {
let time = new Date().getTime(); let time = new Date().getTime();
...@@ -600,8 +602,8 @@ const get_first_time = () => { ...@@ -600,8 +602,8 @@ const get_first_time = () => {
return time return time
}; };
/** /**
* 获取最后一次时间 * 获取最后一次时间
*/ */
const get_last_time = () => { const get_last_time = () => {
let time = new Date().getTime(); let time = new Date().getTime();
...@@ -609,16 +611,16 @@ const get_last_time = () => { ...@@ -609,16 +611,16 @@ const get_last_time = () => {
return time return time
}; };
/** /**
* 获取页面 \ 应用停留时间 * 获取页面 \ 应用停留时间
*/ */
const get_residence_time = (type) => { const get_residence_time = (type) => {
let residenceTime = 0; let residenceTime = 0;
if (Set__First__Time !== 0) { if (Set__First__Time !== 0) {
residenceTime = Set__Last__Time - Set__First__Time; residenceTime = Set__Last__Time - Set__First__Time;
} }
residenceTime = parseInt(residenceTime / 1000); residenceTime = parseInt(residenceTime / 1000);
residenceTime = residenceTime < 1 ? 1 : residenceTime; residenceTime = residenceTime < 1 ? 1 : residenceTime;
if (type === 'app') { if (type === 'app') {
let overtime = residenceTime > APP_PVER_TIME ? true : false; let overtime = residenceTime > APP_PVER_TIME ? true : false;
...@@ -641,9 +643,9 @@ const get_residence_time = (type) => { ...@@ -641,9 +643,9 @@ const get_residence_time = (type) => {
// 统计数据默认值 // 统计数据默认值
let statData = { let statData = {
// uuid: get_uuid(), // 设备标识 uuid: get_uuid(), // 设备标识
// ak: stat_config.appid, // uni-app 应用 Appid ak: stat_config.appid, // uni-app 应用 Appid
// p: sys.platform === 'android' ? 'a' : 'i', // 手机系统 p: sys.platform === 'android' ? 'a' : 'i', // 手机系统
ut: get_platform_name(), // 平台类型 ut: get_platform_name(), // 平台类型
mpn: get_pack_name(), // 原生平台包名、小程序 appid mpn: get_pack_name(), // 原生平台包名、小程序 appid
usv: STAT_VERSION, // 统计 sdk 版本 usv: STAT_VERSION, // 统计 sdk 版本
...@@ -916,9 +918,9 @@ class Report { ...@@ -916,9 +918,9 @@ class Report {
let { url, urlref, urlref_ts } = opt; let { url, urlref, urlref_ts } = opt;
this._navigationBarTitle.lt = '11'; this._navigationBarTitle.lt = '11';
let options = { let options = {
// ak: this.statData.ak, ak: this.statData.ak,
// uuid: this.statData.uuid, uuid: this.statData.uuid,
// p: this.statData.p, p: this.statData.p,
lt: '11', lt: '11',
ut: this.statData.ut, ut: this.statData.ut,
url, url,
...@@ -940,9 +942,9 @@ class Report { ...@@ -940,9 +942,9 @@ class Report {
sendHideRequest(opt, type) { sendHideRequest(opt, type) {
let { urlref, urlref_ts } = opt; let { urlref, urlref_ts } = opt;
let options = { let options = {
// ak: this.statData.ak, ak: this.statData.ak,
// uuid: this.statData.uuid, uuid: this.statData.uuid,
// p: this.statData.p, p: this.statData.p,
lt: '3', lt: '3',
ut: this.statData.ut, ut: this.statData.ut,
urlref, urlref,
...@@ -963,9 +965,9 @@ class Report { ...@@ -963,9 +965,9 @@ class Report {
this._navigationBarTitle.config = get_page_name(routepath); this._navigationBarTitle.config = get_page_name(routepath);
this._navigationBarTitle.lt = '21'; this._navigationBarTitle.lt = '21';
let options = { let options = {
// ak: this.statData.ak, ak: this.statData.ak,
// uuid: this.statData.uuid, uuid: this.statData.uuid,
// p: this.statData.p, p: this.statData.p,
lt: '21', lt: '21',
ut: this.statData.ut, ut: this.statData.ut,
url: routepath, url: routepath,
...@@ -1253,9 +1255,9 @@ class Stat extends Report { ...@@ -1253,9 +1255,9 @@ class Stat extends Report {
emVal = em.stack; emVal = em.stack;
} }
let options = { let options = {
// ak: this.statData.ak, ak: this.statData.ak,
// uuid: this.statData.uuid, uuid: this.statData.uuid,
// p: this.statData.p, p: this.statData.p,
lt: '31', lt: '31',
ut: this.statData.ut, ut: this.statData.ut,
ch: this.statData.ch, ch: this.statData.ch,
......
...@@ -19,9 +19,10 @@ let titleJsons = {}; ...@@ -19,9 +19,10 @@ let titleJsons = {};
let debug = !!process.env.UNI_STAT_DEBUG || false; let debug = !!process.env.UNI_STAT_DEBUG || false;
// #ifdef VUE3 // #ifdef VUE3
titleJsons = process.env.UNI_STAT_TITLE_JSON; titleJsons = process.env.UNI_STAT_TITLE_JSON;
// #endif // #endif
// #ifndef VUE3 // #ifndef VUE3
// eslint-disable-next-line no-restricted-globals // eslint-disable-next-line no-restricted-globals
const pagesTitle = require('uni-pages?{"type":"style"}').default; const pagesTitle = require('uni-pages?{"type":"style"}').default;
let pagesData = pagesTitle.pages; let pagesData = pagesTitle.pages;
...@@ -42,39 +43,40 @@ for (let i in pagesData) { ...@@ -42,39 +43,40 @@ for (let i in pagesData) {
// #endif // #endif
// TODO 在云函数中获取,暂时注释 // TODO 在云函数中获取,暂时注释
// const UUID_KEY = '__DC_STAT_UUID' const UUID_KEY = '__DC_STAT_UUID';
// const UUID_VALUE = '__DC_UUID_VALUE' const UUID_VALUE = '__DC_UUID_VALUE';
// function getUuid() { function getUuid() {
// let uuid = '' let uuid = '';
// if (get_platform_name() === 'n') { if (get_platform_name() === 'n') {
// try { try {
// uuid = plus.runtime.getDCloudId() uuid = plus.runtime.getDCloudId();
// } catch (e) { } catch (e) {
// uuid = '' uuid = '';
// } }
// return uuid return uuid
// } }
// try { try {
// uuid = uni.getStorageSync(UUID_KEY) uuid = uni.getStorageSync(UUID_KEY);
// } catch (e) { } catch (e) {
// uuid = UUID_VALUE uuid = UUID_VALUE;
// } }
// if (!uuid) { if (!uuid) {
// uuid = Date.now() + '' + Math.floor(Math.random() * 1e7) uuid = Date.now() + '' + Math.floor(Math.random() * 1e7);
// try { try {
// uni.setStorageSync(UUID_KEY, uuid) uni.setStorageSync(UUID_KEY, uuid);
// } catch (e) { } catch (e) {
// uni.setStorageSync(UUID_KEY, UUID_VALUE) uni.setStorageSync(UUID_KEY, UUID_VALUE);
// } }
// } }
// return uuid return uuid
// } }
// export const get_uuid = (statData) => {
// // 有可能不存在 deviceId(一般不存在就是出bug了),就自己生成一个 const get_uuid = (statData) => {
// return sys.deviceId || getUuid() // 有可能不存在 deviceId(一般不存在就是出bug了),就自己生成一个
// } return sys.deviceId || getUuid()
};
/** /**
* 获取配置信息 如 appid * 获取配置信息 如 appid
...@@ -527,15 +529,15 @@ const get_first_visit_time = () => { ...@@ -527,15 +529,15 @@ const get_first_visit_time = () => {
time = timeStorge; time = timeStorge;
} else { } else {
time = get_time(); time = get_time();
dbSet(FIRST_VISIT_TIME_KEY, time); dbSet(FIRST_VISIT_TIME_KEY, time);
// 首次访问需要 将最后访问时间置 0 // 首次访问需要 将最后访问时间置 0
dbRemove(LAST_VISIT_TIME_KEY); dbRemove(LAST_VISIT_TIME_KEY);
} }
return time return time
}; };
/** /**
* 最后访问时间 * 最后访问时间
*/ */
const get_last_visit_time = () => { const get_last_visit_time = () => {
const timeStorge = dbGet(LAST_VISIT_TIME_KEY); const timeStorge = dbGet(LAST_VISIT_TIME_KEY);
...@@ -566,20 +568,20 @@ const set_page_residence_time = () => { ...@@ -566,20 +568,20 @@ const set_page_residence_time = () => {
*/ */
const get_page_residence_time = () => { const get_page_residence_time = () => {
Last_Page_Residence_Time = get_time(); Last_Page_Residence_Time = get_time();
First_Page_Residence_Time = dbGet(PAGE_RESIDENCE_TIME); First_Page_Residence_Time = dbGet(PAGE_RESIDENCE_TIME);
return Last_Page_Residence_Time - First_Page_Residence_Time return Last_Page_Residence_Time - First_Page_Residence_Time
}; };
/** /**
* 获取总访问次数 * 获取总访问次数
*/ */
const TOTAL_VISIT_COUNT = '__total__visit__count'; const TOTAL_VISIT_COUNT = '__total__visit__count';
const get_total_visit_count = () => { const get_total_visit_count = () => {
const timeStorge = dbGet(TOTAL_VISIT_COUNT); const timeStorge = dbGet(TOTAL_VISIT_COUNT);
let count = 1; let count = 1;
if (timeStorge) { if (timeStorge) {
count = timeStorge; count = timeStorge;
count++; count++;
} }
dbSet(TOTAL_VISIT_COUNT, count); dbSet(TOTAL_VISIT_COUNT, count);
return count return count
...@@ -587,9 +589,9 @@ const get_total_visit_count = () => { ...@@ -587,9 +589,9 @@ const get_total_visit_count = () => {
let Set__First__Time = 0; let Set__First__Time = 0;
let Set__Last__Time = 0; let Set__Last__Time = 0;
/** /**
* 获取第一次时间 * 获取第一次时间
*/ */
const get_first_time = () => { const get_first_time = () => {
let time = new Date().getTime(); let time = new Date().getTime();
...@@ -598,8 +600,8 @@ const get_first_time = () => { ...@@ -598,8 +600,8 @@ const get_first_time = () => {
return time return time
}; };
/** /**
* 获取最后一次时间 * 获取最后一次时间
*/ */
const get_last_time = () => { const get_last_time = () => {
let time = new Date().getTime(); let time = new Date().getTime();
...@@ -607,16 +609,16 @@ const get_last_time = () => { ...@@ -607,16 +609,16 @@ const get_last_time = () => {
return time return time
}; };
/** /**
* 获取页面 \ 应用停留时间 * 获取页面 \ 应用停留时间
*/ */
const get_residence_time = (type) => { const get_residence_time = (type) => {
let residenceTime = 0; let residenceTime = 0;
if (Set__First__Time !== 0) { if (Set__First__Time !== 0) {
residenceTime = Set__Last__Time - Set__First__Time; residenceTime = Set__Last__Time - Set__First__Time;
} }
residenceTime = parseInt(residenceTime / 1000); residenceTime = parseInt(residenceTime / 1000);
residenceTime = residenceTime < 1 ? 1 : residenceTime; residenceTime = residenceTime < 1 ? 1 : residenceTime;
if (type === 'app') { if (type === 'app') {
let overtime = residenceTime > APP_PVER_TIME ? true : false; let overtime = residenceTime > APP_PVER_TIME ? true : false;
...@@ -639,9 +641,9 @@ const get_residence_time = (type) => { ...@@ -639,9 +641,9 @@ const get_residence_time = (type) => {
// 统计数据默认值 // 统计数据默认值
let statData = { let statData = {
// uuid: get_uuid(), // 设备标识 uuid: get_uuid(), // 设备标识
// ak: stat_config.appid, // uni-app 应用 Appid ak: stat_config.appid, // uni-app 应用 Appid
// p: sys.platform === 'android' ? 'a' : 'i', // 手机系统 p: sys.platform === 'android' ? 'a' : 'i', // 手机系统
ut: get_platform_name(), // 平台类型 ut: get_platform_name(), // 平台类型
mpn: get_pack_name(), // 原生平台包名、小程序 appid mpn: get_pack_name(), // 原生平台包名、小程序 appid
usv: STAT_VERSION, // 统计 sdk 版本 usv: STAT_VERSION, // 统计 sdk 版本
...@@ -914,9 +916,9 @@ class Report { ...@@ -914,9 +916,9 @@ class Report {
let { url, urlref, urlref_ts } = opt; let { url, urlref, urlref_ts } = opt;
this._navigationBarTitle.lt = '11'; this._navigationBarTitle.lt = '11';
let options = { let options = {
// ak: this.statData.ak, ak: this.statData.ak,
// uuid: this.statData.uuid, uuid: this.statData.uuid,
// p: this.statData.p, p: this.statData.p,
lt: '11', lt: '11',
ut: this.statData.ut, ut: this.statData.ut,
url, url,
...@@ -938,9 +940,9 @@ class Report { ...@@ -938,9 +940,9 @@ class Report {
sendHideRequest(opt, type) { sendHideRequest(opt, type) {
let { urlref, urlref_ts } = opt; let { urlref, urlref_ts } = opt;
let options = { let options = {
// ak: this.statData.ak, ak: this.statData.ak,
// uuid: this.statData.uuid, uuid: this.statData.uuid,
// p: this.statData.p, p: this.statData.p,
lt: '3', lt: '3',
ut: this.statData.ut, ut: this.statData.ut,
urlref, urlref,
...@@ -961,9 +963,9 @@ class Report { ...@@ -961,9 +963,9 @@ class Report {
this._navigationBarTitle.config = get_page_name(routepath); this._navigationBarTitle.config = get_page_name(routepath);
this._navigationBarTitle.lt = '21'; this._navigationBarTitle.lt = '21';
let options = { let options = {
// ak: this.statData.ak, ak: this.statData.ak,
// uuid: this.statData.uuid, uuid: this.statData.uuid,
// p: this.statData.p, p: this.statData.p,
lt: '21', lt: '21',
ut: this.statData.ut, ut: this.statData.ut,
url: routepath, url: routepath,
...@@ -1251,9 +1253,9 @@ class Stat extends Report { ...@@ -1251,9 +1253,9 @@ class Stat extends Report {
emVal = em.stack; emVal = em.stack;
} }
let options = { let options = {
// ak: this.statData.ak, ak: this.statData.ak,
// uuid: this.statData.uuid, uuid: this.statData.uuid,
// p: this.statData.p, p: this.statData.p,
lt: '31', lt: '31',
ut: this.statData.ut, ut: this.statData.ut,
ch: this.statData.ch, ch: this.statData.ch,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册