The first step in using the Google Analytics API to retrieve insightful data into your PHP application is logging in. To this end we will use Zend Framework's Gdata libraries which get rid of much of the hassle by providing a comprehensive set of classes and functions that cover most of the GA API needs. The mechanism is simple: you boot up a connection client, use it to open a feed and use that feed to retrieve the necessary reports from GA.
$email = 'some@email.com'; // The email that identifies the Google Analytics Account
$password = 'xXxXxXxXx'; // The Google Analytics account's password
$client = Zend_Gdata_ClientLogin::getHttpClient($email,$password, 'analytics', null, 'curl-accountFeed-v2', null, null, 'https://www.google.com/accounts/ClientLogin', 'GOOGLE');
$feed = new Zend_Gdata_Gapps($client);
$response = $feed->get('https://www.google.com/analytics/feeds/data?ids=ga:13962678&dimensions=ga:browser&metrics=ga:pageviews&filters=ga:browser%3D~%5EFirefox&start-date=2009-01-01&end-date=2009-12-31');
$xml = $response->getBody();
And now, in the $xml variable holds the raw XML with the data from the report so you can collect it and use it in your app!


