|
GoogleAnalyticsAPI
A PHP class library used to programatically access Google Analytics reporting data
IntroductionThere's no official API available to get at Google Analytics reporting data, so this library was created to help you programatically get at your reporting data and use it in a third party reporting application. In particular, the WordPress Reports plugin utilizes this library to retrieve and present quick 7 day overviews in the WordPress admin dashboard. Download the latest version of the library from SVN here: http://wordpress-reports.googlecode.com/svn/trunk/tantan/wordpress-reports/lib.googleanalytics.php You may also need the TanTanCurl library if you don't have PEAR installed, which basically emulates the PEAR's HTTP package with libcurl. http://tantan-toolkit.googlecode.com/svn/trunk/plugins/tantan/lib/curl.php Documentation is sparse for now. Please see PHP file for a full list of methods and available report types. Usage Code Examplerequire('lib.googleanalytics.php');
$ga = new tantan_GoogleAnalytics();
$ga->login('yourusername@gmail.com', 'yourpassword');
$accounts = $ga->getAccounts(); // retrieve accounts you have access to
print_r($accounts);
$profiles = $ga->getSiteProfiles($accountID); // retrieve site profiles for an account
print_r($profiles);
$report = $ga->getReport($profileID, '20071201', '20071214', 'pageviews'); // retrieve a pageviews report
print_r($report);
|
Sign in to add a comment
Ce script ne fonctionne pas chez moi : problème avec PHP :
Notice: Use of undefined constant HTTP_REQUEST_METHOD_GET - assumed 'HTTP_REQUEST_METHOD_GET' in c:\program files\easyphp1-8\www\test\lib.googleanalytics.php on line 92
I have done everything to get the Google Analytics to work on my blog. I am using wordpress 2.6.1. The feedburner works fine I guess, but the problem I face is when I have to select profile for google analytics, it only shows a combo box with select profile and default profile inspite of the fact that I have couple of profiles in my GA account.
Please help me with this, thank you.
I have the same problem, it only shows a combo box with select profile and default profile. I work with WP 2.3.3 Thank you for your help.
Hello, I have done with API integration as shown in above code. Currently I am able to get accountid, profileid. Have a look
require('lib.googleanalytics.php');
$ga = new tantan_GoogleAnalytics?();
$ga->login('xxxxxxx@gmail.com', 'xxxxxx');
$accounts = $ga->getAccounts(); // retrieve accounts you have access to
print_r($accounts);
$accountID = xxxxxxx1;
$profiles = $ga->getSiteProfiles($accountID); // retrieve site profiles for an account
print_r($profiles);
$profileID= xxxxxxx2;
$report = $ga->getReport($profileID, '20080701', '20081114', 'pageviews');
But I am not able to get Pageviews. $ report array is blank array(); I checked with different state and end dates.
Can you please tell me what I am missing?
Thanks in advance. betterwaytodo
Betterwaytodo, Check your Date ranges I was getting the same Error Until I punched in the exact dates from the URL that Google gave me and it worked.
really good script. Its really very helpful.
Check this out http://www.ceritosoftware.com/articles/index/page/php-access-google-analytics-api