尝试使用最新的谷歌分析跟踪代码的网站,使用Barba JS,但它不会跟踪过去的第一页,即用户的路径,任何人的想法?
发布于 2019-06-07 22:40:14
它只能在初始页面上运行的原因是,使用gtag.js实现的默认GA片段在加载后只运行一次。由于您在SPA设置中使用它,因此在路由时需要手动重新发送页面数据。查看barbajs文档,我认为应该是这样的:
// define a global hook, using afterEnter, but you can adjust to enter, beforeEnter, etc as you see fit.
barba.hooks.afterEnter((data) => {
// this hook will be called for each transitions
//data.current.url is the page path.
gtag('config', 'UA-#######-1', {'page_path': data.current.url});
});发布于 2019-08-30 11:21:26
使用google annalitics https://developers.google.com/analytics/devguides/collection/analyticsjs/?hl=en提供的完整代码
在你JS中添加
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-XXXXX-Y', 'auto');
ga('send', 'pageview');https://stackoverflow.com/questions/56495894
复制相似问题