Wit*_*tek 12 html javascript google-analytics jquery-mobile
jQueryMobile会像每个站点一样加载其第一页.通常的Google Analytics集成工作 - 跟踪请求.但是后续页面是异步加载的,并且不会跟踪用户点击.
如何将Google Analytics集成到jQueryMobile网站中,以便跟踪所有页面点击?
Fil*_*lip 15
Jon Gales写了一篇很棒的文章.
http://www.jongales.com/blog/2011/01/10/google-analytics-and-jquery-mobile/
这是他推荐使用的代码:
$('[data-role=page]').live('pageshow', function (event, ui) {
try {
_gaq.push(['_setAccount', 'YOUR_GA_ID']);
hash = location.hash;
if (hash) {
_gaq.push(['_trackPageview', hash.substr(1)]);
} else {
_gaq.push(['_trackPageview']);
}
} catch(err) {
}
});
Run Code Online (Sandbox Code Playgroud)
更新
由于live现在已弃用on,因此如果您使用的是jQuery 1.7+,则应使用该事件.http://api.jquery.com/on/