Google Analytics API - Too complicated?

I've read about Google Analytics API but heard of others that it is a bit complicated to make it work. I use PHP.

Copy / paste example

My question is if there is a copy / paste example anywhere on the web for getting a stats curve of the latest month, or just the numbers for that period?


I need to use the new Google Analytics API version for 2012. The other one is going to die soon.


If you have experience programming in PHP and API's and you plan to only use the data from your own account the simplest method would be to use GAPI http://code.google.com/p/gapi-google-analytics-php-interface/

With this you hard code your Google email and password to gain access it does not use OAuth.

If you are building a 3rd party application that others will use to gather data. You should absolutely use OAuth so tokens are used and not passwords. For this read the OAuth guide https://developers.google.com/gdata/articles/oauth

Then use the Analytics data explorer to authenticate, and build a query URL. Take this URL and go to the OAuth Playground, go through the authentication process and post the URL. You will then see the XML response from Google Analytics with the data you wanted, now you can use the data however you want.

Google Analytics API v3 PHP Beta libraries from Goolge https://developers.google.com/analytics/devguides/reporting/core/v3/gdataLibraries

  • At GAPI it says "The current version of gapi-google-analytics-php-interface use google analtytics api v2.3 . This version will be no longer available because a new version out v3." – Jens Törnell Jun 10 '12 at 13:37
  • 1
    I updated my answer to include a link to Google Analytics v3 libraries – Anagio Jun 10 '12 at 23:20
  • GAPI now supports v3 and OAuth2 for Google Analytics – Stig Manning May 30 '15 at 11:55

Not the answer you're looking for? Browse other questions tagged or ask your own question.