在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) {
    }
  })
}

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

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

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

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

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

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

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

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

可以看到代码安装正确啦

相关文章:

  • 2021-12-16
  • 2021-08-27
  • 2021-10-25
  • 2022-02-26
  • 2021-11-23
猜你喜欢
  • 2021-12-18
  • 2022-12-23
  • 2021-06-16
  • 2021-06-03
  • 2022-12-23
  • 2021-08-06
相关资源
相似解决方案