Red Analytics Demo |
|
Google Analytics Data Export APIThe Google Analytics Data Export API allows client applications to request data from an existing Analytics profile for an authorized user, and refine the results of the request using query parameters. Currently, the Data Export API supports read-only access to Google Analytics data. The current feeds in the Data Export API contain two general categories of Analytics data:
Analytics account and profile data
Analytics report data from a single profile
I will cover actually retrieving the data using the Google Analytics API PHP Class in the next section. However reading the Google Analytics Data Export API is useful in providing some understanding of the API. The most important information is in the Dimensions & Metrics Reference which covers the various types and valid combinations of Analytics data that can be retrieved via the API. An example would be to retrieve the number of visits by date, you would use the dimension ga:date and the metric ga:visits. Google Analytics API PHP ClassAfter deciding I wanted to use the Google Analytics Data Export API and knowing that I would like to process the data on the server using PHP I looked around the Google Analytics site and found in the Articles section a reference to an article by Chris Hope entitled "Google Analytics & PHP Tutorials". In the series of blog posts by Chris he details how he has built a PHP class for accessing the Google Analytics API with CURL and using DOMDocument to parse the returned XML. The class itself is very easy to use and I have had no issues in using it, an example of it's simplicity shown below: Basically all you need to do is include the class, which you can download from Chris's site and then login using an existing Google Analytics account details and then return some data using the data function. Full details of it's use and more examples are available on Chris's Blog. |