Authored by yyq

report

1 import Vue from 'vue'; 1 import Vue from 'vue';
  2 +import {get} from 'lodash';
2 import App from './app.vue'; 3 import App from './app.vue';
3 import {createRouter} from './router'; 4 import {createRouter} from './router';
4 import {createStore} from './store'; 5 import {createStore} from './store';
@@ -8,6 +9,7 @@ import titleMixin from './mixins/title'; @@ -8,6 +9,7 @@ import titleMixin from './mixins/title';
8 import pluginCore from './plugins/core'; 9 import pluginCore from './plugins/core';
9 import lazyload from 'vue-lazyload'; 10 import lazyload from 'vue-lazyload';
10 import reportError from 'report-error'; 11 import reportError from 'report-error';
  12 +import ReportApp from './common/report-app';
11 13
12 Vue.use(lazyload, { 14 Vue.use(lazyload, {
13 preLoad: 2 15 preLoad: 2
@@ -15,11 +17,12 @@ Vue.use(lazyload, { @@ -15,11 +17,12 @@ Vue.use(lazyload, {
15 Vue.use(pluginCore); 17 Vue.use(pluginCore);
16 Vue.mixin(titleMixin); 18 Vue.mixin(titleMixin);
17 19
18 -  
19 export function createApp(context) { 20 export function createApp(context) {
20 const router = createRouter(); 21 const router = createRouter();
21 const store = createStore(context); 22 const store = createStore(context);
22 23
  24 + const reportApp = new ReportApp(store.$context.env);
  25 +
23 const app = new Vue({ 26 const app = new Vue({
24 router, 27 router,
25 store, 28 store,
@@ -27,6 +30,19 @@ export function createApp(context) { @@ -27,6 +30,19 @@ export function createApp(context) {
27 reportError(context, 'server')(error); 30 reportError(context, 'server')(error);
28 return false; 31 return false;
29 }, 32 },
  33 + methods: {
  34 + async reportApp(type, pn, params = {}, pt) {
  35 + let user = await this.$sdk.getUser();
  36 +
  37 + if (!params.ei) {
  38 + params.ei = get(this.$router, 'history.current.name', '');
  39 + }
  40 + reportApp.report(type, pt || 'BUSINESS', pn, params, get(user, 'uid'));
  41 + },
  42 + reportAppStart() {
  43 + this.reportApp('start', 'BUSINESS_PLAN_A_ENTER', {locfun: 'mounted'});
  44 + }
  45 + },
30 render: h => h(App) 46 render: h => h(App)
31 }); 47 });
32 48
1 import axios from 'axios'; 1 import axios from 'axios';
2 2
3 -export default ({  
4 - type,  
5 - pt,  
6 - pn,  
7 - params  
8 -}) => {  
9 - axios({  
10 - baseURL: 'https://app.yoho.cn/collect/v3',  
11 - url: '',  
12 - method: 'POST',  
13 - data: {  
14 - type,  
15 - device: {},  
16 - events: [{  
17 - ps: '0',  
18 - av: APP_VERSION,  
19 - ab: APP_BUILD,  
20 - ca: '0',  
21 - net: networkType,  
22 - sid: sid,  
23 - uid: uid,  
24 - ts: ts,  
25 - pt: 'BUSINESS',  
26 - pn: pn,  
27 - param: {  
28 -  
29 - }  
30 - }] 3 +export default class reportApp {
  4 + constructor(params = {}) {
  5 + this.isProd = !params.unProd;
  6 + this.events = {
  7 + ps: '0',
  8 + av: params.version,
  9 + ab: params.buildId,
  10 + ca: '0',
  11 + net: 'unknown',
  12 + sid: params.visitId,
  13 + };
  14 + this.params = {
  15 + mst: '',
  16 + st: '',
  17 + ec: '',
  18 + ei: '',
  19 + url: '',
  20 + host: '',
  21 + locfun: ''
  22 + };
  23 + }
  24 + report(type, pt, pn, params = {}, uid = 0) {
  25 + if (!this.isProd) {
  26 + return;
31 } 27 }
32 - })  
33 -}  
  28 +
  29 + params = Object.assign({}, this.params, params);
  30 +
  31 + if (window) {
  32 + Object.assign(params, {
  33 + host: window.location.host,
  34 + url: window.location.href
  35 + });
  36 + }
  37 +
  38 + axios({
  39 + baseURL: 'https://app.yoho.cn/collect/v3',
  40 + url: '',
  41 + method: 'POST',
  42 + data: {
  43 + type,
  44 + device: {},
  45 + events: [
  46 + Object.assign({
  47 + uid: uid,
  48 + ts: new Date().getTime() + '000000',
  49 + pt: pt,
  50 + pn: pn,
  51 + param: params
  52 + }, this.events)
  53 + ]
  54 + }
  55 + })
  56 + }
  57 +}
@@ -95,6 +95,10 @@ export default { @@ -95,6 +95,10 @@ export default {
95 } else { 95 } else {
96 this.$yoho.goPage('go.ufo', { pagename: 'MerchantEntry' }); 96 this.$yoho.goPage('go.ufo', { pagename: 'MerchantEntry' });
97 } 97 }
  98 +
  99 + this.$root.reportApp('hb', 'BUSINESS_PLAN_A_EVENT', {
  100 + locfun: 'click:storeNow'
  101 + });
98 } 102 }
99 } 103 }
100 }; 104 };
@@ -26,6 +26,9 @@ export default { @@ -26,6 +26,9 @@ export default {
26 await store.dispatch('invite/invite/fetchAll'); 26 await store.dispatch('invite/invite/fetchAll');
27 } 27 }
28 }, 28 },
  29 + mounted() {
  30 + this.$root.reportAppStart();
  31 + },
29 data() { 32 data() {
30 return { 33 return {
31 title: '卖家邀新返利', 34 title: '卖家邀新返利',
@@ -86,6 +86,10 @@ export default { @@ -86,6 +86,10 @@ export default {
86 if (!this.banks.length) { 86 if (!this.banks.length) {
87 this.fetchBankList(); 87 this.fetchBankList();
88 } 88 }
  89 + this.$root.reportAppStart();
  90 + this.$root.reportApp('hb', 'BUSINESS_PLAN_A_EVEVT', {
  91 + locfun: 'click:bindBankCard'
  92 + });
89 }, 93 },
90 computed: { 94 computed: {
91 ...mapState(['banks', 'bankCardList']), 95 ...mapState(['banks', 'bankCardList']),
@@ -178,6 +182,10 @@ export default { @@ -178,6 +182,10 @@ export default {
178 } 182 }
179 }, 183 },
180 bindBankCardInfo(info) { 184 bindBankCardInfo(info) {
  185 + this.$root.reportApp('hb', 'BUSINESS_PLAN_A_EVENT', {
  186 + locfun: 'click:bindBankCard'
  187 + });
  188 +
181 let confirm = this.$createDialog({ 189 let confirm = this.$createDialog({
182 type: 'confirm', 190 type: 'confirm',
183 title: '提示', 191 title: '提示',
@@ -12,6 +12,7 @@ export default { @@ -12,6 +12,7 @@ export default {
12 name: 'cardList', 12 name: 'cardList',
13 mounted() { 13 mounted() {
14 this.$refs.cards.init(); 14 this.$refs.cards.init();
  15 + this.$root.reportAppStart();
15 }, 16 },
16 components: { 17 components: {
17 LayoutApp, 18 LayoutApp,
@@ -20,6 +20,7 @@ exports.createApp = async(app) => { @@ -20,6 +20,7 @@ exports.createApp = async(app) => {
20 app.locals.devEnv = app.get('env') === 'development'; 20 app.locals.devEnv = app.get('env') === 'development';
21 app.locals.proEnv = app.get('env') === 'production'; 21 app.locals.proEnv = app.get('env') === 'production';
22 app.locals.version = pkg.version; 22 app.locals.version = pkg.version;
  23 + app.locals.buildId = 'web' + new Date().getTime() + '000000';
23 24
24 if (config.zookeeperServer) { 25 if (config.zookeeperServer) {
25 const monitor = global.yoho.monitorSender; 26 const monitor = global.yoho.monitorSender;
@@ -12,6 +12,7 @@ const {createBundleRenderer} = require('vue-server-renderer'); @@ -12,6 +12,7 @@ const {createBundleRenderer} = require('vue-server-renderer');
12 const logger = global.yoho.logger; 12 const logger = global.yoho.logger;
13 const config = global.yoho.config; 13 const config = global.yoho.config;
14 14
  15 +const isProd = process.env.NODE_ENV === 'production';
15 const isDev = process.env.NODE_ENV === 'development' || !process.env.NODE_ENV; 16 const isDev = process.env.NODE_ENV === 'development' || !process.env.NODE_ENV;
16 17
17 let renderer; 18 let renderer;
@@ -34,7 +35,7 @@ if (!isDev) { @@ -34,7 +35,7 @@ if (!isDev) {
34 } 35 }
35 36
36 const getContext = (req) => { 37 const getContext = (req) => {
37 - return { 38 + let res = {
38 url: req.url, 39 url: req.url,
39 title: '', 40 title: '',
40 user: req.user, 41 user: req.user,
@@ -44,6 +45,9 @@ const getContext = (req) => { @@ -44,6 +45,9 @@ const getContext = (req) => {
44 isAndroid: req.yoho.isAndroid, 45 isAndroid: req.yoho.isAndroid,
45 isYohoApp: req.yoho.isYohoApp, 46 isYohoApp: req.yoho.isYohoApp,
46 clientIp: req.yoho.clientIp, 47 clientIp: req.yoho.clientIp,
  48 + version: pkg.version,
  49 + buildId: req.app.locals.buildId,
  50 + visitId: md5(`${req.query.udid}_${new Date().getTime()}`)
47 }, 51 },
48 ua: req.get('user-agent'), 52 ua: req.get('user-agent'),
49 hostname: os.hostname(), 53 hostname: os.hostname(),
@@ -51,6 +55,12 @@ const getContext = (req) => { @@ -51,6 +55,12 @@ const getContext = (req) => {
51 udid: _.get(req, 'cookies.udid', 'yoho'), 55 udid: _.get(req, 'cookies.udid', 'yoho'),
52 path: `[${req.method}]${routeEncode.getRouter(req)}`, 56 path: `[${req.method}]${routeEncode.getRouter(req)}`,
53 }; 57 };
  58 +
  59 + if (!isProd) {
  60 + res.env.unProd = true;
  61 + }
  62 +
  63 + return res;
54 }; 64 };
55 65
56 const handlerError = (err = {}, req, res, next) => { 66 const handlerError = (err = {}, req, res, next) => {