我使用命令在https://github.com/danwilson/google-analytics-plugin成功安装了插件
cordova plugin add https://github.com/danwilson/google-analytics-plugin.git
下面是我在index.js中的跟踪器
var app = {
// Application Constructor
initialize: function() {
this.bindEvents();
},
bindEvents: function() {
document.addEventListener('deviceready', this.onDeviceReady, false);
},
onDeviceReady: function() {
app.receivedEvent('deviceready');
},
// Update DOM on a Received Event
receivedEvent: function(id) {
var parentElement = document.getElementById(id);
var listeningElement = parentElement.querySelector('.listening');
var receivedElement = parentElement.querySelector('.received');
listeningElement.setAttribute('style', 'display:none;');
receivedElement.setAttribute('style', 'display:block;');
console.log('Received Event: ' + id);
// replaced with fake tracker id
window.analytics.startTrackerWithId('UA-1234-1');
}
};
app.initialize();
现在我尝试在landing.js文件中使用window.analytics.trackView('Landing')
,但它会抛出未捕获的TypeError:无法读取属性' trackView'未定义的
$(document).on('pagebeforeshow', '#landing', function(){
window.analytics.trackView('Landing');
$(document).on('click', '#guest', function() {
event.preventDefault();
window.location.href = "guest_search.html";
});
下面是我home.html的头标记,我在哪里获取我的.js文件
<head>
<meta charset="utf-8" />
<!--<meta name="viewport" content="width=device-width, initial-scale=1">-->
<meta name="viewport" content="initial-scale=1">
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.css" />
<link href="css/style.css" rel="stylesheet">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script src="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js"></script>
<script src="http://cdn.jsdelivr.net/jquery.validation/1.13.1/jquery.validate.min.js"></script>
<script src="cordova.js" type="text/javascript"></script>
<script src="js/index.js" type="text/javascript"></script>
<script src="js/landing.js" type="text/javascript"></script>
</head>
这应该很容易。不知道我做错了什么,有什么建议吗?