I've recently started using IPython and wanted to use it to access and analyse Google Analytics for data from my website.
A quick google search indicated that this could be done quite easily and that pandas had some support for GA. But, when I started trying to access and use the data, the trouble started.
The main two sites I was following were:
The first issue I had was an authentication failure with Google. Using oAuth2 can often be difficult and in this case I just kept getting a 401 failure.
Ultimately what I had to do to resolve the issue was create a new project in the Google API console and, under this project, create a new Client ID using the 'installed application' default. Even though I am using IPython through the web interface, I couldn't get the 'web application' default to work as it requires a responding web service. After setting up the new 'installed application' client, downloading the client_secrets.JSON file to the pandas.io subdirectory I finally got authentication happening.
My next issue was accessing the correct data from the website.
We run several websites with many accounts, properties and views tracked through Google Analytics. Unfortunately, these descriptions don't match the setting required in pandas. In summary, some helpful information is:
- property_ID is the last digit at the end of your tracking code. e.g. if you tracking code is UA-12345678-3, the property ID is '3'
- profile_name is the name of the view that you want to look at.
Ultimately I ended up passing in all the settings like so:
metrics = ['pageviews', 'visitors', 'goal1Completions'] dimensions = ['date','hour'] start_date = "2014-08-12" end_date = "2014-08-13" account_id = "<YOUR ID>" property_name = "<YOUR PROPERTY NAME>" property_id = "3" profile_name = "<YOUR VIEW NAME>" df = ga.read_ga(metrics, dimensions=dimensions, start_date=start_date, end_date=end_date, account_id=account_id, property_name = property_name, property_id = property_id, profile_name = profile_name, parse_dates=[['date', 'hour']])
Now it all works fine.
You can get a list of the dimensions, metrics etc you can access through Google's API