Authored by TaoHuang

feat(report):fix report

... ... @@ -36,7 +36,7 @@ export default context => {
setTimeout(() => {
try {
report({
tp: 'err',
tp: context.tp || 'err',
msg: err.message,
sc: 'cdn.yoho.cn',
ln: 0,
... ...
... ... @@ -107,6 +107,7 @@ export default {
height: 0,
isA: false,
isHidden: true,
reported: false,
};
},
computed: {
... ... @@ -151,26 +152,41 @@ export default {
// this.getAllInboxCatInfo();
this.PAGE_URL = window.location.href;
if (!this.reported) {
// 首页进入上报
this.$store.dispatch('reportYas', {
params: {
param: { },
appop: 'XY_UFO_MAIN_START'
}
});
}
},
async serverPrefetch() {
return this.fetchChannelList();
},
mounted() {
// 首页进入上报
this.$store.dispatch('reportYas', {
params: {
param: { },
appop: 'XY_UFO_MAIN_START'
}
});
// 初始化 选中类目
const [firstNav] = this.navList;
if(firstNav) {
const {url = ''} = firstNav;
this.selectedCategory = queryString.parse(url);
}
this.refreshProductList(this.active);
// 首页进入上报
this.$store.dispatch('reportYas', {
params: {
param: { },
appop: 'XY_UFO_MAIN_START'
}
});
this.reported = true;
},
methods: {
...mapActions(['fetchChannelList', 'getAllInboxCatInfo']),
... ...
... ... @@ -212,7 +212,7 @@ export default function(mergeState = {}) {
// 获取设备信息
if (!retry && !get(window, 'appBaseLogs.device.dm') && this.$xianyu.getClientInfo) {
this.$xianyu.getClientInfo(info => {
info = info || {}
info = info || {};
set(window, 'appBaseLogs.device.dm', info.platformName ? info.platformName : `${info.brand} ${info.model}`);
this.dispatch('reportYas', {
... ... @@ -233,7 +233,7 @@ export default function(mergeState = {}) {
return;
}
if (window._yas && window._yas.sendAppLogs) {
if (window) {
param = param || {};
if (!param.C_ID) {
... ... @@ -251,29 +251,53 @@ export default function(mergeState = {}) {
param.SRC_ID = srcId;
}
window._yas.sendAppLogs(
{
appop,
param: param ? JSON.stringify(param) : '{}',
},
asyncindx,
);
if (window._yas && window._yas.sendAppLogs) {
window._yas.sendAppLogs(
{
appop,
param: param ? JSON.stringify(param) : '{}',
},
asyncindx,
);
if (window._yasEvents) {
window._yasEvents.forEach(e => {
window._yas.sendAppLogs(
{
appop: e.appop,
param: e.param ? JSON.stringify(e.param) : '{}',
},
asyncindx,
);
});
if (window._yasEvents) {
window._yasEvents.forEach(e => {
window._yas.sendAppLogs(
{
appop: e.appop,
param: e.param ? JSON.stringify(e.param) : '{}',
},
asyncindx,
);
});
window._yasEvents = null;
}
} else if (window._yas2) {
window._yas2.sendAppLogs(
{
appop,
param: param ? JSON.stringify(param) : '{}',
},
asyncindx,
);
if (window._yasEvents) {
window._yasEvents.forEach(e => {
window._yas2.sendAppLogs(
{
appop: e.appop,
param: e.param ? JSON.stringify(e.param) : '{}',
},
asyncindx,
);
});
window._yasEvents = null;
window._yasEvents = null;
}
} else {
window._yasEvents = window._yasEvents ? window._yasEvents.push({ appop, param }) : [{ appop, param }];
}
} else {
window._yasEvents = window._yasEvents ? window._yasEvents.push({ appop, param }) : [{ appop, param }];
}
}, 300);
} catch (e) {
... ...
import Vue from 'vue';
import cookie from 'yoho-cookie';
import xianyu from '../common/xianyu';
import './yas/ya';
import reportError from 'report-error';
const setWindowSize = (store) => {
const { clientWidth, clientHeight } = document.body;
... ... @@ -50,6 +52,7 @@ window.indx = 1;
function initBaseLogs() {
if (!(window._yas && window._yas.sendAppLogs)) {
reportError({ tp: 'yas_err' });
(function(w, d, s, j, f) {
var a = d.createElement(s);
var m = d.getElementsByTagName(s)[0];
... ...
function getDomain() {
var domainArr = document.domain.split('.');
var length = domainArr.length;
if (length > 1 && isNaN(domainArr[length - 1])) {
return '.' + domainArr[length - 2] + '.' + domainArr[length - 1];
} else {
return document.domain;
}
}
module.exports = {
version: '1.0',
yasPath: '/web/',
yasDomain: getDomain(),
yasImgDomain: '//analytics.m.yohobuy.com/yas.gif',
yasMobileDomain: '//analytics.m.yohobuy.com/yas_mobile'
};
... ...
/**
* 跨域发送信息工具库
*/
var config = require('./config');
var yasMobileDomain = config.yasMobileDomain;
var createCORSRequest = function(method, url) {
var xhr;
if (window.XMLHttpRequest) {
xhr = new XMLHttpRequest();
} else if (typeof XDomainRequest != 'undefined') {
// IE8 & IE9
xhr = new XDomainRequest();
} else if (window.ActiveXObject) {
xhr = new ActiveXObject('Microsoft.XMLHTTP');
}
return xhr;
};
// app中打开wap页 数据上报
exports.appSend = function(data, callback) {
if (!window.appBaseLogs) {
return;
}
var xhr = createCORSRequest();
if (!xhr) {
return;
}
xhr.ontimeout = function(e) {
console.log('timeout: ', JSON.stringify(e));
};
xhr.onerror = function(e) {
console.log('error: ', JSON.stringify(e));
};
xhr.onreadystatechange = function() {
if (xhr.readyState == 4) {
if (xhr.status == 200 && callback) {
callback();
}
}
};
xhr.open('post', (document.location.protocol === 'https:' ? 'https:' : 'http:') + yasMobileDomain, true);
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
xhr.send(data);
};
... ...
/**
* 采集系统的工具库
*/
//浅层合并对象
exports.merge = function(obj1, obj2) {
var ret = {};
for (var attr in obj1) {
ret[attr] = obj1[attr];
}
for (var attr2 in obj2) {
ret[attr2] = obj2[attr2];
}
return ret;
};
... ...
/**
* @fileoverview YAS (YOHO! Acquisition System) YOHO!采集系统的前端js的开发包,
* 用于在网页端采集信息(应用信息,用户信息,用户行为信息,浏览器及其系统信息)。
*/
//工具库
var util = require('./util');
//跨域通信
var cross = require('./cross');
var _yas = {};
/**
* 发送用户订制信息, 此方法提供给用户调用, 本方法不对参数合法性进行检查, 调用者自己保证。(app上报数据使用)
* @param json 用户订制信息, 必选参数,采用json格式
* @param asyncindx 是否需要同步indx
* true表示同步,false表示不需要同步, 默认值是false
* 本方法使用场合:
* 1. app中的事件上报
*/
_yas.sendAppLogs = function(json) {
if (!window.appBaseLogs) {
return;
}
// 数据整合
var param = JSON.parse(json.param);
if (param.F_URL) {
param.F_URL = decodeURIComponent(param.F_URL);
}
// abtype
var ev = window.appBaseLogs.events[0];
if (ev.abtype) {
param.AB_TYPE = ev.abtype;
}
var event = util.merge(ev, {
ts: (new Date()).getTime().toString(),
indx: ++window.indx,
op: json.appop,
param: param
});
var logs = util.merge(window.appBaseLogs, {
events: [event]
});
// 上报数据
cross.appSend('_mlogs=' + encodeURIComponent(JSON.stringify(logs)));
window._yasloaded = true;
};
window._yas2 = _yas;
... ...