gpt4 book ai didi

jquery-mobile - 如何将 Google Analytics 与 jQuery Mobile 应用程序集成?

转载 作者:行者123 更新时间:2023-12-03 17:06:14 24 4
gpt4 key购买 nike

我尝试使用多页模板开发 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>

如何将 Google Analytics 与 jQuery Mobile 应用程序集成?

最佳答案

$(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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com