I want to show my top 5 pages viewed on my blog, I don’t want to count page views myself , and I want to distinguish between views by real people and views by spiders etc... I want to get the information from my statistics package. I use Google Analytics; it is a great stats package for your web site. If you haven’t tried it out you are missing out. The basic functions of Google Analytics are easy to use with all the basic reports at your finger tips on your dashboard. I think there is still a place for server log based statistics as they can give you information about your web site usage the Google Analytics can not.
How can I get my hands on the Google Analytics data?
There currently is no API to allow you to directly access the data but Google Analytics does allow you to export of data in four formats PDF, XML, CSV and TSV. The report you choose really depends on what you want to do with it. If you only want to read the report the PDF report is best, its good to go, its already formatted and looks much like the report in Google Analytics except of course its not interactive. If you want to integrate the information into your web site I choose the XML report, you can easily format this with XSLT.
Exporting the data from Google Analytics
I can think of a number of ways to do this:
- First of course it requires no programming, do it manually, log into Google Analytics and export the information using the export link at the top of each report.
- Setup Google Analytics to email you the information to your email account, this can be scheduled.
- Write a script to download the information for you using web scraping and HTTP POSTs and GETs.
Scheduled Email Reports
The second most reliable method, email. Using C# .NET.
Web Scraping and HTTP
Writing a script to download the information is fairly straight forward but does rely on Google not updating the web interface. There are a number of existing solutions. Felix Geisendörfer has developed a PHP script - Google Analytics API / DataSource there is also a C# project Google Analytics Data Extractor that can extract reports from Google Analytics and store them in a MS SQL database. The Google Analytics Data Extractor is a command line application that you would schedule perhaps using windows task scheduler. This may be difficult if you are using this on your web site.
This has prompted me to make my own C# .NET solution access the Google Analytics data.
I will keep you posted on my progress.