
Download google2piwik for Piwik version 1.2 and higher (UPDATED 01/04/2011)
Download google2piwik for Piwik version up to 1.1.1
Description
Google2Piwik is script written in Python to enable exporting statistics from Google Analytics to open source alternative, Piwik.
Requirements
- Access to Piwik Installation.
- Google Analytics Account with read or admin rights.
- Google Analytics API currently does not support Google Apps for your Domain Accounts.
Thats why you can’t export data from account@yourdomain.com even if you have access via web interface.
However you can grant privileges to your Gmail account, and use it to perform the export. - Python 2.6 with components:
- gdata-python-client (Google Python API)
http://code.google.com/p/gdata-python-client/ - MySQLdb
Preparation
Before running the script please be sure to:
- Prepare `google2piwik.conf` configuration file – sample in
google2piwik.conf.sample - If you don’t know your site table_id, type:
python google2piwik.py -p
(remember to fill google login and pass configuration before) - Check if configuration file is acceptable and all rights are present
./google2piwik.py -c - Create backup of your Piwik MySQL Database
- Set the timezone in Piwik for the site where you import data to UTC
- Run the script
After export
After successful export, please go to your Piwik installation folder
and run misc/cron/archive.sh script.
Limitations
Unfortunately because of lack of full access to data, some statistics may be different from presented in Google Analytics.
Known not trustworthy statistics:
- Visitors -> Visitor Log statistics are not reliable.
This one is generated semi-randomly to supply informations about Actions (Pageviews, Bouncy Rate etc.) - Sometimes page `Bouncy Rate` and `Average time on page` is slightly different from Google Analytics
- Visits Providers are unknown (because Google doesn’t supply such informations)
- Actions -> Unique Pageviews
- Visitors -> Settings -> Plugins
Google provides only informations about Flash Player and Java enabled.
Because of Google API Policy, there is a limit of requests per 24 hours. Currently this script is using 5 requests (fetching 10 000 data rows) for one exported day, plus 3 for whole period. However number of requests depends on number of visits and total number of pageviews.
This means that you should be able to export about 2000 days per 24h in low and medium visited sites. (Read more @ code.google)
Contact
Clearcode is a software development company. We offer consulting, IT development and configuration services for web analytics solutions, including Piwik.
E-mail: office@clearcode.cc


Hi there,
great script, but we have problems on our Debian Server with Python 2.5.2.
We had to alter the sql.php for backward compatibility to our Python version.
Here’s a diff: http://gbpaste.org/YubT7
And now, the script give us errors: http://gbpaste.org/jsYNc
At Line 17, the errormessage came up 32150 times.
And it need 2-3h for one day
Greets
Thanks. Currently the script is compatible with Python 2.6.x.
We are going to release an optimized version that exports data much more faster in a while
Working on Apache and Google Import via Piwik Plugin:
http://forge.typo3.org/projects/extension-piwikintegration/repository/show/trunk/piwik_patches/plugins/KSVisitorImport
Regards
Kay
Wow this software rocks, keep up the good work.
it is difficult to import data from google analytics!
There is an easier way?
I can not use Python!
New version compatible with Piwik 1.2.x released. Thanks to Sven from http://www.sense-design.de/ for supplying all debugging information!
Thanks for the script.
I get the following Error:
http://paste.ubuntuusers.de/400051/
Can you help me with it?
My Server is on Ubuntu hardy. Is it because of Python 2.5.2?
Many Thanks for your help.
Google2Piwik required Python 2.6.x
The error is caused by Python 2.5 which does not support “format” method for strings.
Thanks for your quick reply. I run the script now on my local desktop. Seems to work fine.
Hi,
i recieve the followung error:
[google2piwik-1.2.5] ./google2piwik.py -c
Traceback (most recent call last):
File “./google2piwik.py”, line 16, in
import gdata.analytics.client
ImportError: No module named gdata.analytics.client
Many Thanks for your help!
You need to install gdata module for Python, you can get it from:
http://code.google.com/p/gdata-python-client/downloads/list
Hi,
nice script, but get sometimes:
Exporting 2010-06-15
Traceback (most recent call last):
File “./google2piwik.py”, line 636, in
export_period(start_date, end_date)
File “./google2piwik.py”, line 70, in export_period
export_day(str(currentdate), fetcher)
File “./google2piwik.py”, line 113, in export_day
simulator.initialize(fetcher, “ga:latitude,ga:longitude,ga:hour,ga:flashVersion,ga:javaEnabled,ga:language,ga:screenResolution”, “ga:visits”)
File “./google2piwik.py”, line 372, in initialize
self.visits[index].first(visit)
IndexError: list index out of range
Any idea??
Cheers
Christian
Missing information:
Python 2.7, OpenSUSE 11.4
Hi,
I am running Piwik 1.6 and Python 2.7. The import script seemed to run fine and added nearly 200,000 records to the database but when I ran the archiver they all got deleted and no historic archive records were created. Any ideas?
cheers,
Tom