Authored by TaoHuang

feat(report):fix report

@@ -36,7 +36,7 @@ export default context => { @@ -36,7 +36,7 @@ export default context => {
36 setTimeout(() => { 36 setTimeout(() => {
37 try { 37 try {
38 report({ 38 report({
39 - tp: 'err', 39 + tp: context.tp || 'err',
40 msg: err.message, 40 msg: err.message,
41 sc: 'cdn.yoho.cn', 41 sc: 'cdn.yoho.cn',
42 ln: 0, 42 ln: 0,
@@ -107,6 +107,7 @@ export default { @@ -107,6 +107,7 @@ export default {
107 height: 0, 107 height: 0,
108 isA: false, 108 isA: false,
109 isHidden: true, 109 isHidden: true,
  110 + reported: false,
110 }; 111 };
111 }, 112 },
112 computed: { 113 computed: {
@@ -151,26 +152,41 @@ export default { @@ -151,26 +152,41 @@ export default {
151 // this.getAllInboxCatInfo(); 152 // this.getAllInboxCatInfo();
152 153
153 this.PAGE_URL = window.location.href; 154 this.PAGE_URL = window.location.href;
  155 +
  156 + if (!this.reported) {
  157 + // 首页进入上报
  158 + this.$store.dispatch('reportYas', {
  159 + params: {
  160 + param: { },
  161 + appop: 'XY_UFO_MAIN_START'
  162 + }
  163 + });
  164 + }
154 }, 165 },
155 async serverPrefetch() { 166 async serverPrefetch() {
156 return this.fetchChannelList(); 167 return this.fetchChannelList();
157 }, 168 },
158 mounted() { 169 mounted() {
159 - // 首页进入上报  
160 - this.$store.dispatch('reportYas', {  
161 - params: {  
162 - param: { },  
163 - appop: 'XY_UFO_MAIN_START'  
164 - }  
165 - });  
166 // 初始化 选中类目 170 // 初始化 选中类目
167 const [firstNav] = this.navList; 171 const [firstNav] = this.navList;
  172 +
168 if(firstNav) { 173 if(firstNav) {
169 const {url = ''} = firstNav; 174 const {url = ''} = firstNav;
  175 +
170 this.selectedCategory = queryString.parse(url); 176 this.selectedCategory = queryString.parse(url);
171 } 177 }
172 178
173 this.refreshProductList(this.active); 179 this.refreshProductList(this.active);
  180 +
  181 + // 首页进入上报
  182 + this.$store.dispatch('reportYas', {
  183 + params: {
  184 + param: { },
  185 + appop: 'XY_UFO_MAIN_START'
  186 + }
  187 + });
  188 +
  189 + this.reported = true;
174 }, 190 },
175 methods: { 191 methods: {
176 ...mapActions(['fetchChannelList', 'getAllInboxCatInfo']), 192 ...mapActions(['fetchChannelList', 'getAllInboxCatInfo']),
@@ -212,7 +212,7 @@ export default function(mergeState = {}) { @@ -212,7 +212,7 @@ export default function(mergeState = {}) {
212 // 获取设备信息 212 // 获取设备信息
213 if (!retry && !get(window, 'appBaseLogs.device.dm') && this.$xianyu.getClientInfo) { 213 if (!retry && !get(window, 'appBaseLogs.device.dm') && this.$xianyu.getClientInfo) {
214 this.$xianyu.getClientInfo(info => { 214 this.$xianyu.getClientInfo(info => {
215 - info = info || {} 215 + info = info || {};
216 set(window, 'appBaseLogs.device.dm', info.platformName ? info.platformName : `${info.brand} ${info.model}`); 216 set(window, 'appBaseLogs.device.dm', info.platformName ? info.platformName : `${info.brand} ${info.model}`);
217 217
218 this.dispatch('reportYas', { 218 this.dispatch('reportYas', {
@@ -233,7 +233,7 @@ export default function(mergeState = {}) { @@ -233,7 +233,7 @@ export default function(mergeState = {}) {
233 return; 233 return;
234 } 234 }
235 235
236 - if (window._yas && window._yas.sendAppLogs) { 236 + if (window) {
237 param = param || {}; 237 param = param || {};
238 238
239 if (!param.C_ID) { 239 if (!param.C_ID) {
@@ -251,29 +251,53 @@ export default function(mergeState = {}) { @@ -251,29 +251,53 @@ export default function(mergeState = {}) {
251 param.SRC_ID = srcId; 251 param.SRC_ID = srcId;
252 } 252 }
253 253
254 - window._yas.sendAppLogs(  
255 - {  
256 - appop,  
257 - param: param ? JSON.stringify(param) : '{}',  
258 - },  
259 - asyncindx,  
260 - ); 254 + if (window._yas && window._yas.sendAppLogs) {
  255 + window._yas.sendAppLogs(
  256 + {
  257 + appop,
  258 + param: param ? JSON.stringify(param) : '{}',
  259 + },
  260 + asyncindx,
  261 + );
261 262
262 - if (window._yasEvents) {  
263 - window._yasEvents.forEach(e => {  
264 - window._yas.sendAppLogs(  
265 - {  
266 - appop: e.appop,  
267 - param: e.param ? JSON.stringify(e.param) : '{}',  
268 - },  
269 - asyncindx,  
270 - );  
271 - }); 263 + if (window._yasEvents) {
  264 + window._yasEvents.forEach(e => {
  265 + window._yas.sendAppLogs(
  266 + {
  267 + appop: e.appop,
  268 + param: e.param ? JSON.stringify(e.param) : '{}',
  269 + },
  270 + asyncindx,
  271 + );
  272 + });
  273 +
  274 + window._yasEvents = null;
  275 + }
  276 + } else if (window._yas2) {
  277 + window._yas2.sendAppLogs(
  278 + {
  279 + appop,
  280 + param: param ? JSON.stringify(param) : '{}',
  281 + },
  282 + asyncindx,
  283 + );
  284 +
  285 + if (window._yasEvents) {
  286 + window._yasEvents.forEach(e => {
  287 + window._yas2.sendAppLogs(
  288 + {
  289 + appop: e.appop,
  290 + param: e.param ? JSON.stringify(e.param) : '{}',
  291 + },
  292 + asyncindx,
  293 + );
  294 + });
272 295
273 - window._yasEvents = null; 296 + window._yasEvents = null;
  297 + }
  298 + } else {
  299 + window._yasEvents = window._yasEvents ? window._yasEvents.push({ appop, param }) : [{ appop, param }];
274 } 300 }
275 - } else {  
276 - window._yasEvents = window._yasEvents ? window._yasEvents.push({ appop, param }) : [{ appop, param }];  
277 } 301 }
278 }, 300); 302 }, 300);
279 } catch (e) { 303 } catch (e) {
1 import Vue from 'vue'; 1 import Vue from 'vue';
2 import cookie from 'yoho-cookie'; 2 import cookie from 'yoho-cookie';
3 import xianyu from '../common/xianyu'; 3 import xianyu from '../common/xianyu';
  4 +import './yas/ya';
  5 +import reportError from 'report-error';
4 6
5 const setWindowSize = (store) => { 7 const setWindowSize = (store) => {
6 const { clientWidth, clientHeight } = document.body; 8 const { clientWidth, clientHeight } = document.body;
@@ -50,6 +52,7 @@ window.indx = 1; @@ -50,6 +52,7 @@ window.indx = 1;
50 52
51 function initBaseLogs() { 53 function initBaseLogs() {
52 if (!(window._yas && window._yas.sendAppLogs)) { 54 if (!(window._yas && window._yas.sendAppLogs)) {
  55 + reportError({ tp: 'yas_err' });
53 (function(w, d, s, j, f) { 56 (function(w, d, s, j, f) {
54 var a = d.createElement(s); 57 var a = d.createElement(s);
55 var m = d.getElementsByTagName(s)[0]; 58 var m = d.getElementsByTagName(s)[0];
  1 +function getDomain() {
  2 + var domainArr = document.domain.split('.');
  3 + var length = domainArr.length;
  4 + if (length > 1 && isNaN(domainArr[length - 1])) {
  5 + return '.' + domainArr[length - 2] + '.' + domainArr[length - 1];
  6 + } else {
  7 + return document.domain;
  8 + }
  9 +}
  10 +
  11 +module.exports = {
  12 + version: '1.0',
  13 + yasPath: '/web/',
  14 + yasDomain: getDomain(),
  15 + yasImgDomain: '//analytics.m.yohobuy.com/yas.gif',
  16 + yasMobileDomain: '//analytics.m.yohobuy.com/yas_mobile'
  17 +};
  1 +/**
  2 + * 跨域发送信息工具库
  3 + */
  4 +var config = require('./config');
  5 +
  6 +var yasMobileDomain = config.yasMobileDomain;
  7 +
  8 +var createCORSRequest = function(method, url) {
  9 + var xhr;
  10 + if (window.XMLHttpRequest) {
  11 + xhr = new XMLHttpRequest();
  12 + } else if (typeof XDomainRequest != 'undefined') {
  13 + // IE8 & IE9
  14 + xhr = new XDomainRequest();
  15 + } else if (window.ActiveXObject) {
  16 + xhr = new ActiveXObject('Microsoft.XMLHTTP');
  17 + }
  18 + return xhr;
  19 +};
  20 +
  21 +// app中打开wap页 数据上报
  22 +exports.appSend = function(data, callback) {
  23 + if (!window.appBaseLogs) {
  24 + return;
  25 + }
  26 +
  27 + var xhr = createCORSRequest();
  28 + if (!xhr) {
  29 + return;
  30 + }
  31 +
  32 + xhr.ontimeout = function(e) {
  33 + console.log('timeout: ', JSON.stringify(e));
  34 + };
  35 + xhr.onerror = function(e) {
  36 + console.log('error: ', JSON.stringify(e));
  37 + };
  38 + xhr.onreadystatechange = function() {
  39 + if (xhr.readyState == 4) {
  40 + if (xhr.status == 200 && callback) {
  41 + callback();
  42 + }
  43 + }
  44 + };
  45 +
  46 + xhr.open('post', (document.location.protocol === 'https:' ? 'https:' : 'http:') + yasMobileDomain, true);
  47 + xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
  48 + xhr.send(data);
  49 +};
  50 +
  1 +/**
  2 + * 采集系统的工具库
  3 + */
  4 +
  5 +//浅层合并对象
  6 +exports.merge = function(obj1, obj2) {
  7 + var ret = {};
  8 + for (var attr in obj1) {
  9 + ret[attr] = obj1[attr];
  10 + }
  11 +
  12 + for (var attr2 in obj2) {
  13 + ret[attr2] = obj2[attr2];
  14 + }
  15 + return ret;
  16 +};
  17 +
  1 +/**
  2 + * @fileoverview YAS (YOHO! Acquisition System) YOHO!采集系统的前端js的开发包,
  3 + * 用于在网页端采集信息(应用信息,用户信息,用户行为信息,浏览器及其系统信息)。
  4 + */
  5 +//工具库
  6 +var util = require('./util');
  7 +
  8 +//跨域通信
  9 +var cross = require('./cross');
  10 +
  11 +var _yas = {};
  12 +
  13 +/**
  14 + * 发送用户订制信息, 此方法提供给用户调用, 本方法不对参数合法性进行检查, 调用者自己保证。(app上报数据使用)
  15 + * @param json 用户订制信息, 必选参数,采用json格式
  16 + * @param asyncindx 是否需要同步indx
  17 + * true表示同步,false表示不需要同步, 默认值是false
  18 + * 本方法使用场合:
  19 + * 1. app中的事件上报
  20 + */
  21 +_yas.sendAppLogs = function(json) {
  22 + if (!window.appBaseLogs) {
  23 + return;
  24 + }
  25 +
  26 + // 数据整合
  27 + var param = JSON.parse(json.param);
  28 + if (param.F_URL) {
  29 + param.F_URL = decodeURIComponent(param.F_URL);
  30 + }
  31 +
  32 + // abtype
  33 + var ev = window.appBaseLogs.events[0];
  34 + if (ev.abtype) {
  35 + param.AB_TYPE = ev.abtype;
  36 + }
  37 + var event = util.merge(ev, {
  38 + ts: (new Date()).getTime().toString(),
  39 + indx: ++window.indx,
  40 + op: json.appop,
  41 + param: param
  42 + });
  43 + var logs = util.merge(window.appBaseLogs, {
  44 + events: [event]
  45 + });
  46 +
  47 + // 上报数据
  48 + cross.appSend('_mlogs=' + encodeURIComponent(JSON.stringify(logs)));
  49 + window._yasloaded = true;
  50 +};
  51 +
  52 +window._yas2 = _yas;