提交 919c7d4d 编写于 作者: M mehaotian

fix(stat) : 修复路由错误问题,

上级 7ccd61ee
...@@ -237,7 +237,7 @@ const getRoute = () => { ...@@ -237,7 +237,7 @@ const getRoute = () => {
if (getPlatformName() === 'bd') { if (getPlatformName() === 'bd') {
return _self.$mp && _self.$mp.page.is; return _self.$mp && _self.$mp.page.is;
} else { } else {
return _self.$scope && _self.$scope.route || _self.$mp && _self.$mp.page.route; return (_self.$scope && _self.$scope.route) || (_self.$mp && _self.$mp.page.route);
} }
}; };
...@@ -252,12 +252,12 @@ const getPageRoute = (self) => { ...@@ -252,12 +252,12 @@ const getPageRoute = (self) => {
if (getPlatformName() === 'bd') { if (getPlatformName() === 'bd') {
return _self.$mp && _self.$mp.page.is + str; return _self.$mp && _self.$mp.page.is + str;
} else { } else {
return _self.$scope && _self.$scope.route + str || _self.$mp && _self.$mp.page.route + str; return (_self.$scope && _self.$scope.route + str )|| (_self.$mp && _self.$mp.page.route + str);
} }
}; };
const getPageTypes = (self) => { const getPageTypes = (self) => {
if (self.mpType === 'page' || self.$mp && self.$mp.mpType === 'page') { if (self.mpType === 'page' || (self.$mp && self.$mp.mpType === 'page') || self.$options.mpType === 'page') {
return true; return true;
} }
return false; return false;
...@@ -371,8 +371,9 @@ class Util { ...@@ -371,8 +371,9 @@ class Util {
getLastTime(); getLastTime();
const time = getResidenceTime(); const time = getResidenceTime();
getFirstTime(); getFirstTime();
const route = getPageRoute(this);
this._sendHideRequest({ this._sendHideRequest({
urlref: this._lastPageRoute, urlref: route,
urlref_ts: time.residenceTime urlref_ts: time.residenceTime
}, type); }, type);
} }
...@@ -562,20 +563,32 @@ class Util { ...@@ -562,20 +563,32 @@ class Util {
data.ttc = title.report; data.ttc = title.report;
let requestData = this._reportingRequestData; let requestData = this._reportingRequestData;
if (getPlatformName() === 'n') {
requestData = uni.getStorageSync('__UNI__STAT__DATA') || {};
}
if (!requestData[data.lt]) { if (!requestData[data.lt]) {
this._reportingRequestData[data.lt] = []; requestData[data.lt] = [];
}
requestData[data.lt].push(data);
if (getPlatformName() === 'n') {
uni.setStorageSync('__UNI__STAT__DATA', requestData);
} }
this._reportingRequestData[data.lt].push(data);
if (getPageResidenceTime() < OPERATING_TIME && !type) { if (getPageResidenceTime() < OPERATING_TIME && !type) {
return return
} }
let uniStatData = this._reportingRequestData;
if (getPlatformName() === 'n') {
uniStatData = uni.getStorageSync('__UNI__STAT__DATA');
}
// 时间超过,重新获取时间戳 // 时间超过,重新获取时间戳
setPageResidenceTime(); setPageResidenceTime();
let firstArr = []; let firstArr = [];
let contentArr = []; let contentArr = [];
let lastArr = []; let lastArr = [];
for (let i in this._reportingRequestData) {
const rd = this._reportingRequestData[i]; for (let i in uniStatData) {
const rd = uniStatData[i];
rd.forEach((elm) => { rd.forEach((elm) => {
const newData = getSplicing(elm); const newData = getSplicing(elm);
if (i === 0) { if (i === 0) {
...@@ -594,12 +607,18 @@ class Util { ...@@ -594,12 +607,18 @@ class Util {
t: time, //发送请求时的时间戮 t: time, //发送请求时的时间戮
requests: JSON.stringify(firstArr), requests: JSON.stringify(firstArr),
}; };
this._reportingRequestData = {}; this._reportingRequestData = {};
if (getPlatformName() === 'n') {
uni.removeStorageSync('__UNI__STAT__DATA');
}
if (data.ut === 'h5') { if (data.ut === 'h5') {
this.imageRequest(optionsData); this.imageRequest(optionsData);
return return
} }
setTimeout(() => {
uni.request({ uni.request({
url: STAT_URL, url: STAT_URL,
method: 'POST', method: 'POST',
...@@ -620,6 +639,8 @@ class Util { ...@@ -620,6 +639,8 @@ class Util {
} }
} }
}); });
}, 200);
} }
/** /**
* h5 请求 * h5 请求
...@@ -722,6 +743,10 @@ class Stat extends Util { ...@@ -722,6 +743,10 @@ class Stat extends Util {
} }
load(options, self) { load(options, self) {
if (!self.$scope && !self.$mp) {
const page = getCurrentPages();
self.$scope = page[page.length - 1];
}
this.self = self; this.self = self;
this._query = options; this._query = options;
} }
......
{ {
"name": "@dcloudio/uni-stat", "name": "@dcloudio/uni-stat",
"version": "0.0.108", "version": "0.0.111",
"description": "", "description": "",
"main": "dist/index.js", "main": "dist/index.js",
"scripts": { "scripts": {
......
...@@ -236,7 +236,7 @@ export const getRoute = () => { ...@@ -236,7 +236,7 @@ export const getRoute = () => {
if (getPlatformName() === 'bd') { if (getPlatformName() === 'bd') {
return _self.$mp && _self.$mp.page.is; return _self.$mp && _self.$mp.page.is;
} else { } else {
return _self.$scope && _self.$scope.route || _self.$mp && _self.$mp.page.route; return (_self.$scope && _self.$scope.route) || (_self.$mp && _self.$mp.page.route);
} }
}; };
...@@ -251,12 +251,12 @@ export const getPageRoute = (self) => { ...@@ -251,12 +251,12 @@ export const getPageRoute = (self) => {
if (getPlatformName() === 'bd') { if (getPlatformName() === 'bd') {
return _self.$mp && _self.$mp.page.is + str; return _self.$mp && _self.$mp.page.is + str;
} else { } else {
return _self.$scope && _self.$scope.route + str || _self.$mp && _self.$mp.page.route + str; return (_self.$scope && _self.$scope.route + str )|| (_self.$mp && _self.$mp.page.route + str);
} }
}; };
export const getPageTypes = (self) => { export const getPageTypes = (self) => {
if (self.mpType === 'page' || self.$mp && self.$mp.mpType === 'page') { if (self.mpType === 'page' || (self.$mp && self.$mp.mpType === 'page') || self.$options.mpType === 'page') {
return true; return true;
} }
return false; return false;
......
...@@ -106,8 +106,9 @@ class Util { ...@@ -106,8 +106,9 @@ class Util {
getLastTime(); getLastTime();
const time = getResidenceTime(); const time = getResidenceTime();
getFirstTime(); getFirstTime();
const route = getPageRoute(this);
this._sendHideRequest({ this._sendHideRequest({
urlref: this._lastPageRoute, urlref: route,
urlref_ts: time.residenceTime urlref_ts: time.residenceTime
}, type) }, type)
} }
...@@ -297,44 +298,62 @@ class Util { ...@@ -297,44 +298,62 @@ class Util {
data.ttc = title.report; data.ttc = title.report;
let requestData = this._reportingRequestData; let requestData = this._reportingRequestData;
if (getPlatformName() === 'n') {
requestData = uni.getStorageSync('__UNI__STAT__DATA') || {}
}
if (!requestData[data.lt]) { if (!requestData[data.lt]) {
this._reportingRequestData[data.lt] = []; requestData[data.lt] = [];
}
requestData[data.lt].push(data);
if (getPlatformName() === 'n') {
uni.setStorageSync('__UNI__STAT__DATA', requestData)
} }
this._reportingRequestData[data.lt].push(data);
if (getPageResidenceTime() < OPERATING_TIME && !type) { if (getPageResidenceTime() < OPERATING_TIME && !type) {
return return
} }
let uniStatData = this._reportingRequestData
if (getPlatformName() === 'n') {
uniStatData = uni.getStorageSync('__UNI__STAT__DATA')
}
// 时间超过,重新获取时间戳 // 时间超过,重新获取时间戳
setPageResidenceTime(); setPageResidenceTime();
let firstArr = [] let firstArr = [];
let contentArr = [] let contentArr = [];
let lastArr = [] let lastArr = [];
for (let i in this._reportingRequestData) {
const rd = this._reportingRequestData[i] for (let i in uniStatData) {
const rd = uniStatData[i];
rd.forEach((elm) => { rd.forEach((elm) => {
const newData = getSplicing(elm) const newData = getSplicing(elm);
if (i === 0) { if (i === 0) {
firstArr.push(newData) firstArr.push(newData);
} else if (i === 3) { } else if (i === 3) {
lastArr.push(newData) lastArr.push(newData);
} else { } else {
contentArr.push(newData) contentArr.push(newData);
} }
}) });
} }
firstArr.push(...contentArr, ...lastArr) firstArr.push(...contentArr, ...lastArr);
let optionsData = { let optionsData = {
usv: STAT_VERSION, //统计 SDK 版本号 usv: STAT_VERSION, //统计 SDK 版本号
t: time, //发送请求时的时间戮 t: time, //发送请求时的时间戮
requests: JSON.stringify(firstArr), requests: JSON.stringify(firstArr),
};
this._reportingRequestData = {};
if (getPlatformName() === 'n') {
uni.removeStorageSync('__UNI__STAT__DATA')
} }
this._reportingRequestData = {}
if (data.ut === 'h5') { if (data.ut === 'h5') {
this.imageRequest(optionsData) this.imageRequest(optionsData)
return return
} }
setTimeout(() => {
uni.request({ uni.request({
url: STAT_URL, url: STAT_URL,
method: 'POST', method: 'POST',
...@@ -355,6 +374,8 @@ class Util { ...@@ -355,6 +374,8 @@ class Util {
} }
} }
}); });
}, 200)
} }
/** /**
* h5 请求 * h5 请求
...@@ -457,6 +478,10 @@ class Stat extends Util { ...@@ -457,6 +478,10 @@ class Stat extends Util {
} }
load(options, self) { load(options, self) {
if (!self.$scope && !self.$mp) {
const page = getCurrentPages()
self.$scope = page[page.length - 1]
}
this.self = self; this.self = self;
this._query = options; this._query = options;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册