我正在尝试在ngCordova中使用‘ngCordova’插件。我在控制器中添加了插件并添加了ngCordova作为依赖项。
当我试图设置:
$cordovaGoogleAnalytics.startTrackerWithId('UA-XXXXXXXX-X'); 我得到了这个错误:'TypeError:无法读取属性'startTrackerWithId‘的未定义’。
我已经将我的分析设置为谷歌仪表板上的移动应用程序。
有人能帮忙吗?
发布于 2014-11-13 14:54:07
这是因为在科多瓦初始化之前,您正在尝试使用分析插件。
只需用一个setTimetout递归地包装初始化:
function _waitForAnalytics(){
if(typeof analytics !== 'undefined'){
$cordovaGoogleAnalytics.debugMode();
$cordovaGoogleAnalytics.startTrackerWithId('UA-XXXXXXXX-X');
$cordovaGoogleAnalytics.trackView('APP first screen');
}
else{
setTimeout(function(){
_waitForAnalytics();
},250);
}
};
_waitForAnalytics();发布于 2016-08-18 19:49:30
我认为这是使用google分析进行跟踪的最佳方法。
$ionicPlatform.ready(function () {
$rootScope.$on('$stateChangeSuccess', function () {
if(typeof analytics !== undefined) {
analytics.debugMode();
analytics.startTrackerWithId("UA-xxxxxxxx-x");
analytics.trackView($state.current.name);
} else {
console.log("Google Analytics Unavailable");
}
});
});这将跟踪应用程序上的每个状态更改,并给出用户所处的状态。
https://stackoverflow.com/questions/26910421
复制相似问题