I have created a function which queries the Google Analytic API and get some data. It works fine. I used a console.log to confirm. But I need to get this data to a variable. Here's the function :
function getActiveUsers() {
...
// Set data
authClient.authorize(function(err, tokens) {
if (err) {
console.log(err);
return;
}
analytics.data.realtime.get({
auth: authClient,
'ids': 'ga:ID',
'metrics': 'rt:activeUsers'
}, function(err, result) {
console.log(err);
return result; // I want this result
});
});
}
Now I wont the result into a variable like this :
result = getActiveUsers();
How can I do this? Please help.