Loading... Vue的单页面应用想使用谷歌分析该怎么做呢 查了一些资料,要在router里面下文章 GA事件的网页追踪原理是每一次网页跳转都会调用那个gtag('config')代码,然后追踪当前页面。但是对于单页面来说,其实页面只加载了一次index.html,所以造成了数据丢失。 解决方法:在全局路由钩子里面加上手动添加page_path。 ``` router.afterEach((to, from, next) => { gtag('config', 'UA-ID', {'page_path': to.fullPath}); }); ``` Last modification:May 25th, 2020 at 02:05 pm © 允许规范转载 Support 请博主喝一杯咖啡 ×Close Appreciate the author Sweeping payments Pay by AliPay Pay by WeChat