Google Analytics:如何在单页应用程序中跟踪页面? [英] Google Analytics: How to track pages in a single page application?

查看:53
本文介绍了Google Analytics:如何在单页应用程序中跟踪页面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前在我的网站中,我使用了 HTML5 的 pushState()popState 链接以提高速度.但是,这并没有真正改变真实 URL,而且看起来它会影响和弄乱Google Analytics 的代码.(不显示网址更改)是否有可能的解决方案?谢谢,

Currently in my website, I used HTML5's pushState() and popState in links to increase the speed. However, this doesn't really change the real URL and it looks like it will affect and mess up the Google Analytics's code. (doesn't show a url change) Is there a possible solution for this? Thanks,

推荐答案

如果您使用的是较新的 analytics.js API,Google 的文档 需要以下代码来触发事件:

If you are using the newer analytics.js API, Google's documentation requires the following code to trigger the event:

ga('send', 'pageview', '/some-page');

如果您使用旧的 ga.js API,David Walsh 建议 AJAX网站使用_gaq.push方法:

If you are using the older ga.js API, David Walsh suggests AJAX websites to use the _gaq.push method:

_gaq.push(['_trackPageview', '/some-page']);

这篇关于Google Analytics:如何在单页应用程序中跟踪页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆