Simple Google Analytics API data extraction.
Project description
Freesixty
A simple Google Analytics API data extraction.
Simple example:
1. Install freesixty
pip install freesixty
2. Get data
import freesixty
SCOPES = ['https://www.googleapis.com/auth/analytics.readonly']
KEY_FILE_LOCATION = 'gcp_keyfile.json'
VIEW_ID = 'XXXXXXX'
query = {
'reportRequests': [
{
'viewId': VIEW_ID,
'dateRanges': [{'startDate': '2009-01-01', 'endDate': '2019-01-05'}],
'metrics': [{'expression': 'ga:sessions'}],
'dimensions': [{'name': 'ga:country', 'name': 'ga:date'}]
}]
}
folder_uri = 'file:///tmp/example/folder'
analytics = freesixty.initialize_analyticsreporting(KEY_FILE_LOCATION)
freesixty.store_query(analytics, query, folder_uri, 'json')
3. Use it
ls /tmp/example/folder
4. Profit
:cake:
Splitting query example
In case a query would return over 100k rows of data it will fail. We can get around it by splitting the date range into smaller chunks. E.g.:
queries = freesixty.split_query(query=query, start_date='2019-01-01', end_date='2019-02-01', freq='D')
for q in queries:
freesixty.store_query(analytics, query, folder_uri, 'json')
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
freesixty-0.1.1.tar.gz
(4.9 kB
view hashes)
Built Distribution
Close
Hashes for freesixty-0.1.1-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0e00bad5326ba6e380085cb483c08460d1f3e60da7138ddd0bf82d6353e15a83 |
|
MD5 | afaadd965d6da423d144c3589e80509b |
|
BLAKE2b-256 | a5e276ecb00153e20c7bf0689072a6c148b78bfdbe63b8a546404d9e6ad2c078 |