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');   

}) 
相關問題