0

我在尝试将Google Analytics添加到我的应用中。我正在使用Dan Wilson的Google Analytics插件。我没有收到任何错误,但我的Google Analytics信息中心根本没有更新。我错在哪里,Google Analytics插件不报告控制台中的用户

var googleanalyticsApp = angular.module('starter', ['ionic','ngCordova']) 

.run(function($ionicPlatform) { 
$ionicPlatform.ready(function() { 
if(window.cordova && window.cordova.plugins.Keyboard) {  
    cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);  
    cordova.plugins.Keyboard.disableScroll(true); 
} 
if(window.StatusBar) { 
    StatusBar.styleDefault(); 
} 

if(typeof analytics !== undefined) {     
      analytics.startTrackerWithId("UA-872489XX-1"); 
      console.log("Analytics Initialized"); 
     } else { 
      console.log("Google Analytics Unavailable"); 
     } 
    }); 
}); 

googleanalyticsApp.controller('ExampleController', function($scope,$cordovaGoogleAnalytics) { 
function _waitForAnalytics(){ 

     if(typeof analytics !== 'undefined'){   
     analytics.startTrackerWithId("UA-872489XX-1"); 
     analytics.trackView('APP first screen');   
     console.log("Analytics in Controller"); 
     } 

     else{ 

     setTimeout(function(){ 

     _waitForAnalytics(); 

     },250); 

     } 
     }; 

    _waitForAnalytics(); 

我已经在Device Ready和Controller中初始化Google Analytics。 CONSOLE.LOG状态为: Console

但我的仪表盘完全不

Dashboard

更新请,帮助我。

+0

纠正我,如果我错过了一些代码,但我没有看到任何调用'trackView','trackEvent'或插件中包含的任何其他跟踪功能。所以......你期望什么被准确跟踪?另请注意,Google Analytics可能需要几个小时才能显示实际结果,但您可以尝试使用实时视图,但可以百分之百地确定它是否正常运行,并给它几小时的更新时间(会提示有现在再看一下,如果没有显示,请添加一些跟踪调用)! – OClyde

+0

嗨@OClyde,我已经添加了TrackView(同时显示在代码中) –

回答

1

您的仪表板指向11月14日至11月14日。将此更改为当天,默认为前一天。

数据最长可能需要24小时才会显示在Analytics控制台中。还有,为什么在调用分析函数时有不同的命名约定?您可以在代码中将“analytics”更改为$ cordovaGoogleAnalytics。

+0

花了一个更长的时间来更新 –

1

您需要设置trakid在app.js平台准备像下面 -

$ionicPlatform.ready(function() { 
    if(typeof analytics !== undefined) {     
      analytics.startTrackerWithId("UA-872489XX-1"); // set your trakId 
      console.log("Analytics Initialized"); 
     } else { 
      console.log("Google Analytics Unavailable"); 
     } 
    }); 
}) 

如果以上都不行使用下列 -

$ionicPlatform.ready(function() { 
     if(window.ga != undefined) { 
         window.ga.startTrackerWithId("UA-872489XX-1"); 
        } else { 
         console.log("Google Analytics Unavailable"); 
        } 
    }) 

像下面然后在每个控制器只需设置视图 -

googleanalyticsApp.controller('ExampleController', function($scope,$cordovaGoogleAnalytics) { 
    // Here no need to wait to load analytics as already loaded 
    analytics.trackView('APP first screen');   

}) 
相关问题