Authored by yyq

report

import Vue from 'vue';
import {get} from 'lodash';
import App from './app.vue';
import {createRouter} from './router';
import {createStore} from './store';
... ... @@ -8,6 +9,7 @@ import titleMixin from './mixins/title';
import pluginCore from './plugins/core';
import lazyload from 'vue-lazyload';
import reportError from 'report-error';
import ReportApp from './common/report-app';
Vue.use(lazyload, {
preLoad: 2
... ... @@ -15,11 +17,12 @@ Vue.use(lazyload, {
Vue.use(pluginCore);
Vue.mixin(titleMixin);
export function createApp(context) {
const router = createRouter();
const store = createStore(context);
const reportApp = new ReportApp(store.$context.env);
const app = new Vue({
router,
store,
... ... @@ -27,6 +30,19 @@ export function createApp(context) {
reportError(context, 'server')(error);
return false;
},
methods: {
async reportApp(type, pn, params = {}, pt) {
let user = await this.$sdk.getUser();
if (!params.ei) {
params.ei = get(this.$router, 'history.current.name', '');
}
reportApp.report(type, pt || 'BUSINESS', pn, params, get(user, 'uid'));
},
reportAppStart() {
this.reportApp('start', 'BUSINESS_PLAN_A_ENTER', {locfun: 'mounted'});
}
},
render: h => h(App)
});
... ...
import axios from 'axios';
export default ({
type,
pt,
pn,
params
}) => {
axios({
baseURL: 'https://app.yoho.cn/collect/v3',
url: '',
method: 'POST',
data: {
type,
device: {},
events: [{
ps: '0',
av: APP_VERSION,
ab: APP_BUILD,
ca: '0',
net: networkType,
sid: sid,
uid: uid,
ts: ts,
pt: 'BUSINESS',
pn: pn,
param: {
}
}]
export default class reportApp {
constructor(params = {}) {
this.isProd = !params.unProd;
this.events = {
ps: '0',
av: params.version,
ab: params.buildId,
ca: '0',
net: 'unknown',
sid: params.visitId,
};
this.params = {
mst: '',
st: '',
ec: '',
ei: '',
url: '',
host: '',
locfun: ''
};
}
report(type, pt, pn, params = {}, uid = 0) {
if (!this.isProd) {
return;
}
})
}
\ No newline at end of file
params = Object.assign({}, this.params, params);
if (window) {
Object.assign(params, {
host: window.location.host,
url: window.location.href
});
}
axios({
baseURL: 'https://app.yoho.cn/collect/v3',
url: '',
method: 'POST',
data: {
type,
device: {},
events: [
Object.assign({
uid: uid,
ts: new Date().getTime() + '000000',
pt: pt,
pn: pn,
param: params
}, this.events)
]
}
})
}
}
... ...
... ... @@ -95,6 +95,10 @@ export default {
} else {
this.$yoho.goPage('go.ufo', { pagename: 'MerchantEntry' });
}
this.$root.reportApp('hb', 'BUSINESS_PLAN_A_EVENT', {
locfun: 'click:storeNow'
});
}
}
};
... ...
... ... @@ -26,6 +26,9 @@ export default {
await store.dispatch('invite/invite/fetchAll');
}
},
mounted() {
this.$root.reportAppStart();
},
data() {
return {
title: '卖家邀新返利',
... ...
... ... @@ -86,6 +86,10 @@ export default {
if (!this.banks.length) {
this.fetchBankList();
}
this.$root.reportAppStart();
this.$root.reportApp('hb', 'BUSINESS_PLAN_A_EVEVT', {
locfun: 'click:bindBankCard'
});
},
computed: {
...mapState(['banks', 'bankCardList']),
... ... @@ -178,6 +182,10 @@ export default {
}
},
bindBankCardInfo(info) {
this.$root.reportApp('hb', 'BUSINESS_PLAN_A_EVENT', {
locfun: 'click:bindBankCard'
});
let confirm = this.$createDialog({
type: 'confirm',
title: '提示',
... ...
... ... @@ -12,6 +12,7 @@ export default {
name: 'cardList',
mounted() {
this.$refs.cards.init();
this.$root.reportAppStart();
},
components: {
LayoutApp,
... ...
... ... @@ -20,6 +20,7 @@ exports.createApp = async(app) => {
app.locals.devEnv = app.get('env') === 'development';
app.locals.proEnv = app.get('env') === 'production';
app.locals.version = pkg.version;
app.locals.buildId = 'web' + new Date().getTime() + '000000';
if (config.zookeeperServer) {
const monitor = global.yoho.monitorSender;
... ...
... ... @@ -12,6 +12,7 @@ const {createBundleRenderer} = require('vue-server-renderer');
const logger = global.yoho.logger;
const config = global.yoho.config;
const isProd = process.env.NODE_ENV === 'production';
const isDev = process.env.NODE_ENV === 'development' || !process.env.NODE_ENV;
let renderer;
... ... @@ -34,7 +35,7 @@ if (!isDev) {
}
const getContext = (req) => {
return {
let res = {
url: req.url,
title: '',
user: req.user,
... ... @@ -44,6 +45,9 @@ const getContext = (req) => {
isAndroid: req.yoho.isAndroid,
isYohoApp: req.yoho.isYohoApp,
clientIp: req.yoho.clientIp,
version: pkg.version,
buildId: req.app.locals.buildId,
visitId: md5(`${req.query.udid}_${new Date().getTime()}`)
},
ua: req.get('user-agent'),
hostname: os.hostname(),
... ... @@ -51,6 +55,12 @@ const getContext = (req) => {
udid: _.get(req, 'cookies.udid', 'yoho'),
path: `[${req.method}]${routeEncode.getRouter(req)}`,
};
if (!isProd) {
res.env.unProd = true;
}
return res;
};
const handlerError = (err = {}, req, res, next) => {
... ...