0
私はカスタムアナリティクスダッシュボードを作成するためにGoogleAnalytics Embed APIを使用しています。Googleアナリティクスの値を変数にキャスト
現在、私のコードは次のようになります。
私の問題は、私は、他の計算で変数CurrentUsers
を使用しようとしていますということです。
は、ここに私のコード応答関数内ので
var CurrentUsers; // declared globally
gapi.analytics.ready(function() {
var CurrentVisitorsData = new gapi.analytics.report.Data({
query: {
ids: 'ga:xxxxxx',
metrics: 'ga:users',
'start-date': '7daysAgo',
'end-date': 'yesterday'
}
});
CurrentVisitorsData.on('success', function(response) {
CurrentUsers = response.totalsForAllResults['ga:users'];
console.log (CurrentUsers); //this displays the correct number of current users
});
CurrentVisitorsData.execute();
console.log (currentUsers); // This one returns Uncaught ReferenceError: CurrentUsrs is not defined
});
変数作品だが、それはしていません後。複数の変数を使用して操作を実行する必要があるため、レスポンス関数で行う必要があることはできません。
私はsuccess関数の外でその値にどのようにアクセスできますか?