ios - Google Analytics 如何整合到具有离线/在线模式的 HTML5 移动应用程序中?

标签 ios html jquery-mobile google-analytics google-analytics-api

我有一个基于 JQuery Mobile 的 HTML5 移动应用程序。它不从服务器获取任何内容,有时会连接到互联网,但也有离线模式。 Google Analytics 是否支持离线模式?请注意,我没有使用 Android/iOS SDK。 JQueryMobile 页面中的 ga.js。谢谢

下面是我的 html5 JQueryMobile 代码:

    <!DOCTYPE html> 
<html> 
<head> 
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Mobile @ Your Library</title>
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.0/jquery.mobile-1.0.min.css" />

 <script type="text/javascript" src="http://code.jquery.com/jquery-1.6.4.min.js">  </script>
<script type="text/javascript" src="http://code.jquery.com/mobile/1.0/jquery.mobile-1.0.min.js"></script>
<script type="text/javascript">

    var _gaq = _gaq || [];
    _gaq.push(['_setAccount', 'UA-40418-saddf']);

    _gaq.push(['_gat._anonymizeIp']);

    (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/u/ga_debug.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
     })();

</script>



</script>
<body> 

<div data-role="header" data-theme="d"> 
    <h1>Mobile @ Your Library</h1>
    <a href="#home" data-icon="home" data-iconpos="notext" data-theme="d" class="ui-btn-right">home</a>
</div><!-- /header --> 

<div data-role="content">
    <ul data-role="listview" data-inset="true">
        <li><a href="#search">Search</a></li>
        <li><a href="#hours">Hours</a></li>
        <li><a href="#ask">Ask a Librarian</a></li>
        <li><a href="#about">About</a></li>
        <li><a href="#where" data-rel="dialog" data-transition="pop">Where</a></li>
    </ul>       

</div><!-- /content --> 

<div data-role="footer" data-id="myfooter" data-position="fixed" data-theme="d"> 
    <div class="controls" data-role="controlgroup" data-type="horizontal">
        <a href="#home" data-role="button" data-icon="home">Home</a>
        <a href="#search" data-role="button" data-icon="search">Search</a>
        <a href="#ask" data-role="button" data-icon="info">Ask</a>
        <a href="/index.php" rel="external" data-role="button" data-icon="plus">Full site</a>
    </div>
</div><!-- /footer -->  
</div><!-- /page -->
<!--
<script type="text/javascript">
$('[data-role=page]').live('pageshow', function (event, ui) {
    console.log('pageshow called s');
    console.log('pageshow called s2');
     try {
    _gaq.push( ['_trackPageview', event.target.id] );
    console.log('tracked '+event.target.id);
    } catch(err) {
       console.log('error '+ err);
    }

});
</script>-->
<script type="text/javascript">
$(document).delegate('[data-role=page]', 'pageshow', function (event, ui) {
console.log('pageshow event '+ui.prevPage.id);
var url = location.href;
console.log('pageshow url = '+url);
try  {

    if (location.hash) {

        url = location.hash;
        console.log('location.hash so now url = '+url);
    }
    console.log('about to push page '+url);
    //_gaq.push(['_trackPageview', url]);
    _gaq.push( ['_trackPageview', event.target.id] );
    console.log('about to push page '+url);
} 
catch(error) {
    // error catch
    console.log('error '+error);
}
});

</script>
</body> 
</html>

最佳答案

GA 代码必须能够向服务器发送请求以跟踪数据。如果您处于离线模式且未发出任何请求,则不会进行跟踪。

关于ios - Google Analytics 如何整合到具有离线/在线模式的 HTML5 移动应用程序中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16228103/

相关文章:

jquery - 如何更改此 carousel-title 类的 CSS 样式?

html - 从 URL (PATH) 下载 - iPhone

javascript - 名称中包含空格的 JSON 调用数据数组

javascript - jquery mobile Pageshow - 删除以前的数据

ios - 如何在 uicollectionview header 中添加 uicollectionview

ios - UIGestureRecognizer 和 UITextView

jquery - 更改可折叠元素的默认高度

jquery - div jquery mobile中的下一个上一个按钮

ios - 如何从字典 [Objective-C] 中的其他键中删除对象?

ios - 将通用函数从 Alamofire 3 迁移到 Alamofire 4