nuxt项目添加百度统计的代码

在nuxt项目中添加百度统计的代码

个人博客已经建好,欢迎各位前来访问 http://mengyang.info/

  1. 在plugin文件夹中新建一个js文件,添加如下的代码:
export default ({app: {router}, store}) => {
  /* 每次路由变更时进行pv统计 */
  router.afterEach((to, from) => {
    /* 告诉增加一个PV */
    try {
      window._hmt = window._hmt || []
      window._hmt.push(['_trackPageview', to.fullPath])
    } catch (e) {
    }
  })
}

image-20200727223438706

  1. 在nuxt.config.js中配置这个插件

在head的script中加入自己的百度统计代码

image-20200727223737046

在plugin中注册刚才创建的插件文件夹

image-20200727223757491

然后过20分钟再去百度统计的网站上检查下代码安装成功没

image-20200727223955637

可以看到代码安装正确啦

猜你喜欢

转载自www.cnblogs.com/my466879168/p/13388206.html