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!

Again thanks to the original authors. Have fun!

14 Comments

  1. Google analytics | Internet Marketing Blog 2008-09-27, 10:43 pm

    [...] Google Analytics Export [...]

  2. guitarman 2008-09-29, 4:50 pm

    Get “no input file specified” as reply.
    What do I do wrong?

    Thx

  3. Manfred Weber 2008-09-29, 5:04 pm

    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);

  4. floh 2008-10-16, 9:25 pm

    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!

  5. Manfred Weber 2008-10-16, 9:54 pm

    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!

  6. Spanishgringo 2009-01-27, 9:55 am

    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

  7. tom 2009-01-30, 2:01 pm

    this is php5 only right?

  8. Manfred 2009-01-30, 2:13 pm

    Hmm… might probably also work with php4. But I am not sure.

  9. FrogCMS Google Analytics Plugin | Chris Earls 2009-01-31, 1:18 am

    [...] This plugin uses the Google Analytics export script from Manifred Weber. [...]

  10. listeblog 2009-03-1, 3:22 am

    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.

  11. Hinch 2009-03-6, 7:05 pm

    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

  12. Andreas 2009-04-14, 11:32 pm

    Love the script! Any way to get this to work with advanced segments? I tried adding the extra parameters to no avail.

  13. Eric T Bear 2009-04-21, 4:24 am

    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?

  14. beijie 2009-05-1, 5:33 am

    Thank you. Your code works! Very helpful!

Add a Comment