Authored by yyq

yas report

... ... @@ -4,7 +4,7 @@ import event from './common/event';
import {verify} from './common/api';
import config from './common/config';
import Promise from './vendors/es6-promise';
import {MD5} from './vendors/crypto';
import { MD5 } from './vendors/crypto';
import { WeToast } from './vendors/toast/wetoast';
import { wechatAuthLogin, verifySessionKey } from './common/login';
import { stringify } from './vendors/query-stringify';
... ... @@ -127,7 +127,7 @@ App({
},
getUnionID: function() {
this.globalData.unionID = this._getSync('unionID');
return this.globalData.unionID;
return this.globalData.unionID;
},
getSessionKey: function() {
this.globalData.sessionKey = this._getSync('sessionKey');
... ... @@ -237,5 +237,8 @@ App({
getSystemInfo() {
return this.globalData.systemInfo;
},
getPvid() {
return MD5(`${new Date().getTime()}${udid.get()}`).toString();
},
WeToast
});
... ...
import config from './config';
import api from './api';
import rules from '../router/rules';
import {MD5} from '../vendors/crypto';
export default class yas {
... ... @@ -22,6 +23,10 @@ export default class yas {
success(res) {
self.language = res.language;
if (res.platform === 'devtools') {
self.devEnv = true;
}
Object.assign(self.deviceInfo, {
os: res.platform,
dm: res.model,
... ... @@ -38,6 +43,11 @@ export default class yas {
sid = this.app.globalData.sid || '';
}
// 开发环境不上报
if (this.devEnv) {
return console.log(params);
}
return wx.request({
url: config.domains.yasApi,
data: {'_mlogs': JSON.stringify(params)},
... ... @@ -97,6 +107,31 @@ export default class yas {
}
});
});
}
pageOpenReport(pvid, extra) {
let pages = getCurrentPages();
let currentPage = pages[pages.length - 1];
let path = `/${currentPage.route}`,
options = currentPage.option || {};
let info = {PV_ID: pvid};
for (let i in rules) {
if (rules.hasOwnProperty(i) && rules[i].path === path) {
Object.assign(info, {
PAGE_PATH: path,
PAGE_NAME: i,
FROM_PAGE_NAME: options.fromPage || '',
FROM_PAGE_PARAM: options.fromParam || ''
});
options.fromPage && delete options.fromPage;
options.fromParam && delete options.fromParam;
info.PAGE_PARAM = options;
}
}
this.report('YB_PAGE_OPEN_L', Object.assign(info, extra || {}));
}
};
... ...
... ... @@ -101,6 +101,7 @@ Page({
paymentAmount: ''
},
onLoad(options) {
this.pvid = app.getPvid();
this.orderData = options;
this.yasInfo = {
skns: [],
... ... @@ -108,6 +109,8 @@ Page({
pids: []
};
this.loadEnsurePayment({productSku: this.orderData.productSku});
yas.pageOpenReport(this.pvid);
},
loadEnsurePayment(options, reload) {
if (options.productSku) {
... ...
... ... @@ -5,6 +5,14 @@ import {parse, stringify} from '../vendors/query-stringify';
const MINI_APP_DOMAIN = 'miniapp.yohobuy.com';
const pageNameMap = {};
for (let i in rules) {
if (rules.hasOwnProperty(i) && rules[i].path) {
pageNameMap[rules[i].path] = i;
}
}
global.router = {
go(name, qs, type) {
let rule = rules[name];
... ... @@ -13,21 +21,34 @@ global.router = {
return Promise.reject(`router rules mismatch : ${name}`);
}
qs = qs || {};
// 添加yas上报【fromPage】参数
let pages = getCurrentPages();
let currentPage = pages[pages.length - 1];
let path = `/${currentPage.route}`;
if (pageNameMap[path]) {
qs.fromPage = pageNameMap[path];
}
// 页面登录校验
this.app = this.app || getApp();
if (rule.auth && !this.app.getUid()) {
return jump.navigateTo(rules.login.path);
}
// 跳转类型
let jumpFn = jump[type] || rule.type || jump.navigateTo;
return jumpFn(`${rule.path}?${stringify(qs || {})}`);
return jumpFn(`${rule.path}?${stringify(qs)}`);
},
goUrl(url) {
if (!url) {
return Promise.reject('error url');
}
let [uri, search] = url.split('?');
let path = uri.split(MINI_APP_DOMAIN)[1];
let qs = parse(search);
... ... @@ -40,24 +61,19 @@ global.router = {
}
let openBy = JSON.parse(qs['openby:yohobuy'] || {});
if (openBy.action) {
const GO_LIST = 'go.list';
const GO_DETAIL = 'go.productDetail';
let url;
switch (openBy.action) {
case GO_LIST:
url = `/pages/product/list/list?${stringify(openBy.params)}`;
this.go('productList', openBy.params);
break;
case GO_DETAIL:
url = `/pages/product/detail/detail?productSkn=${openBy.params.product_skn}`;
break;
this.go('productDetail', {productSkn: openBy.params.product_skn});
break;
}
url && jump.navigateTo(url);
}
}
};
... ...
... ... @@ -19,4 +19,4 @@ export default {
cartEnsure: {path: '/pages/cart/ensure/ensure', auth: true },
cartInvoice: {path: '/pages/cart/invoice/invoice'},
paySuccess: {path: '/pages/pay/success', type: jump.redirectTo, auth: true},
}
};
... ...