Simple framework using Google Analytics API with python+pandas to do quick visualization focused on goals.
-
Follow this tutorial to get creds: https://developers.google.com/analytics/devguides/reporting/core/v4/quickstart/installed-py
-
Dependencies (don't know if it works with py2):
pip3 install -r requirements.txt
-
Create config.ini at the root
[Creds]
VIEW_ID: ID_GA
CLIENT_SECRETS_PATH: client_secret.json
[ConfProject]
folder: FOLDER_NAME/
- Launch notebook:
jupyter notebook
- Create object:
d = g.AnalyticsData(start_date="", end_date="", dimension="", metric="", goal="", version="", filter_data='')
Name | Description | Example |
---|---|---|
start_date | Starting date | "2016-08-05" |
end_date | Ending date | "yesterday" |
dimension | Dimensions | "date,deviceCategory,userType" |
metric | Metrics | "sessions" |
goal | If you have goals | "goalXCompletions" |
version | String | "dimensionXX" |
filter_data | String | ga:dimension5=~^(New) |
All the parameters have to follow this guide: https://developers.google.com/analytics/devguides/reporting/core/dimsmets without the "ga:" except for filter_data parameter.
- Retreive data
df = d.get_full_data()
- Graph
input:
d.ts(df)
output:
Name | description |
---|---|
df | data to pass (pandas dataframe) |
filter_dim | Filter data by one of the dimension's name requested |
filter_val | Filter data by one of the dimension's value requested |
ylim | min and max limit of the graph |
title | Title of the graph |
d.ts(df, filter_dim='deviceCategory', filter_val='desktop', title='My time series graph')
Name | Description |
---|---|
filter_dim | Filter data by one of the dimension's name requested |
filter_val | Filter data by one of the dimension's value requested |
ylim | min and max limit of the graph (tuple) |
title | Title of the graph |
d.bar(df, filter_dim='deviceCategory', filter_val='desktop', title='My time series graph', ylim(30,40))
Name | Description |
---|---|
ref_dim | the version to compare |
filter_dim | Filter data by one of the dimension's name requested |
filter_val | Filter data by one of the dimension's value requested |
title | Title of the graph |
d.diff(df,ref_dim='Test version', filter_dim='deviceCategory', filter_val='desktop', title='My time series graph')
Name | Description |
---|---|
filter_dim | Filter data by one of the dimension's name requested |
filter_val | Filter data by one of the dimension's value requested |
ylim | min and max limit of the graph |
title | Title of the graph |
d.cumulative(df, filter_dim='deviceCategory', filter_val='desktop', ylim(30,40), title='My time series graph')
Name | Description |
---|---|
filter_dim | Filter data by one of the dimension's name requested |
filter_val | Filter data by one of the dimension's value requested |
ref_dim | the version to compare |
title | Title of the graph |
ylim | min and max limit of the graph |
d.diff_cumul(d,filter_dim='deviceCategory', ref_dim='Test version', filter_val='desktop', ylim(30,40), title='My time series graph')
-
Add special functions for e-commerce websites.
-
Add new api?