2008-09-26
Google Analytics Export Script
If you want to export Google Analytics statistics data you'll see that there is no API or automatic script for that. But help can be found at Sergej Müller Blog. Sergej gives you a free php script to export your data using curl.
Based on the idea to use Flex / Flash for displaying fancy statistics, I modified the script to also export all the other statistics like GeoMapReport, TrafficSourcesReport, LanguagesReport, ... and I also removed the cache and graphs completely! So this version returns raw xml only! The modified version is available here!
Simply extract the content to some webfolder, open export.php and fill in your settings.
A call to http://localhost/analytics/export.php will return the GeoMapReport of the last 30 days. But you may want to add additional parameters like the timespan or the report type:
export.php?pdr=20080808-20080907&rpt=PageviewsReport
Read the code to see the other available reports!
14 Comments
-
[...] Google Analytics Export [...]
-
Get “no input file specified” as reply.
What do I do wrong?Thx
-
hmmm, I did not get a similair error message yet so it’s difficult to reproduce. did you set the following vars in export.php?
$config['email'] = ‘youremail@gmail.com’;
$config['password'] = ‘yourpassword’;
$config['ids'] = array(123456789);and then a simple call to:
http://localhost/analytics/export.php
should work!In case you do not know your $config['ids'] please login to your analytics account and select a profile!
in your browser you should see a url similar like this:
https://www.google.com/analytics/reporting/?reset=1&scid=200415&id=879834
the 879834 is your analytics-id which you have to copy into your
$config['ids'] = array(879834); -
Hi,
this is an amazing tool! Thanks so much. I’ve tried a number of correct email/password/id combinations and I get the same error every time:
“Notice: Undefined offset: 1 in /home/floh/public_html/test/analytics-proxy/inc/curl.class.php on line 163
Notice: Undefined variable: response_code in /home/floh/public_html/test/analytics-proxy/inc/curl.class.php on line 176
Your login and password don’t match. Make sure you’ve typed them in correctly.”Any idea what’s going on? Do I have a server issue?
Thanks a lot!
-
no idea! to reproduce I’d probably require your email/password and id but I guess you don’t want to share them with me! if you found the bug please tell me!
-
If you want to export the report directly to Google Docs, you can use the Greasemonkey script that I wrote.
You can find it here:
http://spanishgringo.blogspot.com/2009/01/new-version-of-analytics-export-to.html -
this is php5 only right?
-
Hmm… might probably also work with php4. But I am not sure.
-
[...] This plugin uses the Google Analytics export script from Manifred Weber. [...]
-
thank you.thank you.thank you.thank you.thank you.thank you.thank you.thank you.thank you.thank you.thank you.thank you.thank you.thank you.thank you.thank you.thank you.thank you.thank you.thank you.
-
I’m getting the error message ‘Warning: array_merge() [function.array-merge]: Argument #2 is not an array’.
Any ideas? I have the original script up and working OK and I’d like to try this with Fusion Charts =D
-
Love the script! Any way to get this to work with advanced segments? I tried adding the extra parameters to no avail.
-
Brilliant!
works first go
unfortunately I’m not clever enough to get it to dig down into a directory, would you mind adding that var into your script?
-
Thank you. Your code works! Very helpful!

