gpt4 book ai didi

angularjs - ngCordova 谷歌分析 ($cordovaGoogleAnalytics)

转载 作者:行者123 更新时间:2023-12-03 15:23:55 25 4
gpt4 key购买 nike

我正在尝试使用' https://github.com/danwilson/google-analytics-plugin.git ' 带有 ngCordova 的插件。我已经添加了插件并在我的 Controller 中添加了 ngCordova 作为依赖项。

当我尝试设置时:

$cordovaGoogleAnalytics.startTrackerWithId('UA-XXXXXXXX-X'); 

我收到此错误:“类型错误:无法读取未定义的属性 'startTrackerWithId'”。

我已将我的分析设置为 Google 仪表板中的移动应用程序。

有人可以帮忙吗?

最佳答案

发生这种情况是因为您在cordova 初始化之前尝试使用分析插件。

只需使用 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();

关于angularjs - ngCordova 谷歌分析 ($cordovaGoogleAnalytics),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26910421/

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