About 9 weeks ago Google released their Google Analytics Managment API which has been huge for the developer community. An open source Python library came out 2 weeks ago and today we’re releasing our open source PHP library.
This library allows your programmers to now access profiles, web properties, and goals programmatically. And because it extends the existing ga:pi() library, you can also programmatically get analytic data straight from Google Analytics at the same time. With the combined power, your developer can get direct access to very specific data from very specific profiles without having to download everything then sorting through it all afterwards. Way faster and way more efficient!
In condensed programmer speak: “This library is a class extension to the GA:PI() PHP5 library. With it, you can access analytic data feeds and management feeds returned as a single PHP5 object needing only one authorization token.” 😀
The source repository is available on Google Code or you can download it directly from this blog post. Because it extends the gapi class, you will also need to download that too:
How to use:
Using our PHP library is very similar to using the parent library:
require('gapi.class.php'); require('gManagementApi.class.php'); define('GA_EMAIL', 'myUsername');; define('GA_PASSWORD', 'mySecretPassword'); $ga = new gManagementApi(GA_EMAIL, GA_PASSWORD); // Get all the accounts $ga->requestAccountFeed(); // Get all web properties for all your accounts $ga->requestAccountFeed('~all'); // Get all web properties for specfically UA-12345-2 $ga->requestAccountFeed('12345'); // To get all the profiles you have access to for web property under account 12345 $ga->requestAccountFeed('12345', '~all'); // To get the profiles for a specific web property UA-12345-2 under account 12345 $ga->requestAccountFeed('12345', 'UA-12345-2'); // To get all the goals for profile 6789 for web property UA-12345-2 under acount 12345 $ga->requestAccountFeed('12345', 'UA-12345-2', '~all'); // To get everything and the kitchen sink $ga->requestAccountFeed('~all', '~all', '~all'); // To get all advanced segments $ga->requestAdvancedSegmentFeed();