Browse Source

'加入百度统计'

chending1994 5 years ago
parent
commit
002ac13efd
2 changed files with 14 additions and 2 deletions
  1. 5 2
      nuxt.config.js
  2. 9 0
      plugins/baidu.js

+ 5 - 2
nuxt.config.js

@@ -40,7 +40,9 @@ export default {
       { rel: 'icon', type: 'image/x-icon', href: '/favicon.ico' },
       { rel: 'stylesheet', href: '/common/common.css' }
     ],
-    script: []
+    script: [
+      { src: 'https://hm.baidu.com/hm.js?2a45c0311559f89f2ee65d1ac438d204' }
+    ]
   },
   /*
   ** Global CSS
@@ -60,7 +62,8 @@ export default {
     { src: "@/plugins/vue-swiper", ssr: false },
     {
       src: '@/plugins/filter.js'
-    }
+    },
+    { src: '~/plugins/baidu.js' }
   ],
   /*
   ** Auto import components

+ 9 - 0
plugins/baidu.js

@@ -0,0 +1,9 @@
+export default ({ app: { router }, store }) => {
+  router.afterEach((to, from) => {
+    /* 告诉增加一个PV */
+    try {
+      window._hmt = window._hmt || []
+      window._hmt.push(['_trackPageview', to.fullPath])
+    } catch (e) {}
+  })
+}