作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我尝试使用多页模板开发 jQuery Mobile 应用程序。我想将 Google Analytics 添加到应用程序中。
我引用了这个文件,Using Google Analytics with jQuery Mobile .它似乎不适用于我的应用程序。
我的应用程序中的代码如下:
<script type="text/javascript">
var _gaq = _gaq || [];
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(ga, s);
})();
$('[data-role=page]').on('pageshow', function (event, ui) {
try {
_gaq.push(['_setAccount', 'UA-30119852-1']);
hash = location.hash;
if (hash) {
_gaq.push(['_trackPageview', hash.substr(1)]);
} else {
_gaq.push(['_trackPageview']);
}
} catch(err) {
}
});
</script>
最佳答案
$(document).delegate('[data-role=page]', 'pageshow', function (event, ui) {
console.log('pageshow event handler called for ');
var url = location.href;
console.log('pageshow event url = '+url);
try
{
//_gaq.push(['_trackPageview', url]);
_gaq.push( ['_trackPageview', event.target.id] );
console.log('done pushing page '+url);
}
catch(error) {
// error catch
console.log('got error '+error);
}
});
关于jquery-mobile - 如何将 Google Analytics 与 jQuery Mobile 应用程序集成?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11254805/
我是一名优秀的程序员,十分优秀!