Browse Source

feat(tongji): upd

曾志翔 3 years ago
parent
commit
493c63b868
3 changed files with 15 additions and 16 deletions
  1. 1 12
      pages/activity/invite-user.vue
  2. 6 4
      pages/register-for-invite.vue
  3. 8 0
      plugins/baidu-tongji.js

+ 1 - 12
pages/activity/invite-user.vue

@@ -133,18 +133,7 @@ export default {
   mounted() {},
   methods: {
     share() {
-      // window.aplus.getNextTrackCode(
-      //   {
-      //     appkey: '',
-      //     openid: '',
-      //     unionId: 'aTestUnionid',
-      //     trackCode: '',
-      //     rootTrackCode: '',
-      //     url: location.href || 'testurl',
-      //   },
-      //   () => {},
-      // );
-      window._hmt.push(['_trackEvent', '活动', '分享', '邀请好友', 0]);
+      this.$tongji.trackEvent('活动', '分享', '', 0);
       this.$native.share({
         title: '标题',
         content: '内容',

+ 6 - 4
pages/register-for-invite.vue

@@ -13,8 +13,8 @@
 </template>
 
 <script>
-import { registerForInvite } from '~/api/user/client.js'
-import { sendSmsCode } from '~/api/message/phone.js'
+import { registerForInvite } from '~/api/user/client.js';
+import { sendSmsCode } from '~/api/message/phone.js';
 export default {
   name: 'RegisterForInvite',
   data() {
@@ -36,10 +36,12 @@ export default {
   },
   methods: {
     async register() {
-      await registerForInvite(this,this.form);
+      this.$tongji.trackEvent('活动', '注册', '', 0);
+      await registerForInvite(this, this.form);
     },
     async sendSmsCode() {
-      const res = await sendSmsCode(this,{
+      this.$tongji.trackEvent('活动', '发送短信', '', 0);
+      const res = await sendSmsCode(this, {
         type: 'common',
         authorizationType: 4,
         phone: this.form.phone,

+ 8 - 0
plugins/baidu-tongji.js

@@ -1,6 +1,7 @@
 export default function (c, i) {
   const { app, $auth, store } = c;
   window._hmt = window._hmt || [];
+
   window._hmt.push(['_setAutoPageview', false]);
   window._hmt.push(['_setCustomVar', 1, 'MODE', process.env.MODE, 1]);
   app.router.afterEach((to, from) => {
@@ -27,4 +28,11 @@ export default function (c, i) {
     {},
   );
   setUserId();
+  i('tongji', {
+    // 上报pv
+    trackPageview: (path) => window._hmt.push(['_trackPageview', path]),
+    // 上报事件
+    trackEvent: (category, action, optLabel, optValue) =>
+      window._hmt.push(['_trackEvent', category, action, optLabel, optValue]),
+  });
 }