angularjs - ngCordova 谷歌分析 ($cordovaGoogleAnalytics)

标签 angularjs cordova plugins google-analytics ionic-framework

我正在尝试使用' 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/

相关文章:

javascript - 如何交换下拉值?

android - Phonegap + Android status=0 从网络服务返回

plugins - 如何找出 rustc::middle::ty::Ty 代表什么类型?

javascript - 在哪里可以找到一个好的 jQuery 投影插件?

android - Cordova 3.4.0 : Camera. getPicture() 从 GALLERY 中选择时返回编码的 URI

php - WordPress 错误 : There has been a critical error on your website. 请检查您的站点管理员电子邮件收件箱以获取说明

javascript - Angular Firebase 从匿名用户检索收集的数据

javascript - 如何访问 DIV 的 innerHTML onclick(ng-click)Angular JS 中的按钮

javascript - 使用 Angular ng-repeat 在数组中显示数组对象

javascript - $scope.$apply() 在状态导航后不工作