I had a hard time for this one... google realtime API is pretty recent. But it's still quite cumbersome to getting something working well. I thought would be much easier than that, the hardest part is to understand which settings and Id are the right one...
1) request access to realtime API, Create an app with a name and key and all on google API page
https://cloud.google.com/console/project
2) Download and setup php API : google-api-php-client
3) Note that your "Id" or "ga:xxx" number is not the one you may think of:
it is not the "UA-112233 " that you saw on your google analytics, but the number behind any analytics report link...
Look at a google analytics report page's link:
https://www.google.com/analytics/web/?hl=pt-BR&pli=1#report/visitors-overview/a1162727w13022229p612345667/
Then take the last number behind the letter "p":
here it would be "612345667", that's your ga:612345667
4) Bug on the google api php:
Add this line :
$client->setUseObjects(true);
on your code after the new Google Client object creation: $client = new Google_Client();
https://stackoverflow.com/questions/21116417/google-analytics-api-php-object-vs-array
Useful links:
Google analytics general PHP api:
http://enarion.net/programming/php/google-client-api/google-client-api-php/
From google:
https://cloud.google.com/console/project
https://developers.google.com/analytics/devguides/reporting/realtime/v3/reference/data/realtime/get#auth
The Api bug
https://stackoverflow.com/questions/21116417/google-analytics-api-php-object-vs-array
1) request access to realtime API, Create an app with a name and key and all on google API page
https://cloud.google.com/console/project
2) Download and setup php API : google-api-php-client
3) Note that your "Id" or "ga:xxx" number is not the one you may think of:
it is not the "UA-112233 " that you saw on your google analytics, but the number behind any analytics report link...
Look at a google analytics report page's link:
https://www.google.com/analytics/web/?hl=pt-BR&pli=1#report/visitors-overview/a1162727w13022229p612345667/
Then take the last number behind the letter "p":
here it would be "612345667", that's your ga:612345667
4) Bug on the google api php:
Add this line :
$client->setUseObjects(true);
on your code after the new Google Client object creation: $client = new Google_Client();
https://stackoverflow.com/questions/21116417/google-analytics-api-php-object-vs-array
Useful links:
Google analytics general PHP api:
http://enarion.net/programming/php/google-client-api/google-client-api-php/
From google:
https://cloud.google.com/console/project
https://developers.google.com/analytics/devguides/reporting/realtime/v3/reference/data/realtime/get#auth
The Api bug
https://stackoverflow.com/questions/21116417/google-analytics-api-php-object-vs-array
Commentaires
Enregistrer un commentaire
Tell me what you think